ci_cor: CI for Correlation Coefficients

View source: R/ci_cor.R

ci_corR Documentation

CI for Correlation Coefficients

Description

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).

Usage

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])
ci_cor(iris[1:2], type = "bootstrap", R = 999)  # Use larger R
ci_cor(iris[1:2], method = "spearman", type = "bootstrap", R = 999)  # Use larger R

confintr documentation built on June 7, 2023, 6:24 p.m.