Analysis Plan
ASecurityWrite the analysis plan in design/plan.md before the analysis exists, record every deviation from it as it happens, and hold the paper to the study's registration. Use at the start of a paper project, when check reports no-analysis-plan, plan-section-missing, plan-section-empty, feasibility-not-run, planned-result-missing, planned-result-unquoted, planned-results-unkeyed, plan-changed-after-results, not-in-dictionary, registration-missing, registration-not-looked-up, registration-late, regist...
- 2 stars
- 0 votes
- 0 copies
- 1 view
- Added November 6, 2026
Works with
Security analysis
100/100Pro scans all 2 files and shows the line behind each finding
npx -y skills add BasileChretien/manuscript-guard --skill analysis-plan --agent claude-codeAre you the author of Analysis Plan?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/basilechretien-analysis-plan)---
name: analysis-plan
description: Write the analysis plan in design/plan.md before the analysis exists, record every deviation from it as it happens, and hold the paper to the study's registration. Use at the start of a paper project, when check reports no-analysis-plan, plan-section-missing, plan-section-empty, feasibility-not-run, planned-result-missing, planned-result-unquoted, planned-results-unkeyed, plan-changed-after-results, not-in-dictionary, registration-missing, registration-not-looked-up, registration-late, registration-outcomes-undeclared, registration-outcome-not-registered, registration-outcome-role-changed, registration-outcome-dropped, registration-primary-unquoted, planned-package-unloaded, plan-package-unnamed, plan-declarations-unreadable or a control-…, held-out-… or first-reads-… finding, when choosing the packages the analysis will use, or when the analysis is about to do something the plan did not say. Not for finding which dataset could answer the question or how it is reached (use data-sources).
---
# Writing down what you meant to do, before you do it
A result is more credible when the analysis that produced it was written down first. This
is not because departing from a plan is wrong. A departure that was declared is a decision
a reader can weigh; one that nobody recorded looks exactly like having tried several
analyses and reported the one that worked.
G12 warns about the plan and never blocks, at any stage, including submission. That is
deliberate: exploratory work is real work, and a gate that stopped you writing code until a
plan was agreed would be bypassed the first afternoon it cost something. It also means the
gate's approval is worth very little. All the value is in what gets written. A registration
is different, because it is a promise made in public: where the paper is not the study
registered, G12 warns while it is drafted and fails it at submission (below). So are the
controls and the held-out data the plan declares: a control warns and fails at submission,
and a leak of held-out data fails from the analysis stage.
## Where it lives
`design/plan.md`, in UTF-8. The path is fixed. A file saved in another encoding makes the
gate crash, and a crashed gate fails the whole check. `manuscript-guard init` scaffolds
the headings.
The gate matches any heading at any level, ignoring case, against seven requirements:
| Requirement | Headings that count | Headings that do not |
|---|---|---|
| question | Research question, Objective(s) | Aims, Hypothesis |
| design | Design, Study design | |
| population | Population, Study population, Participants, Data source | Data sources |
| exposure | Exposure(s), Intervention(s), Predictor | Predictors |
| outcome | Outcome(s), Endpoint | Endpoints |
| analysis | Analysis, Statistical analyses | Analyses, Methods |
| deviations | Deviations from the plan, Changes to the plan, Protocol amendments | |
The right-hand column is there because those headings look as though they should count and
are reported missing. Rename the heading; do not argue with the pattern.
Two things the gate gets wrong, so check them yourself:
- **Put a sentence directly under every heading.** A section is counted as empty when all
its content sits in subsections, so a `## Population` holding only `### Inclusion` and
`### Exclusion` is flagged.
- **An empty `## Analysis` is never flagged**, because the scaffold's own title,
`# Analysis plan`, already satisfies the requirement. The gate will not tell you the most
important section is blank.
`TBD`, `TODO`, `n/a`, dashes and "see below" count as empty. `Sample size` and
`Sensitivity analyses` are scaffolded but not checked; fill them anyway.
## Writing it
The test of a plan is whether a deviation from it would be recognisable. "Appropriate
statistical methods will be used" cannot be deviated from, so it records nothing. For each
section, write what a reader would need in order to say afterwards "that is not what they
said they would do":
- Research question: one question, stated as the quantity you will estimate.
- Design: the design, and why it answers this question rather than a neighbouring one.
- Population and data source: who or what is included and excluded, over what period,
from which version of which source. The [data-sources](../data-sources/SKILL.md) skill
finds the candidate sources with the author and records how each is reached; name the one
chosen here, by a name its record gives, or `check` says so (`plan-source-unnamed`).
- Exposure: the definition as it will be coded, and the comparator.
- Outcome: the definition as it will be coded. Where two reasonable definitions would
give different counts, choose here, before you have seen which one gives the answer.
- Analysis: the estimator, the model, the covariates, what happens to missing data, any
threshold, and how many comparisons are being made.
- Sample size: what you expect to have and what it can detect, or why that cannot be
calculated in advance. A limit on the data or the money available is a justification
when it is said, with the smallest effect that number can detect (Lakens, *Collabra:
Psychology* 8:33267, 2022, sets out the ways a sample size is justified).
- Sensitivity analyses: which ones, and which result would change your conclusion.
Numbers in the plan are not checked. G2 reads only `manuscript/`, and the plan does not go
in the submission pack.
## How others answered the question
Before the design, the comparator, time zero or the case definition is fixed, read how
studies of the same question did it, judged against a methodological standard rather than
by how many did it, and take what the author decides, with its citation: the
[methods-review](../methods-review/SKILL.md) skill, and `design/methods_review.yaml`.
## The tools for these data
Before the analysis section is fixed, find the software written for this data source and
this question, and let it do what is the source's own logic. A package written with the
source's custodian, or by people who have analysed it for years, knows how the source codes
its records; code written from the data dictionary alone rewrites that logic and gets wrong
the parts nobody wrote down. On VigiBase, the CRAN package `vigicaen` finds a drug's record
numbers in WHODrug (`get_drecno()`), gathers the MedDRA terms under a case definition
(`get_llt_soc()`), and flags each report for a drug and a reaction (`add_drug()`,
`add_adr()`); an analysis that wrote its own joins for those missed what the package
decides for it.
1. **Look.** Search for packages written for this source and this question: the source's
own documentation and user guide, CRAN, Bioconductor and PyPI by the source's name and
the method's, and the CRAN Task View of the field (Epidemiology, Survival,
MetaAnalysis, ClinicalTrials and others). Ask the author which ones they and their
colleagues use.
2. **Read before calling.** Read the help page of each function the analysis will call,
and the package's vignettes, before writing the call: what each argument means, the
default it takes, and what it drops without saying. `add_drug()` counts a report that
names the drug as concomitant unless `repbasis = "s"` asks for the suspected drug only.
Each of these runs in a terminal, with nothing else installed:
```bash
Rscript -e "help('add_drug', package = 'vigicaen')"
Rscript -e "vignette(package = 'vigicaen')"
Rscript -e "vignette('basic_workflow', package = 'vigicaen')"
python -c "import statsmodels.api as sm; help(sm.GLM)"
python -m pydoc statsmodels.genmod.generalized_linear_model.GLM
```
`help()` in R opens the page in the browser when one is set; add
`help_type = 'text'` to print it instead.
3. **Use it.** Call those functions for the source's own logic (identifying a drug, the
levels of a dictionary, which drug is suspected, what counts as a duplicate), and write
your own code for what is the study's: the selection the plan sets out, the model. Where
the analysis rewrites something a package does, say why in the plan. In R, write the
data handling with dplyr and its companions (tidyr, readr, stringr, purrr), unless the
project's code already uses another style (data.table, base R) or the author asks for
one.
4. **Record it.** Under a heading that opens with "Software" ("R packages", "Packages
used", "Libraries" and "Statistical analysis software" do too; "Library preparation"
does not), one list item per package, opening with its name in backticks, then its
version and which of its functions does which step. Put the packages considered and not taken
under a heading of their own below it, each with why. The names there are not taken for
variables of the data dictionary:
```markdown
## Software
- `vigicaen` 2.1.0: `get_drecno()` finds the drug in WHODrug; `get_llt_soc()` the
MedDRA terms of the case definition; `add_drug()` with `repbasis = "s"` flags the
reports where the drug is suspected; `compute_dispro()` the reporting odds ratio.
- `dplyr` and `tidyr`, loaded with `tidyverse`: the selection steps and the counts.
- `R` 4.4.1
### Considered and not used
- `PhViD`: computes signal statistics from a table of counts and does not read
VigiBase's tables, so the counts would have been the analysis's own code.
```
`check` holds the section to the scripts in `analysis/` and `figures/`. A package an item
names that no script loads warns from the analysis stage on (`planned-package-unloaded`);
one a script loads that no item names is a note (`plan-package-unnamed`). A load is
`library()`, `require()`, `requireNamespace()`, `loadNamespace()`, `pkg::` or `pkg:::` in R,
`import`, `from` or `importlib.import_module()` in Python, wherever it stands in the file;
base R, the standard library and the project's own modules are nobody's choice and are not
noted, and a base package R attaches, `stats` for `glm()`, counts as loaded wherever an R
script is read. Three things it cannot know, so write them so it can:
- **The name scripts load.** Where it is not the package's (`sklearn` for
`scikit-learn`, `yaml` for `PyYAML`, `tidyverse` for `dplyr` loaded through
`library(tidyverse)`), give it in the same item, in backticks: every bare name in
backticks in an item counts as that package's, where a script loads it. Write functions
with their brackets, `glm()`, so that they are not taken for packages. Only list items
are read: a table or a sentence names nothing.
- **A name the code computes.** `library(pkg, character.only = TRUE)`, or a package loaded
by another (`pacman::p_load()`), is not read. Load it by its name.
- **A change.** A package dropped, or taken up after the plan was agreed, is a deviation:
write it under Deviations, naming the package in backticks, which stands the finding down.
The version and the functions are for the reader and are not checked. The version the
analysis ran with is what `em.software()` records, and what the Methods quote (the
[results-binding](../results-binding/SKILL.md) skill); a package it records counts as
loaded.
## What the data can answer
Before the analysis section is settled, count what the data hold, with a script of the
project's own and not by reading the data yourself: `analysis/00_feasibility.py` or `.R`,
emitting through the emitter under `feasibility.`:
- the size of the cohort after each selection step;
- the outcome's events, or its prevalence;
- the missing values of each variable the analysis plans to use;
- the date range the data cover;
- the duplicates found, and how they were found;
- whatever else the design needs counted before it is fixed.
Write these into the plan as bindings, "about {{results.feasibility.n_reports}} reports",
so that a reader knows which result is meant. Nothing renders the plan and nothing checks
its bindings, so a key misspelt there is never reported; G1 holds the result itself to the
script and the data that made it. A count too small to publish is small in the plan too.
At the `design` stage, G12 warns (`feasibility-not-run`) where the plan sets out an analysis
and nothing is emitted under `feasibility.`.
Where the project keeps a data dictionary (`design/data_dictionary.yaml`) and the data exist,
hand the extract to `check_data` in the same script (the
[results-binding](../results-binding/SKILL.md) skill): it counts, under `quality.`, each
variable's missing values and the values its entry does not allow, and the rows that break
each rule. Those counts say what the data hold as the feasibility ones do: G12 takes them in
their place, and a design round is sent them with the plan. Bind them in the plan where it
settles what to do with a fault: "{{results.quality.age.missing}} reports give no age; age
group is entered with a category for the missing".
A variable the analysis declares or a model reads has an entry in the dictionary. G16 says
`not-in-dictionary` where one has none: write its entry, with its definition and the codes
or range its values may take, and, for a variable the analysis derives, what it is derived
from.
## What the paper will report
Add a section headed "Planned results" that lists, one item each, the results the paper will
report, each item opening with the key the analysis will emit it under, in backticks:
```markdown
## Planned results
- `case.n_cases`: the cases
- `ror.*`: the reporting odds ratio and its 95% interval
```
`ror.*` is every key under `ror.`. A key with no dot is written as the manuscript binds it, `results.dose`, since a span with no dot is read as code. Agree the keys with whoever writes the analysis, since
they are its names. Once the analysis is under way, G12 warns where a listed key was never
emitted (`planned-result-missing`) or was emitted with `quoted=False`
(`planned-result-unquoted`). If a planned result will not be reported, say so under
Deviations, naming its key; that stands the warning down and is the record a reader needs.
## Controls, and data held out from the model
A control shows that the analysis can find an answer: data simulated with a known effect,
a positive control, an association known to exist, or a negative control, for which no
effect is expected. A prediction model validated on data held out from its development is
validated independently only where nothing that built or tuned it read those data first.
The plan declares both in a `yaml` block, chosen before the results, and G12 and G1 hold
them to what the analysis ran. Before declaring a control, or answering a `control-…`
finding, read [references/controls.md](references/controls.md); before declaring held-out
data, or answering a `held-out-…` or `first-reads-unreadable` finding, read
[references/held-out.md](references/held-out.md). A `plan-declarations-unreadable`
finding is an entry of either form that does not read: the reference for its kind has the
form.
## What will be collected
Where the data do not exist yet, the plan is followed by a second decision: exactly what
will be collected. The [data-dictionary](../data-dictionary/SKILL.md) skill writes it in
`design/data_dictionary.yaml`, one entry per variable, and G12 holds the two together. So
name each variable in the plan in backticks, as the dictionary names it: "adjusted for
`age` and `sex`". Write code as code, `glm()`, so that it is not taken for a variable.
## Dating it
The gate cannot tell when the plan was written, and nothing in the toolkit can. Only a
record outside the project can: a commit of `design/plan.md` made before the first
analysis script, or a registration with whatever registry the field uses. Tell the author
which is available to them. Registering is their decision and their account, not yours.
Fill in the `Agreed <date>` line with the real date.
## Holding the paper to its registration
Once the study is registered, list the registration in `paper.yaml` and quote, under it, each
outcome the registry holds, in the registry's words, with its role there and the planned
result that reports it:
```yaml
registration:
- id: EUPAS1000000417 # or NCT04368728, ISRCTN17072692, osf.io/abcde
outcomes:
- registered: "Overall NDDs, including autism spectrum disorder"
role: primary
reported_as: nnd.* # a key the plan's Planned results lists
- registered: "Individuals NDDs"
role: secondary # not reported: no reported_as, and the same words
# quoted under Deviations from the plan with why
```
Then run `manuscript-guard lookup --registrations`. It asks ClinicalTrials.gov, OSF and
ISRCTN through their APIs and reads the EU PAS register's study pages, and keeps what each
said in `design/registrations/<id>.yaml`. PROSPERO and other registries are not asked: their
record is copied by hand, with `source: by-hand`, `copied_by` and `copied_on`, from the page
the author has open.
G12 then checks that the manuscript gives the identifier, that the registry knows it, that it
was registered before the study's actual start, the start of its data analysis and the first
results (a later one needs `retrospective:` with the reason, and the manuscript saying it was
registered retrospectively), and that each quote is word for word in the registry's record,
in the role given where the registry keeps primary and secondary apart. A registered outcome
reported in another role, one not reported, and a reported one nobody registered are each
named under Deviations, by the result's key, or for one not reported by its quoted words.
Where the registry lists its outcomes apart (ClinicalTrials.gov, ISRCTN), every primary one
must be quoted.
The quotes prove that the words are the registry's, not that they mean the outcome the paper
measures. That is for the co-authors and the panel to judge.
Quote from the record in `design/registrations/`, never from memory or from the protocol's
later version: the registry's first words are the ones that count. Do not write a by-hand
record yourself from what a registry probably says; ask the author to open the page, and copy
what it shows, with their name on it.
## Recording a deviation
When the analysis departs from the plan, write it under the deviations heading at the time,
not at the end. For each one:
- the date, and what prompted it;
- what the plan said, and what was done instead;
- why, and who decided;
- whether the results it affects were known when it was decided;
- whether anything was re-run because of it, and whether the result moved.
The first time the analysis writes results, the emitter keeps the plan as it stood in
`design/plan.frozen.yaml`, and never writes it again. Change the plan in `design/plan.md`,
never the frozen copy; a plan changed after that with its Deviations section as it was is
`plan-changed-after-results`, a warning that says the change was not declared.
`None so far.` is a legitimate entry as long as it is true. Every deviation also belongs
in the paper's Methods; the [methods-writer](../methods-writer/SKILL.md) skill covers that.
## What the design needs
Name the design in `paper.yaml` (`study_type`: cohort, case-control, cross-sectional,
diagnostic-accuracy, case-report, case-series, qualitative, self-controlled,
disproportionality, trial, systematic-review or prediction-model). G12 then
asks the plan for the sections that design needs beyond the seven, each from the guideline
item it comes from: the estimand of a trial, time zero and the confounders of a cohort, the
sampling and the measurement of a cross-sectional study, the risk windows of a
self-controlled design, the case definition and the comparator of a disproportionality
analysis, the reflexivity of a qualitative study. A study that is none of these (a
narrative review) takes `other`: the plan is asked for the seven
sections, and G5 for no guideline of the design's. [references/study-designs.md](references/study-designs.md) has, for each design,
what each section has to answer, where that comes from and how to name one exactly. Whether
the design can support
the conclusion is the author's and the panel's to judge, not a gate's; the sections make the
choices visible.
## If you are a model doing this
Do not write the plan from the analysis code. A plan reconstructed after the fact is exactly
what the plan exists to rule out, and the gate cannot tell the difference, so it will
approve it. If the analysis has already started, say so in the plan: "Written on <date>,
after the following had been run: …". That sentence is worth more than a plan that
pretends otherwise.
Do not fill sections with generic text to clear the warnings. A vague section passes the gate
and misleads the reader. An empty one at least shows what is still undecided. If a section
cannot be written yet, ask the author the question it needs answered.
Files in this skill
- SKILL.md
- references/study-designs.md
Attribution
Related skills
View all in research →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.