Skip to main content

A Power Analysis Toolkit for Python

Project description

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

PyStatPower 是一个统计学功效分析的 Python 软件包,可用于样本量、检验效能和效应量大小的估计。

📚 功能模块

  • 单样本均值置信区间
  • 单样本均值差异性检验
  • 两独立样本均值差异性检验
  • 两独立样本均值非劣效检验
  • 两独立样本均值优效性检验
  • 单样本率置信区间
  • 单样本率差异性检验
  • 两独立样本率差异性检验
  • 两独立样本率非劣效检验
  • 两独立样本率优效性检验
  • 相关系数检验

📦 安装

前置需求:Python 3.10+

pip install pystatpower

🔨 使用示例

估算样本量

  • 单样本率置信区间

    from pystatpower.models import proportion
    
    size = proportion.single.ci.solve_size(
        proportion=0.9,
        ci_width=0.10,
        alpha=0.05,
    )
    print(size)
    
    # output: 158
    
  • 单样本率差异性检验(单组目标值法)

    from pystatpower.models 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
    
  • 两独立样本率非劣效检验

    from pystatpower.models 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)
    
  • 两独立样本均值优效性检验

    from pystatpower.models 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.models 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

反推效应量

from pystatpower.models 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

🧪 兼容性测试结果

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 -

注: - 表示该 Python 版本下不存在对应的 SciPy 发行版。

🔮 鸣谢

Project details


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.6.tar.gz (36.3 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.6-py3-none-any.whl (44.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pystatpower-0.0.6.tar.gz
  • Upload date:
  • Size: 36.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","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.6.tar.gz
Algorithm Hash digest
SHA256 9c2355a25642fe82a2b8a8b800f842d15d0d006ec8bc5fa12001b9eefd8e96ff
MD5 6b2a7868bf84e2e0849bb9170653f2a5
BLAKE2b-256 fba5f7472066d8a81c33315e4c67c1f342d474a42b147ae27b37baf55319451b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pystatpower-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 44.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 1646446d4c0dd01d9296a0690b45f5b30a97465d33f74c3d4509c203d028428a
MD5 f6c3e74b79f7b09f11e1884b9fcb136a
BLAKE2b-256 dfb7124d988b345bea18f96b6baac12c906d195fafe9f7c3e6496668ae52936b

See more details on using hashes here.

Supported by

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