biomed-parity
biomed-parity 用 Python 实现一组生物医学统计方法,适用于将分析流程从 R 迁到 Python、复现既有结果或核对统计口径。常规计算仅依赖 NumPy 和 SciPy,无需安装 R。方法文档记录对应的 R 调用、版本、数值对照与已知差异。
Native Python implementations of selected biostatistical methods with reproducible R reference cases.
安装
需要 Python 3.11 或更高版本。
python -m pip install biomed-parity
使用 ROC、RMST 或区间删失等绘图功能时,安装可选的 Matplotlib 依赖。
python -m pip install "biomed-parity[plot]"
快速上手
比较生存曲线
用 log-rank 检验比较两组右删失数据。事件编码为 1,右删失编码为 0。
from biomed_parity.survival import survdiff
result = survdiff(
time=[1, 2, 3, 4, 5, 6, 7, 8],
event=[1, 0, 1, 1, 0, 1, 1, 0],
group=["A", "A", "A", "A", "B", "B", "B", "B"],
rho=0,
)
print(f"chi2={result.statistic:.3f}, df={result.df}, p={result.pvalue:.4f}")
# chi2=6.118, df=1, p=0.0134
估计 ROC AUC 和置信区间
标签 1 表示病例,0 表示对照。默认分数越高越倾向于病例。
from biomed_parity.roc import delong_auc
result = delong_auc(
labels=[0, 1, 0, 1, 0, 1, 1],
scores=[1, 2, 2, 3, 3, 4, 5],
)
print(round(result.auc, 3), tuple(round(x, 3) for x in result.confidence_interval))
# 0.833 (0.517, 1.0)
方法与文档
| 领域 | 主要功能 | 方法文档 |
|---|---|---|
| 生存与多状态 | log-rank、RMST、区间删失、Royston–Parmar 样条、多状态转移和纵向–生存联合模型 | 区间删失 · 样条生存 · 多状态 · 联合模型 |
| 诊断准确性 | DeLong 检验、部分 AUC、Bootstrap、阈值、平滑和绘图 | DeLong · ROC Bootstrap · 绘图 |
| 试验设计 | 疗效、无效与伤害的组序贯边界,加权 log-rank、MaxCombo 和精确二项设计 | 组序贯设计 · MaxCombo · 精确二项 |
| 临床预测与竞争风险 | 惩罚逻辑回归和有序回归、预测校准、时间依赖 AUC 与 Brier 评分 | 有序回归 · 竞争风险评分 · 校准 |
| 多重插补 | 链式插补、两层模型、非随机缺失敏感性分析和推断合并 | 链式插补 · 合并推断 |
| 复杂抽样 | 调查加权 GLM 和 Cox 模型、权重校准、Taylor 方差和重复权重 | GLM · Cox · 重复权重 |
| Meta 分析 | REML、相关效应量、多层与多结局模型、随机斜率和空间协方差 | 多层模型 · 随机斜率 |
| 计数模型与表达分析 | 零膨胀混合模型、负二项似然比检验、VST、rlog 和逐特征混合模型 | 零膨胀负二项 · rlog · dream |
逐项覆盖范围、R 包对应关系及未覆盖场景见完整方法文档和迁移目录。
如何验证
仓库中的 validation/ 保存参考输入、R 脚本和带版本信息的数值快照。默认测试读取快照,无需安装 R。Bootstrap 通常使用固定重采样索引,随机插补按分布和蒙特卡洛误差核对。各方法的容差、兼容范围和已知差异见方法文档及验证记录。
从源码运行默认测试。
git clone https://github.com/xiangjiawei1234-prog/biomed-parity.git
cd biomed-parity
python3 -m venv .venv
.venv/bin/python -m pip install -e '.[test]'
.venv/bin/python -m pytest -q
安装 R 后,可在同一源码目录运行实时对照,例如复核生存曲线比较。各方法所需的 R 包版本及独立 R 库设置见对应方法文档。
Rscript --vanilla validation/install_r.R
R_LIBS_USER="$PWD/.r-lib" BIOMED_R_PARITY=1 .venv/bin/python -m pytest -q -W error tests/test_survival.py
贡献与许可
项目处于 Alpha 阶段,面向研究与方法复现。欢迎提交数值差异、覆盖需求或文档问题。提交 Issue · 贡献指南 · 版本记录 · MIT 许可证
Metadata
Release files for biomed-parity 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| biomed_parity-0.5.0.tar.gz | 2.7 MB | With provenance | Details for biomed_parity-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| biomed_parity-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for biomed_parity-0.5.0-py3-none-any.whl |
Total release size: 3.2 MB
Release files / biomed_parity-0.5.0.tar.gz
| Download URL | biomed_parity-0.5.0.tar.gz |
|---|---|
| Size | 2.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
376495e83645682ca04dcc53184b323c396b4b42f1dae024861dc57fda539905
|
|
BLAKE2b-256 checksum How to use checksums |
4a708c909b3b4f4ddf0ace500c30e3b2dd4cfc48683865c8b3f8eb6c090cedde
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logRelease files / biomed_parity-0.5.0-py3-none-any.whl
| Download URL | biomed_parity-0.5.0-py3-none-any.whl |
|---|---|
| Size | 475.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7211dbc36ffa4ce259f65f11911bfacc8bb763da356b16a0cac21f33532b5191
|
|
BLAKE2b-256 checksum How to use checksums |
279a8b7cf03969f821cdcad1164707a48ef769cdb06dd601e28d843c121125fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logSecurity for biomed-parity 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for biomed_parity-0.5.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.