Computes statistical power, required total sample size, \(\alpha\),
or the minimal detectable correlation coefficient for a Pearson correlation test.
Two computational methods are supported: exact noncentral t (method = "t"
)
and Fisher's z-transformation with normal approximation (method = "z"
).
Arguments
- alternative
Character. Either
"two.sided"
or"one.sided"
.- n_total
Integer scalar. Total sample size (\(n\)). Must be \(\ge 3\) for
method = "t"
and \(\ge 4\) formethod = "z"
. IfNULL
, the function solves forn_total
.- alpha
Numeric in \((0,1)\). If
NULL
, it is solved for.- power
Numeric in \((0,1)\). If
NULL
, it is computed; ifn_total
isNULL
,n_total
is solved to attain this power.- rho
Numeric correlation coefficient in \((-1,1)\), nonzero. If
NULL
,rho
is solved for given the other inputs.- method
Character. Either
"t"
(noncentral t-distribution) or"z"
(Fisher's z transformation with normal approximation).- bias_correction
Logical. Applies only to
method = "z"
. IfTRUE
, uses the bias-corrected Fisher z-transformation \(z_p = \operatorname{atanh}(r) + r/(2(n-1))\).- nlim
Integer vector of length 2. Search range of
n_total
when solving sample size.
Value
A one-row data.frame
with class
"cal_power"
, "cal_n"
, "cal_alpha"
, or "cal_es"
,
depending on the solved quantity. Columns:
df
(only formethod = "t"
)n_total
,alpha
,power
rho
,t_critical
orz_critical
ncp
(noncentrality parameter or mean under the alternative: see Details)
Details
Exactly one of
n_total
,rho
,alpha
, orpower
must beNULL
; that quantity is then solved.For
method = "t"
, computations are based on the noncentral t-distribution with noncentrality parameter \(\lambda = \tfrac{\rho}{\sqrt{1-\rho^2}} \sqrt{n}\).For
method = "z"
, computations use Fisher's z transformation of the population correlation, \(z_\rho = \operatorname{atanh}(\rho)\). Let \(W = \sqrt{n-3}\, z\). Under the alternative hypothesis, \(W \sim \mathrm{Normal}(\mu,\,1)\) with \(\mu = \sqrt{n-3}\, z_\rho\). Ifbias_correction = TRUE
, \(\rho\) is first bias-corrected before applying Fisher's transform. Critical values are taken from the central normal distribution under \(H_0:\rho=0\) (i.e., \(W \sim \mathrm{Normal}(0,1)\) under the null). The returnedncp
equals \(\mu\).Validation against GPower: Results have been confirmed to match those produced by GPower for equivalent correlation tests using the noncentral t-distribution.
Note: Results from
method = "z"
will not exactly matchpwr::pwr.r.test
, becausepwr
uses a hybrid approach combining the Fisher-z approximation with a t-based critical value.
Examples
# (1) Compute power for rho = 0.3, N = 50, two-sided test
pwrcortest(alternative = "two.sided", n_total = 50, rho = 0.3, alpha = 0.05)
#> df n_total alpha power rho t_critical ncp
#> 1 48 50 0.05 0.5867505 0.3 2.010635 2.223748
#> Power (1 - beta) was calculated based on the total sample size, effect size, and alpha.
# (2) Solve required N for target power, using Fisher-z method
pwrcortest(method = "z", rho = 0.2, alpha = 0.05, power = 0.8)
#> n_total alpha power rho z_critical ncp
#> 1 194 0.05 0.8000666 0.2 1.959964 2.80182
#> The required total sample size was calculated based on the effect size, alpha, and power.
#> Note: 'power' indicates the achieved power rather than the target power.
# (3) Solve minimal detectable correlation
pwrcortest(n_total = 60, alpha = 0.05, power = 0.9, rho = NULL)
#> df n_total alpha power rho t_critical ncp
#> 1 58 60 0.05 0.9 0.3915971 2.001717 3.296573
#> The minimal detectable Cohen's f and partial eta squared were calculated based on the total sample size, alpha, and power.