Statistical Power (Analysis)

tags: #statistics/inferential

What is statistical power?

Statistical power is the likelihood of correctly rejecting the null hypothesis, when there is an effect to be found (i.e., when the alternative is true/null hypothesis is false).

Important to Note!


How can we Compute the Power?

The statistical power of a test is the inverse probability of making a type 2 error, such that the higher the statistical power for a given test, the lower the probability of making a Type II (false negative) error.

Power=1β

Therefore, we can compute the type 2 error by computing the power and finding: β=1Power.

Important Note: Power Rejecting the Null

The corresponding chance of obtaining a pα when the alternative is true is referred to as the power of the experiment, ranging from α to near 100%.

We can compute the statistical power of a test given:

1. Effect Size: magnitude of the result (i.e., practical significance) you expect/want to observe.

2. Sample Size: for practical considerations

3. Significance: Significance level used in the statistical test (probability of rejecting the null hypothesis)


Practical Implications

Before the Experiment

Statistical power analysis can be conducted to estimate the required sample size to detect a desired effect size (e.g., if you are looking for an effect size of 0.8, we can use the power analysis to find n to get the desired 0.8 effect), at a given alpha significance level and statistical power .

After the Experiment

Tells you how confident you should be in the results by computing the type 2 error (the likelihood of failing to reject the null when it is false)  by using the given sample size, effect size, and significance level, consequently helping to conclude whether the probability of committing a Type II error is acceptable from a decision-making perspective.

We can compute a power analysis using functions from the statsmodels.stats.power package.

Different Power Functions

NOTE: there are different statistical power functions available depending on the statistical test you are conducting (see: list of functions)


Power Analysis Using Python

The stats.power module of the statsmodels package in Python contains the required functions for carrying out power analysis for the most commonly used statistical tests such as t-test, normal based test, F-tests, and Chi-square goodness of fit test.

It’s solve_power function takes 3 of the 4 variables mentioned above as input parameters and calculates the remaining 4th variable (e.g., if you want to find the required sample size before an experiment you need to know your estimated effect size, statistical power of your test, and alpha significance level in which you intend to conduct your test at)

Python: Power Analysis

First, import the relevant function from the statsmodels.stats.power module depending on the type of test you want to perform (e.g., TTestIndPower() for independent t-tests).

import statsmodels.stats.power as smp

Instantiate the relevant power analysis class, specifying the required parameters:

# Instantiate the TTestIndPower class 
power_analysis = smp.TTestIndPower() 

# Specify the parameters for the power analysis 
effect_size = 0.5   # expected effect size
alpha = 0.05        # significance level
n1 = 50             # sample size of group 1
n2 = 50             # sample size of group 2
ratio = 1           # ratio of sample sizes between groups; 1 = "equal" as in 1:1

Compute the power of the test using the power() method:

power = power_analysis.power(effect_size=effect_size, nobs1=n1, alpha=alpha, ratio=ratio, alternative='two-sided')

Python: Required Sample Size

First, import the necessary libraries:

import statsmodels.stats.power as smp

Instantiate the power function depending on the hypothesis test being conducted:

power_analysis = smp.<POWER FUNCTION>

To find the required sample size, we can call the .solve_power() method onto the power object, specifying the desired effect size, power, and significance level at which the test is to be conducted at:

sample_size = power_analysis.solve_power(effect_size=2, power=0.8, alpha=0.05)
# conservative effect size - 0.2
# generally power is set to 0.8

print(sample size)
Powered by Forestry.md