pingouin.power_chi2

pingouin.
power_chi2
(dof, w=None, n=None, power=None, alpha=0.05)[source] Evaluate power, sample size, effect size or significance level of chisquared tests.
 Parameters
 doffloat
Degree of freedom (depends on the chosen test).
 wfloat
Effect size.
 nint
Total number of observations.
 powerfloat
Test power (= 1  type II error).
 alphafloat
Significance level (type I error probability). The default is 0.05.
Notes
Exactly ONE of the parameters
w
,n
,power
andalpha
must be passed as None, and that parameter is determined from the others. The degrees of freedomdof
must always be specified.Notice that
alpha
has a default value of 0.05 so None must be explicitly passed if you want to compute it.This function is a mere Python translation of the original pwr.chisq.test function implemented in the pwr package. All credit goes to the author, Stephane Champely.
Statistical power is the likelihood that a study will detect an effect when there is an effect there to be detected. A high statistical power means that there is a low probability of concluding that there is no effect when there is one. Statistical power is mainly affected by the effect size and the sample size.
The noncentrality parameter is defined by:
\[\delta = N * w^2\]Then the critical value is computed using the percentile point function of the \(\chi^2\) distribution with the alpha level and degrees of freedom.
Finally, the power of the chisquared test is calculated using the survival function of the noncentral \(\chi^2\) distribution using the previously computed critical value, noncentrality parameter, and the degrees of freedom of the test.
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.Results have been tested against GPower and the R pwr package.
References
 1
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Hillsdale,NJ: Lawrence Erlbaum.
 2
Examples
Compute achieved power
>>> from pingouin import power_chi2 >>> print('power: %.4f' % power_chi2(dof=1, w=0.3, n=20)) power: 0.2687
Compute required sample size
>>> print('n: %.4f' % power_chi2(dof=3, w=0.3, power=0.80)) n: 121.1396
Compute achieved effect size
>>> print('w: %.4f' % power_chi2(dof=2, n=20, power=0.80, alpha=0.05)) w: 0.6941
Compute achieved alpha (significance)
>>> print('alpha: %.4f' % power_chi2(dof=1, w=0.5, n=20, power=0.80, ... alpha=None)) alpha: 0.1630