Skip to content

sample-size

Write a sample size justification with formula, inputs, result and sensitivity table for means, proportions, log-rank, non-inferiority and equivalence designs, with dropout inflation. Use when a protocol or SAP needs a defensible sample size.

Stage Clinical development
Tier 1 (deterministic tool)
Standards ICH E9, ICH E9(R1), ICH E10
Minimum pharmaskills 0.3.0
Inputs endpoint type, effect size, variability, alpha, power, allocation ratio, dropout
Outputs sample size md, sample size json
Verified by stats sample-size

Draft for qualified review. Not a validated system and not 21 CFR Part 11 compliant.

Install only this skill: pharmaskills skills install --agent claude-code --skill sample-size (see Install).

Purpose

Produce a sample size justification a statistician can review: the design and test, the inputs with their sources, the exact result from a deterministic calculator, dropout inflation, and a sensitivity table showing how the answer moves when the assumptions are wrong. You choose and explain the design; pharmaskills stats sample-size does every calculation.

When to use / when not to use

Use when a protocol (ICH M11 section 9.4), SAP or briefing document needs a sample size, or when asked "how many patients do we need" for a two-group comparison.

Do not use for: group sequential or adaptive designs, cluster or crossover designs, multiplicity adjusted sample sizes, Bayesian sample sizes, or dose-finding. For those, say the tool does not cover the design and ask for a statistician. Never pick the inputs to hit a target number.

Inputs

Required: endpoint type (continuous, binary, time-to-event), the effect size (mean difference and SD, two proportions, or hazard ratio with event probability), alpha, power, allocation ratio and expected dropout. For non-inferiority or equivalence also the margin and its justification. Ask once for anything missing, then proceed with stated assumptions and [DATA NEEDED: ...] placeholders for the source of every effect size, SD and event rate.

If pharmaskills is not installed, tell the user to run uv tool install pharmaskills, then write the document from templates/sample-size.md with the result left as [DATA NEEDED: run pharmaskills stats sample-size], marked unverified. Do not compute by hand. Check pharmaskills --version is at least min_pharmaskills.

Workflow

  1. Pick the design. Map the endpoint to a design name; read references/designs.md: two-means, two-proportions, logrank, noninf-means, noninf-proportions, equiv-means, equiv-proportions.
  2. Compute. Example: pharmaskills stats sample-size --design two-means --delta 0.5 --sd 1 --power 0.9 --alpha 0.05 --dropout 0.15 --out out/sample_size.json. Run without --dropout as well when the evaluable number is quoted. Exit 2 means an input was rejected (for example power outside 0 to 1): fix the input, never override it.
  3. Read the report. result.n_group1, n_group1_enrolled, events, formula, inputs, assumptions and sensitivity come straight from the JSON.
  4. Write out/sample_size.md from templates/sample-size.md: scope and assumptions, formula, inputs table with a source for each, result (evaluable and enrolled), sensitivity table, limitations, and the statistical reference (ICH E9 section 3.5; non-inferiority or equivalence: ICH E9 section 3.3.2). Link to the estimand in the protocol (ICH E9(R1)) and say which intercurrent-event strategy the effect size assumes.
  5. Banner and provenance. pharmaskills docs banner --apply out/sample_size.md; edit the provenance block to name the inputs and the command lines.
  6. Report the number, the three assumptions it is most sensitive to, and what is unconfirmed.

Output contract

Under out/:

File Content
sample_size.md Formula, inputs with sources, result, dropout inflation, sensitivity table
sample_size.json Tool report (design, inputs, result, assumptions, sensitivity)

Every number in the document comes from the tool report or from an input the user supplied.

Verification

Report pass or fail: the tool exited 0; the evaluable per-arm number in the text equals result.n_group1; the enrolled number equals n_group1_enrolled; the sensitivity table matches sensitivity; each input has a stated source or a [DATA NEEDED] placeholder; invalid inputs are rejected rather than adjusted. Known anchors: delta 0.5 SD, power 90 percent, two-sided alpha 0.05 gives 86 per arm; log-rank events follow Schoenfeld (hazard ratio 0.7, power 80 percent, alpha 0.05 two-sided gives 247 events).

Guardrails

  • Insert the draft banner and a provenance block; the document is for statistician review.
  • Never fabricate an effect size, SD, event rate, margin or a literature source for one. An unsourced input is a [DATA NEEDED: ...] placeholder, and the result is conditional on it.
  • Never tune inputs until the sample size looks affordable. If asked to, refuse and show the sensitivity table instead.
  • State alpha sidedness, the test, and that interim analyses and multiplicity are not included.
  • Do not compute sample sizes by hand or with model-written code; use the tool.
  • State the region assumed only where it matters (for example a regulator-specified margin); otherwise say the calculation is region independent.

References

  • references/designs.md - designs, tool parameters, formulas in words, what is not covered
  • references/guidance-notes.md - ICH E9 and E9(R1) citations, margin and dropout notes
  • Public sources: ICH E9 Statistical Principles for Clinical Trials (sections 3.3.2, 3.5), ICH E9(R1) estimands addendum, ICH E10 (choice of control group).

Templates: templates/sample-size.md. Scripts: scripts/run_sample_size.sh (thin wrapper around pharmaskills stats sample-size).

Examples

Worked example with tool outputs: examples/clinical/sample-size/. Case definitions and anchors: skills/sample-size/evals/cases/.

Worked example

Committed example with inputs and outputs: examples/clinical/sample-size/.

Two-arm parallel trial, continuous primary endpoint, difference 0.5 SD.

Inputs

No fixture files: the example is defined by the parameters in the prompt (delta 0.5, SD 1, alpha 0.05 two-sided, power 0.9, 1:1, dropout 15 percent in the second run; hazard ratio 0.7 and event probability 0.6 in the log-rank run). Effect sizes are illustrative, not from a program.

Outputs (out/, tool reports copied to tool_outputs/)

File How it was made
sample_size.json Real output of pharmaskills stats sample-size --design two-means --delta 0.5 --sd 1 --power 0.9 --alpha 0.05 (86 per arm)
sample_size_dropout15.json Same with --dropout 0.15 (102 per arm enrolled)
sample_size_logrank.json --design logrank --hr 0.7 --event-prob 0.6 --power 0.8 (247 events)
sample_size.md Drafted from those outputs following templates/sample-size.md
refusal_invalid_power.md, refusal_tune_inputs.md Sample correct responses

Reproduce

pharmaskills stats sample-size --design two-means --delta 0.5 --sd 1 --power 0.9 --alpha 0.05 \
  --out sample_size.json

Skill source: skills/sample-size/SKILL.md