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 chi-squared 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 and alpha must be passed as None, and that parameter is determined from the others. The degrees of freedom dof 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 non-centrality 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 chi-squared test is calculated using the survival function of the non-central \(\chi^2\) distribution using the previously computed critical value, non-centrality 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

https://cran.r-project.org/web/packages/pwr/pwr.pdf

Examples

  1. Compute achieved power

>>> from pingouin import power_chi2
>>> print('power: %.4f' % power_chi2(dof=1, w=0.3, n=20))
power: 0.2687
  1. Compute required sample size

>>> print('n: %.4f' % power_chi2(dof=3, w=0.3, power=0.80))
n: 121.1396
  1. Compute achieved effect size

>>> print('w: %.4f' % power_chi2(dof=2, n=20, power=0.80, alpha=0.05))
w: 0.6941
  1. Compute achieved alpha (significance)

>>> print('alpha: %.4f' % power_chi2(dof=1, w=0.5, n=20, power=0.80,
...                                   alpha=None))
alpha: 0.1630