This function calculates CIs for a population correlation coefficient. For Pearson correlation, "normal" CIs are available (by stats::cor.test()). Also bootstrap CIs are supported (by default "bca", and the only option for rank correlations).

ci_cor(
  x,
  y = NULL,
  probs = c(0.025, 0.975),
  method = c("pearson", "kendall", "spearman"),
  type = c("normal", "bootstrap"),
  boot_type = c("bca", "perc", "norm", "basic"),
  R = 9999L,
  seed = NULL,
  ...
)

Arguments

x

A numeric vector or a matrix/data.frame with exactly two numeric columns.

y

A numeric vector (only used if x is a vector).

probs

Lower and upper probabilities, by default c(0.025, 0.975).

method

Type of correlation coefficient, one of "pearson" (default), "kendall", or "spearman". For the latter two, only bootstrap CIs are supported.

type

Type of CI. One of "normal" (the default) or "bootstrap" (the only option for rank-correlations).

boot_type

Type of bootstrap CI. Only used for type = "bootstrap".

R

The number of bootstrap resamples. Only used for type = "bootstrap".

seed

An integer random seed. Only used for type = "bootstrap".

...

Further arguments passed to boot::boot().

Value

An object of class "cint", see ci_mean() for details.

Examples

ci_cor(iris[1:2])
#> 
#> 	Two-sided 95% normal confidence interval for the true Pearson
#> 	correlation coefficient
#> 
#> Sample estimate: -0.1175698 
#> Confidence interval:
#>        2.5%       97.5% 
#> -0.27269325  0.04351158 
#> 
ci_cor(iris[1:2], type = "bootstrap", R = 999)  # Use larger R
#> 
#> 	Two-sided 95% bootstrap confidence interval for the true Pearson
#> 	correlation coefficient based on 999 bootstrap replications and the bca
#> 	method
#> 
#> Sample estimate: -0.1175698 
#> Confidence interval:
#>       2.5%      97.5% 
#> -0.2440754  0.0533486 
#> 
ci_cor(iris[1:2], method = "spearman", type = "bootstrap", R = 999)  # Use larger R
#> 
#> 	Two-sided 95% bootstrap confidence interval for the true Spearman
#> 	correlation coefficient based on 999 bootstrap replications and the bca
#> 	method
#> 
#> Sample estimate: -0.1667777 
#> Confidence interval:
#>        2.5%       97.5% 
#> -0.32522253 -0.02070823 
#>