hinna0818/ukbanalytica_v2/ukbsci-imputation
Claude Code and agent skill by hinna0818/ukbanalytica_v2
- community
Checking that the SKILL.md file is still in the repository.
Multiple imputation by chained equations and Rubin's-rules pooling for UK Biobank Research Analysis Platform (RAP) cohorts using UKBAnalytica. Wraps mice (run_imputation, create_imputation_list) and mitools::MIcombine (pool_mi_models, pool_custom_estimates) to produce m imputed datasets, fit regression models on each (fit_mi_models), and pool estimates with FMI diagnostics (S3 mi_pooled_result + plot_mi_pooled, plot_mi_diagnostics). Supports merging additional datasets (e.g. proteomics) into each imputed copy via the additional_data argument. Use this skill when the user asks for multiple imputation, MI pooling, Rubin's rules, FMI, or wants to merge per-imputation analyses across covariate / proteomics datasets. Triggers: multiple imputation, MI, mice, Rubin's rules, FMI, pool imputations, imputed dataset, 多重插补, 插补合并, /ukbsci-imputation. Hard rule: local agents must not read or inspect real UKB RAP participant-level data; generate scripts for RAP execution and interpret aggregate outputs only.
Install
npx vskill@latest install hinna0818/ukbanalytica_v2/ukbsci-imputationSKILL.md
ukbsci-imputation — Multiple imputation and pooling for UKB cohorts
0. RAP guardrails
Strict local-agent boundary: this skill is for script generation, workflow planning, package guidance, and interpretation of aggregate outputs. The agent must not read, inspect, summarize, or process real UK Biobank RAP participant-level data, including de-identified row-level tables, raw RAP fields, exact dates, per-row predictions, row-level SHAP matrices, screenshots, tracebacks, or logs containing row-level values. Generate scripts for the user to run inside RAP; only aggregate results or rendered figures may be shared back with the agent. See ../references/agent-privacy-boundary.md.
The list of m imputed data.tables is per-participant and must remain inside RAP project storage. Pooled coefficient tables and plot_mi_* figures are aggregate and may be shared with the local agent. Recommended on-disk layout:
1. When to load
- Cohort has non-trivial missingness on important covariates
(> ~5–10% per variable).
- The user wants Cox / logistic / linear estimates pooled across
m
imputations using Rubin's rules.
- Multi-mediator or multi-exposure analyses to be repeated under MI.
- Merging a separate RAP-resident table (proteomics, metabolomics) into
each imputed copy.
2. When NOT to load
- Missingness is < 5% on every covariate and complete-case is adequate →
ukbsci-subgroup-sensitivity (complete-case helper).
- The user wants a quick exploratory model, no pooling →
ukbsci-regression.
3. Prerequisites
run_imputation() and pool_mi_models() error out with clear messages if mice / mitools are not installed.
4. Pipeline (4 phases)
Phase 1 — Impute
Phase 2 — Fit models per imputation
Alternative: pass an imputationList and have pool_mi_models() refit:
Phase 3 — Pool via Rubin's rules
The pooled$pooled slot contains: term, estimate, std.error, statistic, df, p.value, conf.low, conf.high, fmi.
Phase 4 — Diagnostics & visualization
FMI ≥ ~0.3 suggests the variable's pooled SE is heavily inflated by between-imputation variance — consider increasing m.
Phase 5 — Pool custom (non-model) estimates
For derived quantities like mediation TNIE across imputations, give pool_custom_estimates() the list of per-imputation point estimates and variance-covariance matrices:
5. Common pitfalls
- `run_imputation()` re-coerces types. Variables in
varsare coerced
to numeric (or factor if listed in factor_vars). Variables outside vars are left alone and merged back on id_col.
- Empty strings → NA.
run_imputation()converts""toNAbefore
imputing — confirm this is the desired behavior, especially if you encoded "Prefer not to answer" as "" upstream.
- `m = 5` is the default, fine for
< 30%missingness. For heavier
missingness, use m = 20 or more.
- Convergence. Inspect
mice::plot(imp$imp)— if trace plots have not
stabilised, increase maxit.
- Cox + small subgroups. Some imputations may fail to converge.
fit_mi_models() drops failures and warns; if fewer than 2 succeed it errors out.
- `exponentiate = NULL` auto-decides. It is
TRUEforcoxand
logistic, FALSE for lm. Override when needed.
- Robust SEs are not directly supported in the pooled output. If you
need IPTW + MI, weight inside each imputation by hand, then pass the fitted weighted models to pool_mi_models(models = ...).
- Cluster the merge. When using
additional_data, every imputed copy
gets the same external table merged on id_col. If the external table itself has missingness, impute those columns inside vars instead.
6. Key functions
| Function | Purpose | Returns | |
|---|---|---|---|
run_imputation(data, id_col, vars, factor_vars, method, m, maxit, seed, print, additional_data, additional_join) | mice MI + merge back | list(imp, data_list) | |
create_imputation_list(datasets, validate = TRUE) | wrap as mitools::imputationList | imputationList | |
fit_mi_models(datasets, formula, model_type, family = NULL, ...) | per-imputation fits | list of model objects | |
pool_mi_models(models = NULL, datasets = NULL, formula = NULL, model_type, family = NULL, df.complete = Inf, conf.level = 0.95, exponentiate = NULL) | Rubin's rules pool | S3 mi_pooled_result | |
pool_custom_estimates(estimates, variances, df.complete = Inf, conf.level = 0.95, labels = NULL) | pool arbitrary effects | S3 mi_pooled_result | |
plot_mi_pooled(mi_result, terms, exponentiate, null_value, title, colors, show_fmi) | forest with FMI | ggplot | |
plot_mi_diagnostics(mi_result, type = c("fmi","variance_ratio","df")) | diagnostic bar | ggplot | |
S3 on mi_pooled_result | print, summary, coef, confint, vcov, tidy | varies |
7. Related skills
| Skill | When | |
|---|---|---|
ukbsci-cohort | Build cohort + outcomes first. | |
ukbsci-preprocess | Negative-code sanitation before imputation. | |
ukbsci-regression | Single-dataset model as comparison anchor. | |
ukbsci-mediation | Repeat across imputations + pool_custom_estimates(). | |
ukbsci-propensity | Weighted models per imputation, then pool. | |
ukbsci-plot | Polished forest of pooled estimates. |
8. References
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckinginst/skills/UKBAnalytica_skills/ukbsci-imputation/SKILL.md
Popularity
- Repository stars
- 35
- 7-day trend score
- 18
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 1 Sep 2026, 2 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/hinna0818/ukbanalytica_v2/ukbsci-imputation)