/lucid-coder:longitudinalfrom lucid-coder
Longitudinal mixed models per feature on repeated sample-level values (CLR cell-type frequencies, pseudobulk vst or log CPM, signature scores, Olink NPX): one lmerTest `lmer(value ~ time + covariates + random term)` per feature (random intercept or random slope, user's choice), the named coefficient tested with Satterthwaite df, BH or Bonferroni across features, singular and unconverged fits flagged per feature, subject trajectory, forest and p-value figures, a report and a reproducibility bundle. Fire on "mixed model per gene over visits", "lmer per cell type with a random subject intercept", "does the CLR frequency change over time", "time effect across visits per feature", "longitudinal Olink with lme4". Do NOT fire for a two-visit paired test without covariates (group-tests), raw counts that need pseudobulk DE (pseudobulk-de, dreamlet), compositional models (crumblr, scCODA), random slopes or nested random effects, GLMMs, or survival models.
Ships in lucid-coder. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
You are the dispatcher for longitudinal. The scripts do the analysis; you collect the arguments, run them, and explain the outputs.
Run scripts/longitudinal.py; it calls scripts/lmer.R through Rscript. Never
re-implement the model, change a threshold, change the formula or the reference
time, or pick a value the user has not given. If a required argument is unknown,
ask the user (these are grill questions), or run --demo only when the user asks
for a demo.
Then read result.json and relay chat_summary_lines and preferred_artifacts.
Always say how many fits were singular or unconverged. If the script prints
ERROR: ... and exits 2, tell the user the message and the argument it names.
Do not work around it.
| Input | Format | Required content | Example |
|---|---|---|---|
--input | TSV, long | columns feature, subject, time, value (numeric) | examples/demo.tsv |
| covariates | TSV columns | every other name in --formula; text columns become factors with levels in sorted order (alphabetical, so the first level is the reference; the script does not choose it), numbers stay numeric. The reference level per factor is in the report summary and result.json (reference_levels; time uses --reference-time) | age, sex |
One row per feature, subject and time; a repeat is an error. A row with a
missing feature, subject, time or value is dropped and counted. A missing
covariate stops the run until the user answers --missing. Labels are
read as text, so 01 stays 01. Values are already on the scale to model
(CLR, vst, log CPM, NPX); the script does not transform them.
Required checks (docs/pipeline-skills.md, adopted 2026-10-27):
duplicate_rows); in a long table that is the uniqueness check.skillkit.check_design_rank; a covariate aliased
with time, such as a batch that equals the visit, stops the run before R.--random is required
((1|subject) or (1 + time | subject)), so repeated visits are never
treated as independent.--reference: features are generic (frequencies, scores, NPX), so no
genome build is recorded. Gene-level input belongs in pseudobulk-de.result.json (n_rows_dropped_by_time).Ask these through the analysis contract: ${CLAUDE_PLUGIN_ROOT}/skills/lucid-coder/references/contracts.md.
Each row is a grill question. Ask the user; never fill one in.
| Argument | Grill question | Demo-only value |
|---|---|---|
--context | Species, tissue or cell type, condition and dataset? It opens the report and the chat summary. | synthetic demo: 24 subjects, 3 visits, 30 features, no real tissue |
--input | Which TSV holds the values? | examples/demo.tsv |
--formula | Which fixed covariates beside time? The form is value ~ time + covariates, the fixed part only; a:b and a*b interactions allowed. The random term comes from --random; a | in the formula is an error. | value ~ time + age |
--random | Does each subject get a random intercept only (intercept: (1|subject), subjects differ in level) or also a random slope over time (slope: (1 + time | subject), subjects differ in trend)? slope needs --time-type numeric. No default. Recommended for the usual repeated-visits question: intercept, the lmerTest::lmer form used in the corpus (C-an-16, C-an-22); slope needs enough visits per subject, else the fit is singular and flagged. | intercept |
--time-type | Is time a set of visits (factor, one coefficient per visit against the reference), a number with a linear trend (numeric, one slope) or a number with a curved trend (spline, a natural spline)? | factor |
--knots | Only for spline: how many interior knots? They sit at time quantiles, the same for every feature, and result.json records them. At most the number of distinct times minus 2. | not asked |
--reference-time | Which visit is the baseline? For numeric, time is shifted so this value is 0; the slope does not change. For spline it must be a number but the fit does not use it. | 1 |
--value-unit | What unit or scale is value on (e.g. CLR, NPX, log2)? It labels the y axis and the forest x axis. | a.u. |
--time-unit | What unit is time in (e.g. visit, week, day)? It labels the x axis. | visit |
--term | Which coefficient is tested? R names it time<level> for a visit (time3 = visit 3 minus the reference) or time for a slope. For spline, time is the joint F test of all spline columns. | time3 |
--missing | Only when a formula covariate has a missing value: drop those rows (complete-case) or impute them (impute: mice, pooled with Rubin's rules)? No default; the run stops and names the covariate until it is answered. | not asked |
--n-imputations | Only with --missing impute: how many imputed tables (mice m, an integer >= 2)? No default. Recommended: 5, the value this skill used before it became an argument, which is the mice 3.19.0 default for m. | not asked |
--adjust | Correct across features with bh (FDR) or bonferroni (FWER)? | bh |
--padj-max | Which adjusted-p cutoff marks a feature significant? | 0.05 |
--n-plot | How many top features get a trajectory figure? | 4 |
--seed | Which seed is recorded? lmer draws no random numbers, so it is set for provenance. | 0 |
--outdir | Which new directory gets the outputs? It must not exist. | given by the user |
The last column is demo-only, not defaults. --demo alone pins all of them;
beside --demo only --outdir may be given. Ask --knots only for spline time
and --missing only after the run reports a missing covariate; ask
--n-imputations only with --missing impute. Giving any of them when it does
not apply is an error.
python scripts/longitudinal.py \
--context "human PBMC, CD4 T cell frequencies, pre vs post vaccination, cohort X" \
--input results/2026-10-27_freqs/clr_long.tsv \
--formula "value ~ time + age + sex" --random intercept \
--time-type factor --reference-time pre --term timepost \
--value-unit CLR --time-unit visit \
--adjust bh --padj-max 0.05 --n-plot 6 --seed 0 \
--outdir results/2026-10-27_clr-lmer
# Demo (only when the user asks for one)
python scripts/longitudinal.py --demo --outdir demo_out
--formula has value on the left,
time on the right, no |, and only column names, : or * otherwise.
--random slope needs numeric time; --n-imputations goes with --missing impute. A numeric --reference-time for --time-type numeric
or spline; --knots with spline only.feature, subject, time, value and the formula's
columns; drop rows with a missing value and count them per time (under
--missing impute, rows missing only a covariate stay); refuse a
repeated (feature, subject, time), an absent factor reference time and a
rank-deficient fixed design. For spline, place the interior knots at time
quantiles over all rows, once for every feature.lmer.R: lmerTest::lmer(formula + random term, data)
(--random intercept adds (1|subject), slope adds (1 + time | subject);
the report and result.json name the one used) with REML
(the lme4 default). Factor time has the reference as its first level; numeric
time is time - reference. --term must be a fixed-effect column of the
model matrix, or the run stops and lists the valid names. Spline time is the
splines::ns() basis on those knots (columns time1 to time<knots+1>);
--term time is then the joint Satterthwaite F test of those columns
(lmerTest::contest). Each fit records estimate, SE, Satterthwaite df, t and
p for --term (num_df, F, denominator df and p for the joint test),
isSingular(), whether the optimizer converged, and every lme4 warning or
message. A fit that errors keeps its row with NA statistics and the error
text. Under --missing impute, each feature runs mice (m = --n-imputations, seeded) on
one row per subject holding the imputed covariates and the subject's mean
value, fits the model on each completed table and pools the --term
coefficient with Rubin's rules (mice::pool.scalar, the mean Satterthwaite
df as the complete-data df). A feature is singular if any imputation is, and
converged only if all are.--adjust); NA stays NA.
Singular and unconverged fits stay in the family.padj < --padj-max. Sort by padj, then feature, NA last.--n-plot features with the
lowest padj, a forest plot of the top 20, and the p-value histogram.model_results.tsv has one row per feature: feature, estimate, se, df, t,
num_df, f, pvalue, padj, significant, singular, converged, n_obs, n_subjects,
fit_message. num_df and f are filled only for the spline joint test, which
leaves estimate, se and t empty and draws no forest plot.
Figures are named by padj rank, top01 to top<n-plot>; the demo draws four.
outdir/
├── report.md # params, fit counts, figures with padj captions
├── result.json # context, term, n_features, n_fitted, n_significant, n_singular, n_not_converged, n_rows_dropped, n_rows_dropped_by_time, time_knots, missing_covariates, random, random_term, n_imputations, reference_levels, significant/singular/not_converged/failed_features, params, seed, chat_summary_lines, preferred_artifacts
├── tables/
│ └── model_results.tsv
├── figures/
│ ├── top01.pdf
│ ├── top01.png
│ ├── top01.csv
│ ├── top02.pdf
│ ├── top02.png
│ ├── top02.csv
│ ├── top03.pdf
│ ├── top03.png
│ ├── top03.csv
│ ├── top04.pdf
│ ├── top04.png
│ ├── top04.csv
│ ├── forest.pdf
│ ├── forest.png
│ ├── forest.csv
│ ├── pvalue_hist.pdf
│ ├── pvalue_hist.png
│ └── pvalue_hist.csv
└── reproducibility/
├── commands.sh # argv as run, and the resolved command with every argument
├── environment.txt # Python, R, lme4 and lmerTest versions
└── checksums.sha256 # tables and figure PDFs; sha256sum -c from outdir
Figures are matplotlib in the vendored theme.py, saved by save_panel as PDF,
PNG and source CSV, with no title and no significance stars:
topNN (60 x 60 mm): one grey line and points per subject over time, with the
raw mean per time and its t-based 95% CI in red. Factor time sits on visit
positions in level order. A line never bridges a missed visit: each subject is
drawn on the full visit grid (every factor level, or every time seen for
numeric time) with NaN at a gap, so the line breaks there. The caption counts
subjects with a gap and subjects dropped for having no values. topNN.csv
holds that drawn grid (subject, x, value); an empty value is a break.forest (89 mm wide): estimate and 95% CI (estimate ± t(0.975, df) · se)
for the 20 features with the lowest padj, lowest at the top, dashed line at 0.
Red rows pass --padj-max; hollow points are singular or unconverged fits.pvalue_hist (89 x 70 mm): raw p-values in 20 bins.lme4::lmer or call anova() for p-values.
Do not. lme4 gives no df or p; the script uses lmerTest's Satterthwaite t-test
on the one named --term.--random is required (the subject is always a random term).--term after seeing
results, or try numeric when factor finds little. Do not. Both are the
user's answers, fixed before the run.(1|batch). Do not. This
skill fits a random subject intercept only; a richer model is a new question
for the user.allFit() or rescaled covariates inside this run. Do not. Report the flagged
features; an optimizer check is a follow-up the user asks for.n_subjects is
small.--term estimate is change over visits in this cohort, associated
with time; without a control arm it is not a treatment effect (house-style
claims.strength).--missing itself or impute "to keep the
rows". Do not. It is the user's answer; complete-case is the behaviour they
get unless they choose otherwise. Imputation handles covariates fixed within a
subject only (a varying one stops the run), uses only the imputed covariates
and the subject's mean value as predictors, and cannot pool the spline joint
test; say so when the user picks it.Not arguments: the script sets these, and reproducibility/environment.txt
records the package versions. A change is a maintainer edit, not a user choice.
lmer with its default REML fit; lmerTest 3.2.1 Satterthwaite
degrees of freedom for the t-tests (joint F test for the spline basis).m (--n-imputations) and the seed:
per-column default imputation method and default iterations; the pooled
--term coefficient uses Rubin's rules (mice::pool.scalar).splines::ns() on --knots interior knots at time quantiles.Corpus sources, ClawBio mechanisms, tests, citations and the plot spec are in references/maintainer.md. The agent running the script does not need them.
examples/demo.tsv (opens in a new tab)examples/make_demo.py (opens in a new tab)references/maintainer.md (opens in a new tab)scripts/lmer.R (opens in a new tab)scripts/longitudinal.py (opens in a new tab)scripts/palettes.py (opens in a new tab)scripts/plots.py (opens in a new tab)scripts/skillkit.py (opens in a new tab)scripts/theme.py (opens in a new tab)tests/test_longitudinal.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub mdmanurung/lucid-coder --plugin lucid-coder27 skills in this plugin
/alignInstall the lucid-coder house-style configs into this repository, one file at a time, after showing each diff and asking. Use when the user says "align this repo", "install the house style configs", "set up air/ruff/lintr", or "add the palette file"./cccLigand-receptor cell-cell communication between cell types from a log-normalised single-cell h5ad with LIANA+ rank_aggregate (CellPhoneDB, Connectome, log2FC, NATMI, SingleCellSignalR, or a subset), a bundled or exported ligand-receptor resource TSV, a fixed pass rule on magnitude and specificity ranks, a source x target count heatmap, an LR dot plot, a report and a reproducibility bundle. Optional per-sample runs. Fire on "cell-cell communication", "ligand-receptor analysis", "which cell types talk to which", "LIANA", "CellPhoneDB", "rank_aggregate", "CCC between clusters". Do NOT fire for spatial CCC (bivariate, MISTy), for factorising CCC across many samples (Tensor-Cell2cell, MOFAtalk), for DE-driven CCC between conditions, for non-human data without a translated resource, or for raw counts./compositionCell-type composition and differential abundance with crumblr: counts cells per sample and label (from a cell-level h5ad or a counts TSV), drops rare labels, runs crumblr's precision-weighted CLR and variancePartition dream (fixed and random effects, e.g. (1|donor)), and writes tables, a stacked composition bar, per-label proportion boxes, an effect forest, a report and a reproducibility bundle. Fire on "cell-type composition", "differential abundance of cell types", "do cell-type proportions change", "crumblr", "CLR of cell frequencies", "which populations expand after stimulation". Do NOT fire for neighbourhood-level DA on a KNN graph (Milo), gene expression DE (pseudobulk or cell-level), scCODA / Bayesian composition models, or a plain Wilcoxon on frequencies (group-tests).