[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M74ZMQCAAFVSCRV76EK3WJYN":3,"skill-same:01M74ZMQCAAFVSCRV76EK3WJYN":79},{"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":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":31,"commitSha":32,"skillDirectory":33,"forksCount":34,"repositoryHtmlUrl":35,"repositoryHomepageUrl":36,"ownerHtmlUrl":37,"ownerBlogUrl":38,"ownerDescription":39,"updatedAt":40,"install":41,"resources":54},"01M74ZMQCAAFVSCRV76EK3WJYN","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.","KalarisLabs\u002Fresearch-agent-skills","KalarisLabs","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F300878568?v=4","01M74Y7MT23GXXC56VM6TVSXZY","Kalarislabs","01M74Y7MTQM9REXZX4SNXWX95C",124,"MIT","https:\u002F\u002Fgithub.com\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fstatistical-power\u002FSKILL.md",[],[],"2026-11-11 17:47:46",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":24,"description":7,"allowed-tools":29,"compatibility":30},{"tags":25,"version":26,"category":27,"maintainer":28},"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","29fe36d26127205057d5e0ed8425f6b0e9a8c13a","skills\u002Fstatistical-power",13,"https:\u002F\u002Fgithub.com\u002FKalarisLabs\u002Fresearch-agent-skills","https:\u002F\u002Fdocs.kalarislabs.com\u002Fresearch-agent-skills","https:\u002F\u002Fgithub.com\u002FKalarisLabs","kalarislabs.com","Applied AI lab building the infrastructure for the agentic era","2026-11-13 00:03:12",{"source":8,"skillName":5,"commands":42,"prompt":52,"zipAvailable":53},[43,46,49],{"tool":44,"command":45},"npx","npx skills add KalarisLabs\u002Fresearch-agent-skills --skill statistical-power",{"tool":47,"command":48},"bunx","bunx skills add KalarisLabs\u002Fresearch-agent-skills --skill statistical-power",{"tool":50,"command":51},"pnpm","pnpm dlx skills add KalarisLabs\u002Fresearch-agent-skills --skill statistical-power","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fstatistical-power\u002FSKILL.md",true,[55,61,65,69,75],{"path":56,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":59,"sourceHtmlUrl":60},"references\u002Fclosed_form_recipes.md","REFERENCE","参考文档",6809,"https:\u002F\u002Fgithub.com\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fstatistical-power\u002Freferences\u002Fclosed_form_recipes.md",{"path":62,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":63,"sourceHtmlUrl":64},"references\u002Feffect_sizes.md",4919,"https:\u002F\u002Fgithub.com\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fstatistical-power\u002Freferences\u002Feffect_sizes.md",{"path":66,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":67,"sourceHtmlUrl":68},"references\u002Fsimulation_based_power.md",5684,"https:\u002F\u002Fgithub.com\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fstatistical-power\u002Freferences\u002Fsimulation_based_power.md",{"path":70,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":73,"sourceHtmlUrl":74},"scripts\u002Fpower.py","SCRIPT","脚本",12824,"https:\u002F\u002Fgithub.com\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fstatistical-power\u002Fscripts\u002Fpower.py",{"path":76,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":77,"sourceHtmlUrl":78},"scripts\u002Fsimulate_power.py",8220,"https:\u002F\u002Fgithub.com\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fstatistical-power\u002Fscripts\u002Fsimulate_power.py",[80,87,94,101,108,115],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":19},"01M74ZSRSWD92NYM8TNJRH35DK","zarr-python","Guides use of Zarr-Python 3 for storing chunked, compressed N-dimensional arrays and groups, with local, in-memory, ZIP, and fsspec-backed S3\u002FGCS\u002FHTTP stores, plus NumPy, Dask, and Xarray integration. Covers array creation, resizing and appending, attributes, chunk and shard sizing, codecs, consolidated metadata, and v2-to-v3 migration. Use when creating or opening Zarr arrays or groups, choosing chunk sizes or compression for large datasets, reading or writing arrays on S3 or GCS, appending to time-series arrays, or migrating code from Zarr-Python 2 to 3. Use when setting up parallel I\u002FO with Dask or Xarray. For labeled multi-dimensional datasets, use Xarray instead.","https:\u002F\u002Fgithub.com\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fzarr-python\u002FSKILL.md",[],[],{"skillNo":88,"name":89,"nameZh":6,"description":90,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":19},"01M74ZSK6JG5HKNC1AHF4D97G9","whisper","Transcribes and translates audio with OpenAI's Whisper (openai-whisper Python package and whisper CLI), covering model sizes from tiny to large plus turbo, language specification, initial prompts, word and segment timestamps, temperature fallback, batch processing, and subtitle generation. Use when transcribing speech, podcasts, meetings, or video audio to text. Use when translating non-English speech to English. Use when working with noisy or multilingual audio in any of 99 languages. Use when choosing a Whisper model size for available VRAM. Use when generating subtitles from audio. Not for speaker diarization or live captioning; use AssemblyAI or Deepgram instead.","https:\u002F\u002Fgithub.com\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fwhisper\u002FSKILL.md",[],[],{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":19},"01M74ZSBYQ2EGDFTTA4ZK6K5TR","weights-and-biases","Logs and tracks machine learning experiments with Weights & Biases (W&B, wandb): metrics, hyperparameters, checkpoints, sweeps, artifacts with lineage, model registry, custom charts and shareable reports. Includes integrations for PyTorch, HuggingFace Transformers, PyTorch Lightning and Keras\u002FTensorFlow. Use when logging training runs and comparing them across configurations, running automated hyperparameter sweeps, versioning datasets and models as artifacts, registering model versions, or sharing results with a team workspace. Use when setting up wandb.init for offline or unstable-connection training. Not for general data versioning outside ML runs.","https:\u002F\u002Fgithub.com\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fweights-and-biases\u002FSKILL.md",[],[],{"skillNo":102,"name":103,"nameZh":6,"description":104,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":105,"categories":106,"keywords":107,"publishedAt":19},"01M74ZS5MZTK84WHEQXCVDZ6GB","waypoint-bio","Use when working with Outpost Bio's open microbiome foundation models - the Waypoint checkpoints (Waypoint-6m, Waypoint-45m, Waypoint-170m), the Atlas pretraining corpus, the Compass eight-task benchmark, or the `waypoint` CLI from the `waypoint-bio` package. Covers embedding microbiome samples, fine-tuning on taxonomic abundance data, benchmarking a checkpoint on Compass, pretraining a GPT-2 model on taxonomic abundance profiles, and converting MetaPhlAn, Kraken2, QIIME 2, or MGnify abundance tables into waypoint format.","https:\u002F\u002Fgithub.com\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fwaypoint-bio\u002FSKILL.md",[],[],{"skillNo":109,"name":110,"nameZh":6,"description":111,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":112,"categories":113,"keywords":114,"publishedAt":19},"01M74ZS0TCW96WJAKSG07C5Z7A","verl-rl-training","Provides guidance for training LLMs with reinforcement learning using verl (Volcano Engine RL). Use when implementing RLHF, GRPO, PPO, or other RL algorithms for LLM post-training at scale with flexible infrastructure backends.","https:\u002F\u002Fgithub.com\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fverl-rl-training\u002FSKILL.md",[],[],{"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":6,"sourceHtmlUrl":119,"categories":120,"keywords":121,"publishedAt":19},"01M74ZRVG6SSWGT1N3Q55134KA","venue-templates","Prepare journal manuscripts, conference papers, research posters, and grant documents using venue-specific formatting guidance and bundled LaTeX scaffolds. Use when selecting an official template, checking current page or anonymity rules, adapting academic writing to a venue, or inspecting a submission PDF.","https:\u002F\u002Fgithub.com\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fvenue-templates\u002FSKILL.md",[],[]]