Power Analysis¶
Statistical power for z- and t-tests computed by hand with SciPy, cross-checked against statsmodels, plus Cohen's d helpers.
compute_power_z(effect_size, alpha=0.05, n=None, two_tailed=True)
¶
Compute statistical power for a one-sample Z-test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
effect_size
|
float
|
Standardized effect size (Cohen's d). |
required |
alpha
|
float
|
Significance level (Type I error rate). |
0.05
|
n
|
int
|
Sample size. |
None
|
two_tailed
|
bool
|
If True, uses two-tailed critical value; otherwise one-tailed. |
True
|
Returns:
| Type | Description |
|---|---|
float
|
Statistical power in [0, 1]. Power > 0.8 is typically desirable. |
Notes
Uses the normal distribution (appropriate when population variance is known or n is large enough for CLT to apply).
Source code in utils/power_utils.py
compute_power_t(effect_size, alpha=0.05, n=None, two_tailed=True)
¶
Compute statistical power for a one-sample t-test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
effect_size
|
float
|
Standardized effect size (Cohen's d). |
required |
alpha
|
float
|
Significance level. |
0.05
|
n
|
int
|
Sample size (must be >= 2). |
None
|
two_tailed
|
bool
|
If True, uses two-tailed critical value. |
True
|
Returns:
| Type | Description |
|---|---|
float
|
Statistical power in [0, 1]. |
Notes
Uses the t-distribution with df = n - 1. Preferred over Z-test power when population variance is unknown.
Source code in utils/power_utils.py
statsmodels_power(effect_size, alpha=0.05, n=None, alternative='two-sided')
¶
Compute t-test power using the statsmodels TTestPower API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
effect_size
|
float
|
Standardized effect size (Cohen's d). |
required |
alpha
|
float
|
Significance level. |
0.05
|
n
|
int
|
Number of observations. |
None
|
alternative
|
str
|
|
'two-sided'
|
Returns:
| Type | Description |
|---|---|
float
|
Statistical power in [0, 1]. |
Source code in utils/power_utils.py
compute_cohens_d(mean1, mean2, std_dev)
¶
Compute Cohen's d effect size from two group means.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean1
|
float
|
Mean of the first group. |
required |
mean2
|
float
|
Mean of the second group. |
required |
std_dev
|
float
|
Pooled or common standard deviation. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Cohen's d = (mean1 - mean2) / std_dev. Interpretation: 0.2 small, 0.5 medium, 0.8 large. |