Skip to main content

PyStatPower

PyPI - Version PyPI - Python Version GitHub License PyPI - Status PyPI Downloads

Build Status Test Status Documentation Status codecov pre-commit.ci status

uv Ruff pytest Codacy Badge

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.

📦 Installation

Prerequisites: Python 3.10+

pip install pystatpower

🚀 Usage Examples

Sample Size Estimation

  • 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)
    

Statistical Power Calculation

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.800282915718918

Effect Size Solving

from 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

🧪 Compatibility Matrix

Test Status

🐍 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.

✨ Contributing

Issues and pull requests are welcome and highly appreciated. To get started, check out the contributing guidelines.

🤝 Acknowledgments

Metadata

Release files for pystatpower 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pystatpower 0.0.7
File Size Uploaded
pystatpower-0.0.7.tar.gz 49.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pystatpower 0.0.7
File Interpreter ABI Platform
pystatpower-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 116.3 kB

Release files / pystatpower-0.0.7.tar.gz

Download URL pystatpower-0.0.7.tar.gz
Size 49.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d68e8dc39bd13c5443275d392a00625fcb77fbfcfd0fed35bdb17b02749cea83
BLAKE2b-256 checksum
How to use checksums
6763e5e008a6eb559704d4c52bb7e4a9a9e27bf8364f32500475d577f15bd665
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pystatpower-0.0.7-py3-none-any.whl

Download URL pystatpower-0.0.7-py3-none-any.whl
Size 67.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a9b85f631777d3dde6d0529eb0a229b366c4388de2d172308bd7e2b98eb5ead
BLAKE2b-256 checksum
How to use checksums
36063250c56daaf96daefe143af7748f918fe4091722801700a1f1c0943a82a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page