Power analysis

From pedrohcgs/claude-code-my-workflow · View interactive version

Power analysis is an AI agent skill from the GitHub repository pedrohcgs/claude-code-my-workflow. Compute statistical power, required sample size, and minimum detectable effect (MDE) for a study design, then write a registry-ready power section. Handles two-arm RCTs (with clustering / ICC and unequal allocation), multiple-arm corrections, and a simulation-based power option for non-standard desi

How to use this skill

Skill file

`/power-analysis` — Power / MDE for study design

Compute the three interlocking quantities of an ex-ante design calculation — power, required N, and minimum detectable effect (MDE) — and emit a power section the user can paste straight into a preregistration. Analytical for standard designs; simulation-based (reusing the /simulation-study harness pattern) for non-standard ones.

Core principle: a power calculation is a design-time commitment made before the data exist. Fix any two of {effect size, N, power} and solve for the third; never back out a "power" number from a realised estimate (that is post-hoc power, and it is uninformative — see "What this skill does NOT do").

When to use

Inputs

$ARGUMENTS may carry flags; missing pieces are elicited in Phase 0.

Workflow

Phase 0 — Elicit the design

Gather the design parameters; ask once for anything missing rather than fabricating. Required:

Echo a Pre-Flight Report (design, the two fixed quantities, the one being solved for, alpha, power, allocation, ICC/clusters, multiplicity) before computing. If the estimand or the SD source is ambiguous, stop and ask.

Phase 1 — Analytical power (standard designs)

For two-arm RCTs, clustered RCTs, and multi-arm comparisons, compute analytically. Prefer R pwr / WebPower (or a closed-form power.t.test / power.prop.test); for clustered designs inflate variance by DEFF, or use pwr on the effective N. Stata users: power twomeans / power twoproportions / power, cluster; Python: statsmodels.stats.power. Emit a short script to scripts/R/power_<slug>.R (or .do / .py) so the calc is reproducible, not a one-off console number.

Sweep a grid (N or #clusters × effect size) so Phase 3 can draw a power curve and an MDE-vs-N curve.

Phase 2 — Simulation-based power (non-standard designs)

When the design is not a clean two-arm comparison — DiD / staggered event-study, IV / 2SLS, panel with serial correlation, a non-normal or censored outcome, or any estimator with no closed-form SE — switch to simulation. Reuse the /simulation-study harness exactly (see CODE1 and CODE2):

  1. Seeded, parameterized DGP that embeds the hypothesized effect (and the null DGP for size). set.seed(YYYYMMDD) once; L'Ecuyer streams if parallel.
  2. Estimator = the one you will actually use on the real data (e.g. fixest::feols two-way FE, did::att_gt, AER::ivreg), returning est, se, ci, p, reject.
  3. Power = share of reps rejecting H0 at alpha; size = rejection rate under the null DGP (verify it is near nominal before trusting power). Report each with its Monte Carlo SE = sqrt(p(1−p)/R).
  4. Sweep N (or #clusters / #periods) to trace the power curve; save the raw per-rep tibble via saveRDS() to output/.

A simulated power number without an MCSE, or without a verified size check, is not yet an answer.

Phase 3 — Write the power section

Produce the deliverables under quality_reports/power/:

# Power Analysis: <study title>
**Date:** YYYY-MM-DD · **Design:** <rct|cluster|multiarm|sim> · **Method:** <analytical|simulation, R/Stata/Python>

| Quantity | Value |
|---|---|
| alpha (sided) | 0.05 (two-sided) |
| Target power | 0.80 |
| Baseline mean (SD) | <m0> (<sd>) |
| Allocation (T:C) | 1:1 |
| ICC / cluster size / #clusters | <ρ> / <m> / <J>  (DEFF = <…>) |
| Total N (analysis sample) | <N> |
| **MDE (raw / standardized)** | **<Δ> / <d>** |
| Achieved power at planned N | <…>  (± MCSE <…> if simulated) |

## Methods paragraph (paste into preregistration)
> Assuming a baseline outcome mean of <m0> (SD <sd>), 1:1 allocation, and a two-sided
> test at α = 0.05, a total sample of <N> [<J> clusters of <m>, ICC = <ρ>] yields 80%
> power to detect a minimum effect of <Δ> (<d> SD). [Simulation: under the hypothesized
> DGP, <P>% of <R> replications rejected H0 (MCSE <…>); size under the null was <…>.]

Phase 4 — Handoff

If invoked by /preregister, return the methods paragraph + MDE row for the preregistration's power section. If standalone, print the save paths and remind the user the MDE is a design commitment to record before data collection.

Exit behavior

Flags

Cross-references

What this skill does NOT do

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.