statistical-power
它能做什么
这个工具可以帮你计算科学研究所需的参与者或样本数量。它还能告诉你,在参与者数量确定的情况下,你的研究最小能检测到多大的效应。
适用场景
- ✓在开始研究之前,用来确定需要纳入多少人。
- ✓在设计实验时,确保它能够发现重要的结果。
- ✓在申请经费或伦理审批时,用来说明参与者人数的合理性。
技能链接
https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/statistical-power/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“要检测两组之间的中等程度差异,我需要多少人?”
每周 5 个新技能,1 分钟读完。
工作原理
你需要提供计划使用的统计检验类型、你认为重要的效应量,以及期望的置信水平。工具会计算所需的样本量,或最小可检测效应。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Statistical Power & Sample Size
Overview
Power analysis plans the probability of rejecting a specified null under an assumed alternative. It answers how many independent experimental units are needed to detect a scientifically important effect, or what effects a feasible sample could detect. Choose the inferential goal first: precision, equivalence, noninferiority, or sequential monitoring need their own calculations; the bundled superiority-test helpers do not cover them.
Four quantities are locked together for any given test: sample size (n), effect size, significance level (α), and power (1 − β). For a fixed design, analysis, and nuisance parameters, fixing three permits solving for the fourth when a solution exists. Every calculation in this skill is some rearrangement of that relationship.
This skill covers the two ways to do power analysis:
- Analytical power calculations (exact under some standard-test assumptions; asymptotic approximations for others) — see
references/closed_form_recipes.md. - Simulation / Monte Carlo (requires a credible data-generating process and a calibrated planned analysis) — see
references/simulation_based_power.md.
For choosing and converting effect sizes — usually the hardest part — see references/effect_sizes.md.
When to Use This Skill
- Determining required sample size before collecting data (a priori power analysis)
- Finding the minimum detectable effect (MDE) for a fixed, already-determined sample size
- Producing power curves (power vs. n, or power vs. effect size) for a grant or protocol
- Justifying a sample size for an IRB submission, grant, or pre-registration
- Powering designs with unequal group sizes or non-1:1 allocation
- Planning complex mixed models, GLMs, clustering, survival, mediation, and interactions through simulation when simpler approximations do not fit
- Accounting for multiple comparisons, attrition/dropout, or clustering in the sample-size estimate
Installation
The local examples were checked on Python 3.13 with statsmodels 0.15.0, SciPy 1.18.1, NumPy 2.5.3, pandas 2.3.3, and Matplotlib 3.11.2. Use an environment separate from the repository's development environment:
uv venv --python 3.13 .venv-power
uv pip install --python .venv-power/bin/python "statsmodels==0.15.0" "scipy==1.18.1" "numpy==2.5.3" "pandas==2.3.3" "matplotlib==3.11.2"
# Optional comparison / survival methods (also checked for current API use):
uv pip install --python .venv-power/bin/python "pingouin==0.7.0" "lifelines==0.30.3"
On Windows use .venv-power/Scripts/python.exe. Lifelines 0.30.3 requires
pandas<3; the tested pin above accommodates it. Mixed models and GLMs are
included in statsmodels. Record versions and seeds with the output; numerical
smoke tests do not establish a study's effect assumptions or Type I error control.
The one decision that drives everything: the effect size
Power calculations are only as trustworthy as the effect size you feed them. Do not invent a number. Use, in rough order of preference:
- A minimally important effect — the smallest effect that would actually change a decision or matter scientifically/clinically (the "smallest effect size of interest", SESOI). This is the most defensible basis: you power to detect what matters, not what you hope to see.
- A pilot or prior-study estimate, with uncertainty and selection bias considered. Small pilots are imprecise; publication or significance-based selection can inflate effects. Use a justified uncertainty model or sensitivity range instead of an arbitrary shrinkage factor.
- A convention (Cohen's small/medium/large) only as a last resort, and say so explicitly.
Whatever you pick, run a sensitivity analysis: report how required n changes across a plausible range of effect sizes, not a single point. A power analysis presented as one number hides its biggest source of uncertainty. See references/effect_sizes.md for benchmarks and conversions between d, f, r, η², odds ratios, and Cohen's h/w.
…
常见问题
什么是'效应量'(effect size)?
它用来衡量你预期发现的差异或关系有多大。效应量越大,就越容易被检测到。
什么是'统计功效'(statistical power)?
它指的是在真实效应存在的情况下,你的研究能够发现该效应的概率。研究者通常把功效目标设为 80%。
我能把它用在已经完成的研究上吗?
不建议这样做。研究结束后再计算功效(即事后功效)可能会产生误导。更好的做法是计算最小可检测效应,或使用置信区间。
详情
作者的原始描述
Calculates sample sizes and statistical power for study planning. Applies when someone asks "how many subjects/samples/replicates do I need", wants an a priori power analysis, a minimum detectable effect (MDE), a power curve, or needs to justify a sample size for a grant, IRB protocol, or pre-registration. Covers closed-form power for t-tests, ANOVA, proportions, correlations, chi-square, and regr
热度
- GitHub 星标
- 51k
- 排名
- #3577
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …