hinna0818/ukbanalytica_v2/ukbsci-propensity
Claude Code and agent skill by hinna0818/ukbanalytica_v2
- community
Checking that the SKILL.md file is still in the repository.
Propensity-score analyses for UK Biobank Research Analysis Platform (RAP) cohorts built with UKBAnalytica. Covers PS estimation via logistic regression or gradient-boosted models (estimate_propensity_score), 1:N nearest-neighbor or optimal matching (match_propensity), inverse-probability of treatment weighting (calculate_weights, ATE / ATT / ATC, stabilized, truncated), covariate balance diagnostics (assess_balance, plot_balance, plot_ps_distribution), and weighted regression with robust standard errors (run_weighted_analysis). Use this skill when the user asks for propensity score matching, PSM, IPTW, ATE / ATT, covariate balance, Love plot, PS distribution check, or a weighted Cox / logistic / linear analysis on a UKB cohort. Triggers: propensity score, PSM, IPTW, ATE, ATT, Love plot, covariate balance, 倾向评分, 倾向得分匹配, /ukbsci-propensity. 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-propensitySKILL.md
ukbsci-propensity — Propensity scores, matching, and IPTW on 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 matched / weighted dataset is participant-level and stays in RAP project storage. Shareable artefacts are aggregate: balance tables, Love plots, PS distribution figures, and final weighted-effect estimates.
1. When to load
- Estimate a propensity score for a binary treatment / exposure.
- Build a 1:N PSM-matched sub-cohort.
- Construct IPTW weights (ATE / ATT / ATC, stabilized, optionally truncated).
- Assess covariate balance before vs after matching / weighting.
- Run a weighted Cox / logistic / linear analysis with robust SEs.
2. When NOT to load
- Vanilla unadjusted / multivariable Cox →
ukbsci-regression. - Multiple-imputation pooling of weighted estimates → use this skill plus
ukbsci-imputation.
- Mediation analysis →
ukbsci-mediation.
3. Prerequisites
4. Pipeline (5 phases)
Phase 1 — Estimate PS
For non-linear / non-additive relationships, prefer method = "gbm".
Phase 2 — Choose matching OR weighting
Matching path:
Weighting path:
Phase 3 — Assess balance (before / after)
The standard target: SMD ≤ 0.1 on every covariate post-adjustment.
Phase 4 — Weighted / matched analysis
run_weighted_analysis() also supports model_type = "logistic" / "linear". Robust standard errors via sandwich + lmtest.
Phase 5 — Export
All output goes to /mnt/project/<area>/04-results/:
5. Common pitfalls
- Bounded PS at `[0.001, 0.999]`. Prevents extreme weights but
shrinks the tails. Verify with plot_ps_distribution() that no group has piled-up boundary mass.
- Caliper too tight. Default
0.2 × SD(PS)is generous; tightening
below 0.05 × SD can drop most of the treated arm.
- Replace = TRUE. Increases effective sample but inflates variance;
warn the user and confirm.
- `weight_type = "ATE"` vs `"ATT"` changes the estimand. PSM by default
targets ATT (the matched cohort). Mixing in IPTW with ATE and reporting them side-by-side without flagging is misleading.
- Truncation defaults at 1st/99th percentile. Aggressive — if the user
wants to keep extremes, set truncate = c(0, 1).
- SMD on factors.
assess_balance()converts factors to numeric for
SMD; multi-level factors are summarized as a single SMD. For per-level SMD, expand the factor into dummies first.
- Robust SE for Cox. `run_weighted_analysis(model_type = "cox",
robust_se = TRUE) uses survival::coxph(..., robust = TRUE) semantics — appropriate for IPTW. For matched Cox, prefer **cluster-robust SE on match_id`** (build the formula manually).
- Missing `weight` column for `method = "weighted"` triggers a clear
error from assess_balance(). Pass weight_col = "weight" explicitly.
6. Key functions
| Function | Signature highlights | Returns | |
|---|---|---|---|
estimate_propensity_score(data, treatment, covariates, method = c("logistic","gbm"), formula = NULL) | adds ps ∈ [0.001, 0.999] | data.table | |
match_propensity(data, ps_col, treatment, ratio, caliper, method, replace, exact_match) | wraps MatchIt::matchit | data.table + match_id, match_distance | |
calculate_weights(data, ps_col, treatment, weight_type, stabilized, truncate) | IPTW weights | data.table + weight | |
assess_balance(data, treatment, covariates, method, weight_col, threshold) | SMD + variance ratio | data.frame with balanced flag | |
plot_balance(balance_before, balance_after, threshold, title, xlab) | Love plot | ggplot | |
plot_ps_distribution(data, ps_col, treatment, type, matched, match_col) | PS overlap viz | ggplot | |
run_weighted_analysis(data, exposure, outcome, covariates, weight_col, model_type, endpoint, robust_se) | IPTW model | data.frame: HR / OR / β + 95% CI |
See `references/functions.md` for full argument tables.
7. Related skills
| Skill | When | |
|---|---|---|
ukbsci-cohort | Build the cohort + outcome_status first. | |
ukbsci-baseline | Post-PSM Table 1 with SMD column. | |
ukbsci-regression | Unweighted multivariable adjustment for comparison. | |
ukbsci-plot | Forest plot of weighted results. |
8. References
- `references/functions.md`
- `references/examples.md` — three examples
(PSM with caliper + exact match, IPTW with stabilized ATE weights, weighted Cox with robust SE)
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-propensity/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 7 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-propensity)