confIntCorrelation: Confidence interval for correlation coefficient using...

View source: R/confIntCorrelation.R

confIntCorrelationR Documentation

Confidence interval for correlation coefficient using Fisher's transformation

Description

Computes a confidence interval for a correlation coefficient r using the variance-stabilizing transformation

z = \tanh^{-1}(r) = 0.5 \log((1 + r) / (1 - r)),

known as Fisher's z-transformation. Independent of the true correlation \rho, z is approximately normally distributed with variance (n-3)^{-1}. This enables the construction of a Wald-type confidence interval. Back-transformating this interval yields a confidence interval for r. An advantage of this method is that the interval is contained in (-1, 1).

Usage

confIntCorrelation(
  x,
  y,
  conf.level = 0.95,
  method = c("spearman", "pearson"),
  type = c("t", "z")
)

Arguments

x

Vector containing the first variable.

y

Vector of same length as x containing the second variable.

conf.level

Confidence level for confidence interval. Default is 0.95.

method

Correlation coefficient to be used: "spearman" (default) or "pearson".

type

Quantile to be used: "t" (default) or "z".

Value

List with entries:

estimate

Value of correlation coefficient.

ci

Computed confidence interval.

p.value

p-value for a test on \rho = 0 based on the transformation.

n

Number of observations.

p2

p-value based on the R function cor.est.

Author(s)

Kaspar Rufibach
kaspar.rufibach@gmail.com

Examples


n <- 40
x <- runif(n = n)
y <- 2 * x + 0.5 * rnorm(n = n)
confIntCorrelation(x = x, y = y)


felix-hof/biostatUZH documentation built on Sept. 27, 2024, 1:48 p.m.