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).
A numeric vector or a matrix
/data.frame
with exactly two numeric columns.
A numeric vector (only used if x
is a vector).
Lower and upper probabilities, by default c(0.025, 0.975)
.
Type of correlation coefficient, one of "pearson" (default), "kendall", or "spearman". For the latter two, only bootstrap CIs are supported.
Type of CI. One of "normal" (the default) or "bootstrap" (the only option for rank-correlations).
Type of bootstrap CI. Only used for type = "bootstrap"
.
The number of bootstrap resamples. Only used for type = "bootstrap"
.
An integer random seed. Only used for type = "bootstrap"
.
Further arguments passed to boot::boot()
.
An object of class "cint", see ci_mean()
for details.
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
#>