pingouin.power_corr

pingouin.
power_corr
(r=None, n=None, power=None, alpha=0.05, alternative='twosided')[source] Evaluate power, sample size, correlation coefficient or significance level of a correlation test.
 Parameters
 rfloat
Correlation coefficient.
 nint
Number of observations (sample size).
 powerfloat
Test power (= 1  type II error).
 alphafloat
Significance level (type I error probability). The default is 0.05.
 alternativestring
Defines the alternative hypothesis, or tail of the correlation. Must be one of “twosided” (default), “greater” or “less”. Both “greater” and “less” return a onesided pvalue. “greater” tests against the alternative hypothesis that the correlation is positive (greater than zero), “less” tests against the hypothesis that the correlation is negative.
Notes
Exactly ONE of the parameters
r
,n
,power
andalpha
must be passed as None, and that parameter is determined from the others.Notice that
alpha
has a default value of 0.05 so None must be explicitly passed if you want to compute it.scipy.optimize.brenth()
is used to solve power equations for other variables (i.e. sample size, effect size, or significance level). If the solving fails, a nan value is returned.This function is a Python adaptation of the pwr.r.test function implemented in the pwr R package.
Examples
Compute achieved power given
r
,n
andalpha
>>> from pingouin import power_corr >>> print('power: %.4f' % power_corr(r=0.5, n=20)) power: 0.6379
Same but onesided test
>>> print('power: %.4f' % power_corr(r=0.5, n=20, alternative="greater")) power: 0.7510
>>> print('power: %.4f' % power_corr(r=0.5, n=20, alternative="less")) power: 0.0000
Compute required sample size given
r
,power
andalpha
>>> print('n: %.4f' % power_corr(r=0.5, power=0.80)) n: 28.2484
Compute achieved
r
givenn
,power
andalpha
level
>>> print('r: %.4f' % power_corr(n=20, power=0.80, alpha=0.05)) r: 0.5822
Compute achieved alpha level given
r
,n
andpower
>>> print('alpha: %.4f' % power_corr(r=0.5, n=20, power=0.80, alpha=None)) alpha: 0.1377