[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6MB79BM7183AQMPYS73W7TS":3,"skill-same:01M6MB79BM7183AQMPYS73W7TS":114},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":31,"publishedAt":54,"linkOnly":55,"markdownContent":56,"markdownBody":57,"frontMatter":58,"refName":66,"commitSha":67,"skillDirectory":68,"forksCount":69,"repositoryHtmlUrl":70,"repositoryHomepageUrl":71,"ownerHtmlUrl":72,"ownerBlogUrl":73,"ownerDescription":74,"updatedAt":75,"install":76,"resources":89},"01M6MB79BM7183AQMPYS73W7TS","statistical-power",null,"Sample-size and statistical power calculations for planning studies. Use whenever someone asks \"how many subjects\u002Fsamples\u002Freplicates 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 regression, plus simulation-based (Monte Carlo) power for designs with no formula — logistic\u002FPoisson regression, mixed models, cluster-randomized trials, survival, and interactions. Use this skill even when the request only mentions an effect size, alpha, or \"80% power\" without saying \"power analysis\" explicitly. For laying out the study (randomization, blocking, factorial\u002FDOE, crossover, sequential designs) use experimental-design; for analyzing data already collected and reporting it use statistical-analysis.","hashgraph-online\u002Fawesome-codex-plugins","hashgraph-online","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F160371962?v=4","01M6CNB6NRJVNNGN14TR01Q6D3","HOL (Hashgraph Online)","01M6JT1HSKKG9V68KQAQGBA7XP",1575,"MIT","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fstatistical-power\u002FSKILL.md",[18,23,26],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000015","视觉设计","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发",{"categoryNo":27,"categoryName":28,"taxonomyType":29,"taxonomyTypeDesc":30},"01JBSEEDCAT000000000000032","设计师","PROFESSION","适用职业",[32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53],"statistical power","power","only","when","analyzing data","request","chi-square","ANOVA","statistics","sample","scipy","formula","design","sample-size","effect","regression","Bash","how","simulation","analysis","MDE","alpha","2026-11-10 10:12:30",false,"---\nname: statistical-power\ndescription: Sample-size and statistical power calculations for planning studies. Use whenever someone asks \"how many subjects\u002Fsamples\u002Freplicates 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 regression, plus simulation-based (Monte Carlo) power for designs with no formula — logistic\u002FPoisson regression, mixed models, cluster-randomized trials, survival, and interactions. Use this skill even when the request only mentions an effect size, alpha, or \"80% power\" without saying \"power analysis\" explicitly. For laying out the study (randomization, blocking, factorial\u002FDOE, crossover, sequential designs) use experimental-design; for analyzing data already collected and reporting it use statistical-analysis.\nlicense: MIT\ncompatibility: Requires Python >=3.10. Examples target statsmodels >=0.14.6, scipy >=1.11, pingouin >=0.6, numpy >=1.26, and matplotlib. Optional extras are statsmodels mixed models and lifelines for simulation-based power.\nallowed-tools: Read Write Edit Bash\nmetadata:\n  version: '1.1'\n  category: ideation-and-design\n  maintainer: Kalaris Labs\n  tags: power analysis, sample size, study design, statistics\n---\n\n# Statistical Power & Sample Size\n\n## Overview\n\nPower analysis answers one of the most consequential questions in study planning: **how large a sample do you need to reliably detect an effect of a given size, and what could you detect with the sample you can afford?** An underpowered study wastes resources and produces inconclusive or irreproducible results; an overpowered one wastes participants, money, and (in clinical work) exposes more people to risk than necessary. Getting this right *before* data collection is the single highest-leverage statistical decision in a project.\n\nFour quantities are locked together for any given test: **sample size (n)**, **effect size**, **significance level (α)**, and **power (1 − β)**. Fix any three and the fourth is determined. Every calculation in this skill is some rearrangement of that relationship.\n\nThis skill covers the two ways to do power analysis:\n- **Closed-form** formulas (fast, exact for standard tests) — see `references\u002Fclosed_form_recipes.md`.\n- **Simulation \u002F Monte Carlo** (works for *any* design or model you can simulate and analyze) — see `references\u002Fsimulation_based_power.md`.\n\nFor choosing and converting effect sizes — usually the hardest part — see `references\u002Feffect_sizes.md`.\n\n## When to Use This Skill\n\n- Determining required sample size before collecting data (a priori power analysis)\n- Finding the minimum detectable effect (MDE) for a fixed, already-determined sample size\n- Producing power curves (power vs. n, or power vs. effect size) for a grant or protocol\n- Justifying a sample size for an IRB submission, grant, or pre-registration\n- Powering designs with unequal group sizes or non-1:1 allocation\n- Powering anything without a textbook formula (mixed models, logistic\u002FPoisson regression, cluster-randomized trials, survival analysis, mediation, interactions) via simulation\n- Accounting for multiple comparisons, attrition\u002Fdropout, or clustering in the sample-size estimate\n\n## Installation\n\nUse **uv**. Pin versions in production; unpinned is fine for exploration.\n\n```bash\nuv pip install \"statsmodels>=0.14.6\" \"scipy>=1.11\" \"pingouin>=0.6\" \"numpy>=1.26\" matplotlib pandas\n# For simulation-based power of advanced models (optional, add as needed):\nuv pip install lifelines            # survival\n# mixed models and GLMs come with statsmodels\n```\n\n**Compatibility note:** use `statsmodels>=0.14.6` with `scipy>=1.11` to avoid `_lazywhere` import errors on SciPy 1.16+. Pingouin 0.5+ renamed power-function arguments to match the names used below.\n\n---\n\n## The one decision that drives everything: the effect size\n\nPower calculations are only as trustworthy as the effect size you feed them. **Do not invent a number.** Use, in rough order of preference:\n\n1. A **minimally important effect** — the smallest effect that would actually change a decision or matter scientifically\u002Fclinically (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.\n2. A **pilot or prior-study estimate**, but shrink it — published and pilot effects are inflated by publication bias and the winner's curse. Powering on a raw pilot estimate routinely underpowers the real study.\n3. A **convention** (Cohen's small\u002Fmedium\u002Flarge) only as a last resort, and say so explicitly.\n\nWhatever 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\u002Feffect_sizes.md` for benchmarks and conversions between d, f, r, η², odds ratios, and Cohen's h\u002Fw.\n\n> **Avoid post-hoc (\"observed\") power.** Computing power from the effect size you just estimated is circular: it is a deterministic function of the p-value and tells you nothing new. If a study is already done and you want to know what it could have detected, report a **sensitivity analysis** (MDE at the achieved n) or, better, the confidence interval around the observed effect. This is a common reviewer complaint — do not produce observed power even if asked without flagging the issue.\n\n---\n\n## Quick recipes (closed-form)\n\nThe bundled `scripts\u002Fpower.py` wraps statsmodels into one consistent interface so you don't have to remember which solver belongs to which test. Run from the skill directory or add `scripts\u002F` to `sys.path`.\n\n```python\nfrom power import sample_size, power, mde, power_curve\n\n# 1. How many per group to detect Cohen's d = 0.5, two-sided, 80% power?\nsample_size(test=\"t_ind\", effect_size=0.5, power=0.80, alpha=0.05)\n# -> required n per group\n\n# 2. Two groups, 3:1 allocation (e.g. more controls than cases)\nsample_size(test=\"t_ind\", effect_size=0.5, power=0.80, ratio=3.0)\n\n# 3. Fixed n=30\u002Fgroup — what's the minimum detectable d at 80% power?\nmde(test=\"t_ind\", nobs1=30, power=0.80, alpha=0.05)\n\n# 4. One-way ANOVA, 4 groups, detect Cohen's f = 0.25\nsample_size(test=\"anova\", effect_size=0.25, k_groups=4, power=0.80)\n\n# 5. Two proportions: 0.40 vs 0.55 (auto-converts to Cohen's h)\nsample_size(test=\"two_proportions\", prop1=0.40, prop2=0.55, power=0.80)\n\n# 6. Correlation: detect r = 0.30\nsample_size(test=\"correlation\", effect_size=0.30, power=0.80)\n\n# 7. Power curve for the grant figure\npower_curve(test=\"t_ind\", effect_size=0.5, n_range=range(10, 120, 5),\n            save=\"power_curve.png\")\n```\n\nSupported `test=` values: `t_ind` (two independent means), `t_paired`\u002F`t_one` (paired or one-sample mean), `anova` (one-way), `two_proportions`, `one_proportion`, `correlation`, `chi2` (goodness-of-fit \u002F contingency via effect size *w*), `linear_regression` (R² increment \u002F f²). Full argument tables and the underlying statsmodels calls are in `references\u002Fclosed_form_recipes.md`.\n\n---\n\n## When there is no formula: simulate\n\nClosed-form power exists only for a handful of simple tests. For **logistic\u002FPoisson regression, mixed-effects \u002F repeated-measures models, cluster-randomized trials, survival analysis, mediation, multi-way interactions, or any non-standard analysis**, the right tool is simulation. The logic is always the same three steps:\n\n1. **Simulate** a dataset from your assumed truth (the effect you want to detect, plus realistic noise, baseline rates, cluster structure, etc.).\n2. **Analyze** it with the *exact* test\u002Fmodel you plan to use on the real data.\n3. **Repeat** many times (≥1,000; 5,000–10,000 for a stable estimate near 80%). Power is the fraction of replicates in which the test is significant.\n\n`scripts\u002Fsimulate_power.py` provides a reusable harness plus worked examples (two-group difference, logistic regression, cluster-randomized trial with an ICC, and a linear mixed model). The core is just:\n\n```python\nfrom simulate_power import simulate_power\n\ndef gen_and_test(n, rng):\n    # build a dataset of size n under the assumed effect, run the planned test,\n    # return True if the result is significant\n    ...\n\nest = simulate_power(gen_and_test, n=200, n_sims=2000, alpha=0.05)\nprint(f\"Power at n=200: {est.power:.3f} (95% CI {est.ci_low:.3f}-{est.ci_high:.3f})\")\n```\n\nReport the **Monte Carlo confidence interval** on the estimate (the harness returns it) so the reader knows whether 0.81 vs. 0.79 is signal or simulation noise. See `references\u002Fsimulation_based_power.md` for the full patterns, including how to search for the n that hits target power and how to model dropout and clustering.\n\n---\n\n## Adjustments people forget\n\nThese routinely make the difference between an adequately powered study and an underpowered one. Apply them explicitly and state that you did.\n\n- **Multiple comparisons.** If the analysis tests *m* hypotheses with a Bonferroni-style correction, power each test at the corrected α (e.g. α\u002Fm), which raises n. Better: power on the family-wise or FDR-controlled procedure directly via simulation. Ignoring this silently underpowers every secondary endpoint.\n- **Attrition \u002F dropout \u002F unusable samples.** Power gives the n you need *analyzed*. Inflate the *enrolled* n: `n_enroll = ceil(n_analyzed \u002F (1 − dropout_rate))`. A 20% dropout rate means enrolling 25% more than the formula returns.\n- **Clustering (design effect).** When observations are nested (patients within clinics, cells within animals, repeated measures within subject), the effective sample size is smaller than the raw count. Inflate by the design effect `DEFF = 1 + (m − 1)·ICC`, where *m* is cluster size and ICC the intraclass correlation. Treating clustered data as independent is **pseudoreplication** and badly overstates power — for cluster-randomized designs, simulate instead.\n- **One- vs. two-sided.** Two-sided is the default and almost always the right choice; a one-sided test buys power only by refusing to detect an effect in the unexpected direction. Justify any one-sided test.\n- **Unequal allocation.** Equal groups are most efficient for a fixed total n. If allocation is fixed by design (e.g. 2:1 treatment:control), pass `ratio=` so the calculation reflects it.\n\n---\n\n## Workflow\n\n1. **State the design and the planned analysis.** The test you will run determines the power method. If the analysis is a mixed model or GLM, go straight to simulation.\n2. **Choose the effect size** on a defensible basis (SESOI > shrunk pilot > convention) and write down the justification.\n3. **Set α and target power.** Conventional defaults are α = 0.05 (two-sided) and power = 0.80; 0.90 is common for confirmatory\u002Fclinical work. State them.\n4. **Compute** with `scripts\u002Fpower.py` (closed-form) or `scripts\u002Fsimulate_power.py` (simulation).\n5. **Sensitivity analysis.** Recompute across a range of plausible effect sizes and produce a power curve. This is the deliverable, not a single number.\n6. **Apply adjustments** for dropout, clustering, and multiplicity.\n7. **Report** following the template below.\n\n---\n\n## Reporting template\n\nA defensible power statement contains every input, so a reader could reproduce it. Adapt:\n\n```\nA priori power analysis was conducted to determine the sample size needed to detect\na [between-group difference of Cohen's d = 0.50], which we considered the smallest\neffect of clinical interest. With α = .05 (two-sided) and power = .80, a two-sample\nt-test requires n = 64 per group (128 total; computed with statsmodels 0.14).\nAllowing for 20% attrition, we will enrol 160 participants. A sensitivity analysis\nshowed required n ranges from 45 to 105 per group across plausible effects\nd = 0.40–0.60 (Figure X).\n```\n\nFor simulation: also state the data-generating assumptions (baseline rate, residual SD, ICC, cluster sizes), the number of simulations, and the Monte Carlo CI.\n\n---\n\n## Common pitfalls\n\n1. **Inventing the effect size** or copying an inflated pilot estimate — the most common way power analyses go wrong.\n2. **Reporting a single n** instead of a sensitivity range \u002F power curve.\n3. **Post-hoc \u002F observed power** — circular and uninformative; use sensitivity analysis or the effect-size CI instead.\n4. **Ignoring clustering** (pseudoreplication) — counting cells\u002Fmeasurements as if they were independent subjects.\n5. **Forgetting dropout** — powering the analyzed n but enrolling the same number.\n6. **Confusing α with power**, or one-sided with two-sided.\n7. **Powering only the primary endpoint** while reporting secondary\u002Finteraction tests that need far larger n.\n8. **Using a t-test formula for a model you won't actually fit** (e.g. planning a logistic regression with a means-based calculation) — match the power method to the planned analysis.\n\n---\n\n## Resources\n\n### Scripts\n- `scripts\u002Fpower.py` — unified closed-form interface (`sample_size`, `power`, `mde`, `power_curve`) over statsmodels\u002Fpingouin for all standard tests.\n- `scripts\u002Fsimulate_power.py` — Monte Carlo power harness with `simulate_power()` and `find_sample_size()`, plus worked examples (two-group, logistic regression, cluster-randomized, linear mixed model).\n\n### References\n- `references\u002Fclosed_form_recipes.md` — per-test argument tables and exact statsmodels\u002Fpingouin calls, including proportions, chi-square, and regression.\n- `references\u002Fsimulation_based_power.md` — full simulation patterns for GLMs, mixed models, cluster designs, survival, and dropout.\n- `references\u002Feffect_sizes.md` — choosing effect sizes (SESOI), Cohen's benchmarks, and conversions between d, f, r, η²\u002Ff², OR, h, and w.\n\n### Related skills\n- **experimental-design** — once you know n, lay out the actual study (randomization, blocking, factorial\u002FDOE, crossover, sequential designs).\n- **statistical-analysis** — assumption checks, running the test, effect sizes, and APA reporting after data collection.\n- **statsmodels** \u002F **pymc** — fitting the models referenced here.\n\n### Key references\n- Cohen, J. (1988). *Statistical Power Analysis for the Behavioral Sciences* (2nd ed.).\n- Lakens, D. (2022). *Sample Size Justification*. Collabra: Psychology, 8(1).\n- Arnold, B. F. et al. (2011). Simulation methods to estimate design power. *BMC Medical Research Methodology*, 11:94.\n\n## Agent operating procedure\n\n1. **Check the environment.** Clarify the research goal, constraints (budget, time, ethics) and the decision the user needs to make.\n2. **Pin down the inputs.** Confirm formats, identifiers and parameters from the data or the user. Ask rather than guess any value that changes the result.\n3. **Run a small version first.** Propose a short shortlist of options with explicit assumptions before expanding any of them.\n4. **Execute the full task** using the instructions and references above.\n5. **Validate the result.** Assumptions are stated, alternatives are compared on explicit criteria, and statistical plans include power and analysis choices.\n6. **Report.** State what was run (versions, commands, parameters), what was checked, and what is still uncertain.\n\n| If this happens | Do this |\n|---|---|\n| A design choice depends on unknown effect sizes or costs | Present scenarios (optimistic, expected, pessimistic) instead of a single guess. |\n| A function, flag or endpoint in these instructions is missing in the installed version | Check the installed version's own documentation (`help()`, `--help`, official docs), adapt, and tell the user. Never invent an API. |\n| A required input, identifier or parameter is ambiguous | Ask the user, or state the assumption explicitly before running. |\n\n**Integrity rules**\n\n- Never fabricate results, parameters, identifiers, citations or statistics. If something cannot be run or verified, say so plainly.\n- Label speculation as speculation; separate established evidence from new hypotheses.\n- Treat version-specific details here as possibly outdated: confirm them against the official documentation for the installed version.\n- Ask before actions that cost money, consume shared GPUs or cloud quota, touch personal or patient data, or cannot be undone.\n","# Statistical Power & Sample Size\n\n## Overview\n\nPower analysis answers one of the most consequential questions in study planning: **how large a sample do you need to reliably detect an effect of a given size, and what could you detect with the sample you can afford?** An underpowered study wastes resources and produces inconclusive or irreproducible results; an overpowered one wastes participants, money, and (in clinical work) exposes more people to risk than necessary. Getting this right *before* data collection is the single highest-leverage statistical decision in a project.\n\nFour quantities are locked together for any given test: **sample size (n)**, **effect size**, **significance level (α)**, and **power (1 − β)**. Fix any three and the fourth is determined. Every calculation in this skill is some rearrangement of that relationship.\n\nThis skill covers the two ways to do power analysis:\n- **Closed-form** formulas (fast, exact for standard tests) — see `references\u002Fclosed_form_recipes.md`.\n- **Simulation \u002F Monte Carlo** (works for *any* design or model you can simulate and analyze) — see `references\u002Fsimulation_based_power.md`.\n\nFor choosing and converting effect sizes — usually the hardest part — see `references\u002Feffect_sizes.md`.\n\n## When to Use This Skill\n\n- Determining required sample size before collecting data (a priori power analysis)\n- Finding the minimum detectable effect (MDE) for a fixed, already-determined sample size\n- Producing power curves (power vs. n, or power vs. effect size) for a grant or protocol\n- Justifying a sample size for an IRB submission, grant, or pre-registration\n- Powering designs with unequal group sizes or non-1:1 allocation\n- Powering anything without a textbook formula (mixed models, logistic\u002FPoisson regression, cluster-randomized trials, survival analysis, mediation, interactions) via simulation\n- Accounting for multiple comparisons, attrition\u002Fdropout, or clustering in the sample-size estimate\n\n## Installation\n\nUse **uv**. Pin versions in production; unpinned is fine for exploration.\n\n```bash\nuv pip install \"statsmodels>=0.14.6\" \"scipy>=1.11\" \"pingouin>=0.6\" \"numpy>=1.26\" matplotlib pandas\n# For simulation-based power of advanced models (optional, add as needed):\nuv pip install lifelines            # survival\n# mixed models and GLMs come with statsmodels\n```\n\n**Compatibility note:** use `statsmodels>=0.14.6` with `scipy>=1.11` to avoid `_lazywhere` import errors on SciPy 1.16+. Pingouin 0.5+ renamed power-function arguments to match the names used below.\n\n---\n\n## The one decision that drives everything: the effect size\n\nPower calculations are only as trustworthy as the effect size you feed them. **Do not invent a number.** Use, in rough order of preference:\n\n1. A **minimally important effect** — the smallest effect that would actually change a decision or matter scientifically\u002Fclinically (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.\n2. A **pilot or prior-study estimate**, but shrink it — published and pilot effects are inflated by publication bias and the winner's curse. Powering on a raw pilot estimate routinely underpowers the real study.\n3. A **convention** (Cohen's small\u002Fmedium\u002Flarge) only as a last resort, and say so explicitly.\n\nWhatever 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\u002Feffect_sizes.md` for benchmarks and conversions between d, f, r, η², odds ratios, and Cohen's h\u002Fw.\n\n> **Avoid post-hoc (\"observed\") power.** Computing power from the effect size you just estimated is circular: it is a deterministic function of the p-value and tells you nothing new. If a study is already done and you want to know what it could have detected, report a **sensitivity analysis** (MDE at the achieved n) or, better, the confidence interval around the observed effect. This is a common reviewer complaint — do not produce observed power even if asked without flagging the issue.\n\n---\n\n## Quick recipes (closed-form)\n\nThe bundled `scripts\u002Fpower.py` wraps statsmodels into one consistent interface so you don't have to remember which solver belongs to which test. Run from the skill directory or add `scripts\u002F` to `sys.path`.\n\n```python\nfrom power import sample_size, power, mde, power_curve\n\n# 1. How many per group to detect Cohen's d = 0.5, two-sided, 80% power?\nsample_size(test=\"t_ind\", effect_size=0.5, power=0.80, alpha=0.05)\n# -> required n per group\n\n# 2. Two groups, 3:1 allocation (e.g. more controls than cases)\nsample_size(test=\"t_ind\", effect_size=0.5, power=0.80, ratio=3.0)\n\n# 3. Fixed n=30\u002Fgroup — what's the minimum detectable d at 80% power?\nmde(test=\"t_ind\", nobs1=30, power=0.80, alpha=0.05)\n\n# 4. One-way ANOVA, 4 groups, detect Cohen's f = 0.25\nsample_size(test=\"anova\", effect_size=0.25, k_groups=4, power=0.80)\n\n# 5. Two proportions: 0.40 vs 0.55 (auto-converts to Cohen's h)\nsample_size(test=\"two_proportions\", prop1=0.40, prop2=0.55, power=0.80)\n\n# 6. Correlation: detect r = 0.30\nsample_size(test=\"correlation\", effect_size=0.30, power=0.80)\n\n# 7. Power curve for the grant figure\npower_curve(test=\"t_ind\", effect_size=0.5, n_range=range(10, 120, 5),\n            save=\"power_curve.png\")\n```\n\nSupported `test=` values: `t_ind` (two independent means), `t_paired`\u002F`t_one` (paired or one-sample mean), `anova` (one-way), `two_proportions`, `one_proportion`, `correlation`, `chi2` (goodness-of-fit \u002F contingency via effect size *w*), `linear_regression` (R² increment \u002F f²). Full argument tables and the underlying statsmodels calls are in `references\u002Fclosed_form_recipes.md`.\n\n---\n\n## When there is no formula: simulate\n\nClosed-form power exists only for a handful of simple tests. For **logistic\u002FPoisson regression, mixed-effects \u002F repeated-measures models, cluster-randomized trials, survival analysis, mediation, multi-way interactions, or any non-standard analysis**, the right tool is simulation. The logic is always the same three steps:\n\n1. **Simulate** a dataset from your assumed truth (the effect you want to detect, plus realistic noise, baseline rates, cluster structure, etc.).\n2. **Analyze** it with the *exact* test\u002Fmodel you plan to use on the real data.\n3. **Repeat** many times (≥1,000; 5,000–10,000 for a stable estimate near 80%). Power is the fraction of replicates in which the test is significant.\n\n`scripts\u002Fsimulate_power.py` provides a reusable harness plus worked examples (two-group difference, logistic regression, cluster-randomized trial with an ICC, and a linear mixed model). The core is just:\n\n```python\nfrom simulate_power import simulate_power\n\ndef gen_and_test(n, rng):\n    # build a dataset of size n under the assumed effect, run the planned test,\n    # return True if the result is significant\n    ...\n\nest = simulate_power(gen_and_test, n=200, n_sims=2000, alpha=0.05)\nprint(f\"Power at n=200: {est.power:.3f} (95% CI {est.ci_low:.3f}-{est.ci_high:.3f})\")\n```\n\nReport the **Monte Carlo confidence interval** on the estimate (the harness returns it) so the reader knows whether 0.81 vs. 0.79 is signal or simulation noise. See `references\u002Fsimulation_based_power.md` for the full patterns, including how to search for the n that hits target power and how to model dropout and clustering.\n\n---\n\n## Adjustments people forget\n\nThese routinely make the difference between an adequately powered study and an underpowered one. Apply them explicitly and state that you did.\n\n- **Multiple comparisons.** If the analysis tests *m* hypotheses with a Bonferroni-style correction, power each test at the corrected α (e.g. α\u002Fm), which raises n. Better: power on the family-wise or FDR-controlled procedure directly via simulation. Ignoring this silently underpowers every secondary endpoint.\n- **Attrition \u002F dropout \u002F unusable samples.** Power gives the n you need *analyzed*. Inflate the *enrolled* n: `n_enroll = ceil(n_analyzed \u002F (1 − dropout_rate))`. A 20% dropout rate means enrolling 25% more than the formula returns.\n- **Clustering (design effect).** When observations are nested (patients within clinics, cells within animals, repeated measures within subject), the effective sample size is smaller than the raw count. Inflate by the design effect `DEFF = 1 + (m − 1)·ICC`, where *m* is cluster size and ICC the intraclass correlation. Treating clustered data as independent is **pseudoreplication** and badly overstates power — for cluster-randomized designs, simulate instead.\n- **One- vs. two-sided.** Two-sided is the default and almost always the right choice; a one-sided test buys power only by refusing to detect an effect in the unexpected direction. Justify any one-sided test.\n- **Unequal allocation.** Equal groups are most efficient for a fixed total n. If allocation is fixed by design (e.g. 2:1 treatment:control), pass `ratio=` so the calculation reflects it.\n\n---\n\n## Workflow\n\n1. **State the design and the planned analysis.** The test you will run determines the power method. If the analysis is a mixed model or GLM, go straight to simulation.\n2. **Choose the effect size** on a defensible basis (SESOI > shrunk pilot > convention) and write down the justification.\n3. **Set α and target power.** Conventional defaults are α = 0.05 (two-sided) and power = 0.80; 0.90 is common for confirmatory\u002Fclinical work. State them.\n4. **Compute** with `scripts\u002Fpower.py` (closed-form) or `scripts\u002Fsimulate_power.py` (simulation).\n5. **Sensitivity analysis.** Recompute across a range of plausible effect sizes and produce a power curve. This is the deliverable, not a single number.\n6. **Apply adjustments** for dropout, clustering, and multiplicity.\n7. **Report** following the template below.\n\n---\n\n## Reporting template\n\nA defensible power statement contains every input, so a reader could reproduce it. Adapt:\n\n```\nA priori power analysis was conducted to determine the sample size needed to detect\na [between-group difference of Cohen's d = 0.50], which we considered the smallest\neffect of clinical interest. With α = .05 (two-sided) and power = .80, a two-sample\nt-test requires n = 64 per group (128 total; computed with statsmodels 0.14).\nAllowing for 20% attrition, we will enrol 160 participants. A sensitivity analysis\nshowed required n ranges from 45 to 105 per group across plausible effects\nd = 0.40–0.60 (Figure X).\n```\n\nFor simulation: also state the data-generating assumptions (baseline rate, residual SD, ICC, cluster sizes), the number of simulations, and the Monte Carlo CI.\n\n---\n\n## Common pitfalls\n\n1. **Inventing the effect size** or copying an inflated pilot estimate — the most common way power analyses go wrong.\n2. **Reporting a single n** instead of a sensitivity range \u002F power curve.\n3. **Post-hoc \u002F observed power** — circular and uninformative; use sensitivity analysis or the effect-size CI instead.\n4. **Ignoring clustering** (pseudoreplication) — counting cells\u002Fmeasurements as if they were independent subjects.\n5. **Forgetting dropout** — powering the analyzed n but enrolling the same number.\n6. **Confusing α with power**, or one-sided with two-sided.\n7. **Powering only the primary endpoint** while reporting secondary\u002Finteraction tests that need far larger n.\n8. **Using a t-test formula for a model you won't actually fit** (e.g. planning a logistic regression with a means-based calculation) — match the power method to the planned analysis.\n\n---\n\n## Resources\n\n### Scripts\n- `scripts\u002Fpower.py` — unified closed-form interface (`sample_size`, `power`, `mde`, `power_curve`) over statsmodels\u002Fpingouin for all standard tests.\n- `scripts\u002Fsimulate_power.py` — Monte Carlo power harness with `simulate_power()` and `find_sample_size()`, plus worked examples (two-group, logistic regression, cluster-randomized, linear mixed model).\n\n### References\n- `references\u002Fclosed_form_recipes.md` — per-test argument tables and exact statsmodels\u002Fpingouin calls, including proportions, chi-square, and regression.\n- `references\u002Fsimulation_based_power.md` — full simulation patterns for GLMs, mixed models, cluster designs, survival, and dropout.\n- `references\u002Feffect_sizes.md` — choosing effect sizes (SESOI), Cohen's benchmarks, and conversions between d, f, r, η²\u002Ff², OR, h, and w.\n\n### Related skills\n- **experimental-design** — once you know n, lay out the actual study (randomization, blocking, factorial\u002FDOE, crossover, sequential designs).\n- **statistical-analysis** — assumption checks, running the test, effect sizes, and APA reporting after data collection.\n- **statsmodels** \u002F **pymc** — fitting the models referenced here.\n\n### Key references\n- Cohen, J. (1988). *Statistical Power Analysis for the Behavioral Sciences* (2nd ed.).\n- Lakens, D. (2022). *Sample Size Justification*. Collabra: Psychology, 8(1).\n- Arnold, B. F. et al. (2011). Simulation methods to estimate design power. *BMC Medical Research Methodology*, 11:94.\n\n## Agent operating procedure\n\n1. **Check the environment.** Clarify the research goal, constraints (budget, time, ethics) and the decision the user needs to make.\n2. **Pin down the inputs.** Confirm formats, identifiers and parameters from the data or the user. Ask rather than guess any value that changes the result.\n3. **Run a small version first.** Propose a short shortlist of options with explicit assumptions before expanding any of them.\n4. **Execute the full task** using the instructions and references above.\n5. **Validate the result.** Assumptions are stated, alternatives are compared on explicit criteria, and statistical plans include power and analysis choices.\n6. **Report.** State what was run (versions, commands, parameters), what was checked, and what is still uncertain.\n\n| If this happens | Do this |\n|---|---|\n| A design choice depends on unknown effect sizes or costs | Present scenarios (optimistic, expected, pessimistic) instead of a single guess. |\n| A function, flag or endpoint in these instructions is missing in the installed version | Check the installed version's own documentation (`help()`, `--help`, official docs), adapt, and tell the user. Never invent an API. |\n| A required input, identifier or parameter is ambiguous | Ask the user, or state the assumption explicitly before running. |\n\n**Integrity rules**\n\n- Never fabricate results, parameters, identifiers, citations or statistics. If something cannot be run or verified, say so plainly.\n- Label speculation as speculation; separate established evidence from new hypotheses.\n- Treat version-specific details here as possibly outdated: confirm them against the official documentation for the installed version.\n- Ask before actions that cost money, consume shared GPUs or cloud quota, touch personal or patient data, or cannot be undone.\n",{"name":5,"license":15,"metadata":59,"description":7,"allowed-tools":64,"compatibility":65},{"tags":60,"version":61,"category":62,"maintainer":63},"power analysis, sample size, study design, statistics","1.1","ideation-and-design","Kalaris Labs","Read Write Edit Bash","Requires Python >=3.10. Examples target statsmodels >=0.14.6, scipy >=1.11, pingouin >=0.6, numpy >=1.26, and matplotlib. Optional extras are statsmodels mixed models and lifelines for simulation-based power.","main","2b63f856ce19c2a797929cacabd9e0fc936812fa","plugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fstatistical-power",491,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins","https:\u002F\u002Fhol.org\u002Fplugins\u002Fbest-codex-plugins","https:\u002F\u002Fgithub.com\u002Fhashgraph-online","https:\u002F\u002Fhol.org","Open-source standards and developer tools for interoperable AI agents: discovery, identity, communication, payments, privacy and security.","2026-11-14 14:06:13",{"source":8,"skillName":5,"commands":77,"prompt":87,"zipAvailable":88},[78,81,84],{"tool":79,"command":80},"npx","npx skills add hashgraph-online\u002Fawesome-codex-plugins --skill statistical-power",{"tool":82,"command":83},"bunx","bunx skills add hashgraph-online\u002Fawesome-codex-plugins --skill statistical-power",{"tool":85,"command":86},"pnpm","pnpm dlx skills add hashgraph-online\u002Fawesome-codex-plugins --skill statistical-power","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fstatistical-power\u002FSKILL.md",true,[90,96,100,104,110],{"path":91,"resourceType":92,"resourceTypeDesc":93,"sizeBytes":94,"sourceHtmlUrl":95},"references\u002Fclosed_form_recipes.md","REFERENCE","参考文档",6809,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fstatistical-power\u002Freferences\u002Fclosed_form_recipes.md",{"path":97,"resourceType":92,"resourceTypeDesc":93,"sizeBytes":98,"sourceHtmlUrl":99},"references\u002Feffect_sizes.md",4919,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fstatistical-power\u002Freferences\u002Feffect_sizes.md",{"path":101,"resourceType":92,"resourceTypeDesc":93,"sizeBytes":102,"sourceHtmlUrl":103},"references\u002Fsimulation_based_power.md",5684,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fstatistical-power\u002Freferences\u002Fsimulation_based_power.md",{"path":105,"resourceType":106,"resourceTypeDesc":107,"sizeBytes":108,"sourceHtmlUrl":109},"scripts\u002Fpower.py","SCRIPT","脚本",12726,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fstatistical-power\u002Fscripts\u002Fpower.py",{"path":111,"resourceType":106,"resourceTypeDesc":107,"sizeBytes":112,"sourceHtmlUrl":113},"scripts\u002Fsimulate_power.py",8009,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fstatistical-power\u002Fscripts\u002Fsimulate_power.py",[115,124,132,140,148,156],{"skillNo":116,"name":117,"nameZh":6,"description":118,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":119,"sourceHtmlUrl":120,"categories":121,"keywords":122,"publishedAt":123},"01M7DV332YQMGD8WTRJ9DZQXTB","worktable-review-with-annotations","Create, inspect, reply to, update, or resolve situated Worktable annotations. Use when feedback belongs to a Doc section, block, text range, or HTML Doc, or when the user asks to address existing review feedback and coordinate a requested artifact edit.","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fworktable\u002Fworktable-plugin\u002Fskills\u002Fworktable-review-with-annotations\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fworktable\u002Fworktable-plugin\u002Fskills\u002Fworktable-review-with-annotations\u002FSKILL.md",[],[],"2026-11-15 14:19:17",{"skillNo":125,"name":126,"nameZh":6,"description":127,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":128,"sourceHtmlUrl":129,"categories":130,"keywords":131,"publishedAt":123},"01M7DV2YGHCZVBEB1AHYB6CGHE","worktable-find-and-synthesize-context","Find, assess, and synthesize context from Worktable Docs and Records. Use when the user asks what a workspace contains, wants workspace-backed research, needs current facts reconciled across artifacts, or requests a cited synthesis without changing workspace state.","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fworktable\u002Fworktable-plugin\u002Fskills\u002Fworktable-find-and-synthesize-context\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fworktable\u002Fworktable-plugin\u002Fskills\u002Fworktable-find-and-synthesize-context\u002FSKILL.md",[],[],{"skillNo":133,"name":134,"nameZh":6,"description":135,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":136,"sourceHtmlUrl":137,"categories":138,"keywords":139,"publishedAt":123},"01M7DV2TQN1H11ME2SAF9MXN7V","worktable-create-or-update-docs","Create, edit, rename, or maintain narrative Worktable Docs. Use for plans, decisions, briefs, notes, research syntheses, and other durable prose when the user requests a new artifact or a safe update to an existing one.","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fworktable\u002Fworktable-plugin\u002Fskills\u002Fworktable-create-or-update-docs\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fworktable\u002Fworktable-plugin\u002Fskills\u002Fworktable-create-or-update-docs\u002FSKILL.md",[],[],{"skillNo":141,"name":142,"nameZh":6,"description":143,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":144,"sourceHtmlUrl":145,"categories":146,"keywords":147,"publishedAt":123},"01M7DV2NE452NEA8TXATKSNAJH","worktable-create-or-manage-records","Organize repeated structured information as durable Worktable Records. Use for research datasets, inventories, directories, pipelines, trackers, and other collections whose items need identity, fields, filtering, links, validation, or individual updates.","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fworktable\u002Fworktable-plugin\u002Fskills\u002Fworktable-create-or-manage-records\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fworktable\u002Fworktable-plugin\u002Fskills\u002Fworktable-create-or-manage-records\u002FSKILL.md",[],[],{"skillNo":149,"name":150,"nameZh":6,"description":151,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":152,"sourceHtmlUrl":153,"categories":154,"keywords":155,"publishedAt":123},"01M7DV2HENRBR2KSCVM064WH0Y","worktable-create-or-manage-interactive-html","Create or improve durable visual and interactive artifacts in Worktable. Use for dashboards, trackers, calculators, mini apps, slide presentations, and other requests that benefit from a polished HTML Doc.","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fworktable\u002Fworktable-plugin\u002Fskills\u002Fworktable-create-or-manage-interactive-html\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fworktable\u002Fworktable-plugin\u002Fskills\u002Fworktable-create-or-manage-interactive-html\u002FSKILL.md",[],[],{"skillNo":157,"name":158,"nameZh":6,"description":159,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":160,"sourceHtmlUrl":161,"categories":162,"keywords":163,"publishedAt":123},"01M7DV2CADR5R7RQFFYPNAGR9Y","worktable-collaborate-threads","Read, answer, and hand off messages through durable Worktable threads with users or other authenticated participants. Use when the user asks to check addressed messages, reply to a participant, continue a thread, request another agent's help, wait briefly for a response, or watch for comments and messages sent to the agent.","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fworktable\u002Fworktable-plugin\u002Fskills\u002Fworktable-collaborate-threads\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fworktable\u002Fworktable-plugin\u002Fskills\u002Fworktable-collaborate-threads\u002FSKILL.md",[],[]]