PyStatPower is a Python package for statistical power analysis that allows users to estimate sample size, test power, and effect size.
简体中文 | English
🗺️ Feature List & Roadmap: To see currently supported statistical models and planned features, check out roadmap.
Prerequisites: Python 3.10+
pip install pystatpower-
Single Proportion Confidence Interval
from pystatpower import proportion size = proportion.single.ci.solve_size( proportion=0.9, distance=0.10, conf_level=0.95, interval_type="two-sided", ) print(size) # output: 158
-
Single Proportion Inequality Test
from pystatpower import proportion size = proportion.single.inequality.solve_size( null_proportion=0.80, proportion=0.95, alternative="one-sided", alpha=0.025, power=0.8, ) print(size) # output: 42
-
Two Independent Proportions Non-Inferiority Test
from pystatpower import proportion size = proportion.independent.noninferiority.solve_size( treatment_proportion=0.95, reference_proportion=0.90, margin=-0.10, ratio=1, alpha=0.025, power=0.8, ) print(size) # output: (48, 48)
-
Two Independent Means Superiority Test
from pystatpower import mean size = mean.independent.superiority.solve_size( diff=0.5, margin=0.1, treatment_std=1.2, reference_std=1.2, ratio=2, alpha=0.025, power=0.8, ) print(size) # output: (214, 107)
from pystatpower import proportion
power = proportion.independent.noninferiority.solve_power(
treatment_proportion=0.95,
reference_proportion=0.90,
margin=-0.10,
treatment_size=48,
reference_size=48,
alpha=0.025,
)
print(power)
# output: 0.800282915718918from pystatpower import proportion
treatment_proportion = proportion.independent.noninferiority.solve_treatment_proportion(
reference_proportion=0.90,
margin=-0.10,
treatment_size=48,
reference_size=48,
alpha=0.025,
power=0.8,
)
print(treatment_proportion)
# output: 0.9499637015276098| 🐍 3.10 | 🐍 3.11 | 🐍 3.12 | 🐍 3.13 | 🐍 3.14 | |
|---|---|---|---|---|---|
| SciPy 1.7 | ✅ | - | - | - | - |
| SciPy 1.8 | ✅ | - | - | - | - |
| SciPy 1.9 | ✅ | - | - | - | - |
| SciPy 1.10 | ✅ | ✅ | - | - | - |
| SciPy 1.11 | ✅ | ✅ | ✅ | - | - |
| SciPy 1.12 | ✅ | ✅ | ✅ | - | - |
| SciPy 1.13 | ✅ | ✅ | ✅ | - | - |
| SciPy 1.14 | ✅ | ✅ | ✅ | - | - |
| SciPy 1.15 | ✅ | ✅ | ✅ | ✅ | - |
| SciPy 1.16 | - | ✅ | ✅ | ✅ | ✅ |
| SciPy 1.17 | - | ✅ | ✅ | ✅ | ✅ |
| SciPy 1.18 | - | - | ✅ | ✅ | ✅ |
Note
- : This combination of Python and SciPy does not exist.
Issues and pull requests are welcome and highly appreciated. To get started, check out the contributing guidelines.