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

🔨 使用

估算样本量

  1. 单样本率置信区间
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
  1. 单样本率差异性检验(单组目标值法)
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
  1. 两独立样本率非劣效检验
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 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.5.tar.gz (26.5 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.5-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pystatpower-0.0.5.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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.5.tar.gz
Algorithm Hash digest
SHA256 3c4c0e6a1b84b46d0ae04be9c646b0ccee96252a980867eebc8dc00cdc570010
MD5 9eda126f7144367325bd814234ee2e4e
BLAKE2b-256 86fa7d8b43a8b9d0bf179ff4652651d3f7c4a12c0523f63afa469c0bb872d2ae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pystatpower-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 29.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1f5ae78ee18f2c8e8d17e44f43ca87f4421524547fd823e79b36153201bf9836
MD5 901c685ee6cff9a5ad3985b5c3736f7a
BLAKE2b-256 b136d43e72c7e2017e6377e1db6e83e4f2021e7f8ef90f3108350bfe57507137

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