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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pystatpower-0.0.7.tar.gz (49.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pystatpower-0.0.7-py3-none-any.whl (67.0 kB view details)

Uploaded Python 3

File details

Details for the file pystatpower-0.0.7.tar.gz.

File metadata

  • Download URL: pystatpower-0.0.7.tar.gz
  • Upload date:
  • Size: 49.4 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for pystatpower-0.0.7.tar.gz
Algorithm Hash digest
SHA256 d68e8dc39bd13c5443275d392a00625fcb77fbfcfd0fed35bdb17b02749cea83
MD5 d9447d543e7001befc6694d95c66ba6b
BLAKE2b-256 6763e5e008a6eb559704d4c52bb7e4a9a9e27bf8364f32500475d577f15bd665

See more details on using hashes here.

File details

Details for the file pystatpower-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: pystatpower-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 67.0 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for pystatpower-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 3a9b85f631777d3dde6d0529eb0a229b366c4388de2d172308bd7e2b98eb5ead
MD5 77dde21f3617988c5e4f2f471306f435
BLAKE2b-256 36063250c56daaf96daefe143af7748f918fe4091722801700a1f1c0943a82a6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page