cor.n: Sample size calculation for correlation

View source: R/stat.R

cor.nR Documentation

Sample size calculation for correlation

Description

Compute the sample size for a given correlation coefficient, alpha level, and confidence interval width. Alternatively, solve for the coefficient, interval width, or alpha level given fixed parameters. cor.ci calculated the confidence interval for a fixed correlation coefficient and sample size.

Usage

cor.n(
  rho = NULL,
  n = NULL,
  width = NULL,
  alpha = 0.05,
  two.sided = TRUE,
  method = c("bonett", "fieller"),
  tol = .Machine$double.eps^0.25
)

cor.ci(rho, n, alpha = 0.05, two.sided = TRUE, method = c("bonett", "fieller"))

Arguments

rho

correlation coefficient

n

sample size

width

the width of the 1 - alpha confidence interval

alpha

type I error probability

two.sided

logical; if TRUE, a two-sided alpha is used

method

the method used to calculate the standard deviation, one of "bonett" or "fieller" (can be (unambiguously) abbreviated)

tol

numerical tolerance used in root finding, the default providing (at least) four significant digits

References

https://www.researchgate.net/profile/Douglas_Bonett/publication/279926406_Sample_size_requirements_for_estimating_Pearson_Kendall_and_Spearman_correlations/links/575de23908aed88462166f2e/Sample-size-requirements-for-estimating-Pearson-Kendall-and-Spearman-correlations.pdf

http://solarmuri.ssl.berkeley.edu/~schuck/public/manuscripts/Fieller1.pdf

https://ncss-wpengine.netdna-ssl.com/wp-content/themes/ncss/pdf/Procedures/PASS/Confidence_Intervals_for_Spearmans_Rank_Correlation.pdf

https://stats.stackexchange.com/a/18904

Examples

## table 1, bonett (spearman) -- solving for n
args <- data.frame(
  rho = 0.9,
  width = rep(1:3, each = 2) / 10,
  alpha = c(0.05, 0.01)
)

apply(args, 1L, function(x)
  ceiling(cor.n(x['rho'], NULL, x['width'], x['alpha'])))


## table 1, bonett (spearman)
cor.ci(0.1, 290, 0.01)
ceiling(cor.n(0.1, NULL, 0.3, 0.01))

cor.ci(0.5, 111, 0.05)
ceiling(cor.n(0.5, NULL, 0.3, 0.05))


raredd/rawr documentation built on March 4, 2024, 1:36 a.m.