AgentStack
SKILL verified MIT-0 Self-run

Pharmacoepidemiology

skill-awslabs-hcls-agent-skills-pharmacoepidemiology · by awslabs

Reason about pharmacoepidemiologic study design for causal inference from real-world data — choosing active comparator new-user designs, emulating target trials, avoiding immortal time bias, handling time-varying confounding with marginal structural models, and selecting propensity score methods. Use when the user asks to design a drug safety or effectiveness study, choose between propensity scor…

No reviews yet
0 installs
1 views
0.0% view→install

Install

$ agentstack add skill-awslabs-hcls-agent-skills-pharmacoepidemiology

✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

Are you the author of Pharmacoepidemiology? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Pharmacoepidemiology Study Design

Overview

This skill teaches the agent how to think about pharmacoepidemiologic study design — the discipline of estimating causal drug effects from non-randomized real-world data (claims, EHR, registries). The core challenge is confounding: patients who receive Drug A differ systematically from those who receive Drug B, and naive comparisons conflate treatment effects with selection effects.

A well-designed pharmacoepidemiology study addresses this through three pillars: (1) a new-user active comparator design that aligns time zero and reduces confounding by indication, (2) propensity score methods or target trial emulation to balance measured confounders, and (3) sensitivity analyses to probe the impact of unmeasured confounding.

Use this skill to interrogate study designs, identify bias sources, and guide the user toward defensible causal inference before analysis code is written.

Usage

Invoke this skill when the user:

  • Wants to estimate the effect of a drug on a clinical outcome using observational data.
  • Asks how to choose a comparator group for a drug safety or effectiveness study.
  • Needs to decide between propensity score matching, weighting, or stratification.
  • Describes a cohort design that may contain immortal time bias.
  • Asks about target trial emulation or how to map observational data to a hypothetical RCT.
  • Has time-varying treatments or confounders and needs marginal structural models.
  • Wants to assess sensitivity to unmeasured confounding (E-value, negative controls).
  • Is reviewing or critiquing a published pharmacoepidemiology study.

The agent should respond by:

  1. Clarifying the causal question — what treatment, what comparator, what outcome, what population, what time horizon.
  2. Checking the design — is it new-user? Is the comparator active? Is time zero aligned?
  3. Identifying bias threats — immortal time, confounding by indication, prevalent user bias, time-varying confounding.
  4. Recommending a propensity score approach — matching, IPTW, or stratification based on the study context.
  5. Specifying sensitivity analyses — E-value, negative controls, quantitative bias analysis.

Response Format

  • Lead with the direct recommendation or classification (≤3 sentences)
  • Structure as: recommendation → justification (citing specific criteria/thresholds) → caveats
  • Use tables for comparisons; bullet points for criteria lists
  • Omit background the user already knows — they asked the question
  • Target: 200-400 words unless the user requests exhaustive detail

The decision trees and frameworks in this skill are for internal reasoning only. Apply them to reach your conclusion, but do not reproduce them in your response. Present only the final recommendation with supporting evidence.

Core Concepts

1. The New-User (Incident User) Design

The foundation of modern pharmacoepidemiology. Every study should start here.

Rules:

  1. Index date = first dispensing (or first prescription) of the study drug after a clean washout period.
  2. Washout period: require 180–365 days of continuous enrollment with no dispensing of the study drug. This excludes prevalent users who may have already experienced early events or side effects.
  3. Exclude prevalent users. Patients already on the drug at cohort entry are a biased survivor population — they tolerated the drug long enough to still be on it. Including them introduces depletion-of-susceptibles bias.
  4. Baseline covariates are measured before the index date. Nothing after index date enters the propensity model.
  5. Follow-up starts at the index date. Time zero is the moment of treatment initiation, not some earlier eligibility date.
Why prevalent users are dangerous

| Problem | Mechanism | |---|---| | Depletion of susceptibles | Patients who had early adverse events already stopped the drug and are absent from the prevalent-user pool | | Undefined baseline | Covariates measured "at baseline" are actually post-treatment for prevalent users | | Adjusted prevalence | Duration of prior use varies, making the cohort a mixture of different exposure histories |

2. Active Comparator Design

Rule: Compare Drug A vs Drug B, not Drug A vs no drug.

Comparing treated patients to untreated patients introduces massive confounding by indication — the reason a patient receives a drug is correlated with their outcome risk. An active comparator (another drug for the same indication) ensures both groups have the indication, reducing this bias.

Decision tree: choosing a comparator
Start
│
├── Is there another drug for the same indication?
│     ├── Yes → Use it as the active comparator.
│     │         Prefer a drug with similar:
│     │         - Indication (same disease stage/severity)
│     │         - Channeling (similar patient profile)
│     │         - Time trends (used in the same era)
│     └── No  → Consider:
│               - Non-pharmacologic standard of care
│               - Delayed/deferred treatment (with careful time-zero alignment)
│               - Document residual confounding by indication as a limitation.
│
├── Multiple candidate comparators available?
│     └── Prefer the one with the most clinical overlap.
│         Run the primary analysis with the best comparator;
│         use others in sensitivity analyses.
│
└── Is the comparator a drug from the same class?
      ├── Within-class comparison → smaller confounding, but smaller effect sizes.
      └── Between-class comparison → larger confounding, but more clinically relevant contrast.

3. Target Trial Emulation

Map every observational study to a hypothetical randomized trial. This framework forces explicit specification of each design element and reveals hidden assumptions.

| Target trial component | Specification in observational data | |---|---| | Eligibility criteria | Inclusion/exclusion applied at time zero (index date) using pre-index data only | | Treatment strategies | Initiate Drug A vs initiate Drug B (new-user design) | | Treatment assignment | Observational — handled by propensity scores or IP weighting | | Follow-up start | Index date (= treatment initiation). Must be identical for both arms | | Outcome | Same definition as the target trial; ascertained after time zero | | Causal contrast | Intention-to-treat (follow regardless of adherence) or per-protocol (censor/weight at discontinuation) | | Analysis plan | Pre-specified; registered if possible |

Critical rule: If any component cannot be mapped cleanly, the study has a structural bias that no statistical method can fix. The most common failure is misaligned time zero (see immortal time bias below).

4. Immortal Time Bias

Immortal time is the period between cohort entry and treatment start during which the outcome cannot occur (because occurrence of the outcome would prevent the patient from being classified as treated). Misclassifying this time inflates survival in the treated group.

How it arises:

  • Cohort entry is defined by diagnosis, but treatment starts later. The gap is "immortal" for the treated group — they had to survive long enough to receive treatment.
  • Comparing "ever-treated" vs "never-treated" without aligning time zero.

Solutions:

| Method | How it works | When to use | |---|---|---| | New-user design | Time zero = treatment initiation; no gap exists | Default — prevents the problem entirely | | Landmark analysis | Define a fixed time point (e.g., 90 days post-diagnosis); classify exposure status at the landmark; start follow-up there | When treatment timing varies and you want a common time origin | | Time-varying exposure | Model treatment as a time-dependent covariate in a Cox model; person-time before treatment counts as unexposed | When treatment can start at any time and you want to use all person-time |

Rule: If the study compares "ever-users" vs "never-users" with follow-up starting at a time point before treatment initiation, immortal time bias is present. The new-user design eliminates it by construction.

5. Propensity Score Methods

The propensity score (PS) is the probability of receiving treatment A (vs B) conditional on measured baseline covariates. It reduces a high-dimensional covariate space to a single balancing score.

Estimation
  1. Fit a logistic regression: treatment ~ age + sex + comorbidities + prior_meds + ...
  2. Include all pre-index covariates that predict treatment, outcome, or both. Do NOT include instruments (variables that predict treatment but not outcome) — they increase variance without reducing bias.
  3. Check overlap: both groups should have PS distributions that substantially overlap. Trim or truncate extreme weights if needed.
Three approaches

| Method | Mechanism | Strengths | Limitations | |---|---|---|---| | Matching (1:1, caliper) | Pair each treated patient with the nearest untreated patient within a caliper (typically 0.2 × SD of logit-PS) | Intuitive; easy to check balance; mimics an RCT | Discards unmatched patients → reduced sample size and generalizability | | IPTW (inverse probability of treatment weighting) | Weight each patient by 1/PS (treated) or 1/(1−PS) (comparator) to create a pseudo-population | Uses all patients; estimates ATE; flexible | Extreme weights destabilize estimates; requires truncation or stabilized weights | | Stratification | Divide PS into quantiles (typically 5–10); estimate treatment effect within each stratum; pool | Simple; transparent | Residual confounding within strata; less precise than IPTW |

Decision tree: which PS method?
Start
│
├── Is sample size limited or matching feasible?
│     ├── Yes → 1:1 PS matching with caliper = 0.2 × SD(logit-PS).
│     │         Report number matched and unmatched.
│     └── No  → Continue.
│
├── Do you need the full sample (e.g., rare outcome)?
│     ├── Yes → IPTW. Use stabilized weights. Truncate at 1st/99th percentile
│     │         if max weight > 10.
│     └── No  → Continue.
│
├── Is the goal transparency and simplicity?
│     └── PS stratification (5–10 strata). Report stratum-specific effects.
│
└── Multiple analyses?
      └── Use matching as primary, IPTW as sensitivity (or vice versa).
          Concordant results strengthen the conclusion.
Balance diagnostics

After PS adjustment, verify covariate balance:

  • Standardized mean difference (SMD): target 0.1 after adjustment, the PS model is inadequate. Add interactions, non-linear terms, or additional covariates and re-estimate.

6. Covariate Selection for Confounding Adjustment

Which variables to include in the propensity score or outcome model is a design decision, not a data-driven one. Get it wrong and the estimate is biased or inefficient.

Rules for covariate inclusion
  1. Include confounders — variables that cause both treatment and outcome. These are the primary targets.
  2. Include outcome risk factors — variables that predict the outcome but not treatment. They reduce variance (increase precision) without introducing bias.
  3. Exclude instruments — variables that predict treatment but NOT outcome. Including them amplifies bias from unmeasured confounding and inflates variance.
  4. Exclude mediators — variables on the causal pathway between treatment and outcome. Adjusting for them blocks part of the effect you are trying to estimate.
  5. Exclude colliders — variables caused by both treatment and outcome (or their descendants). Conditioning on a collider opens a non-causal path and introduces bias.
Typical covariate categories in claims data

| Category | Examples | Measurement window | |---|---|---| | Demographics | Age, sex, race, region | At index date | | Comorbidities | Charlson/Elixhauser score, specific ICD-10 codes | 365 days pre-index | | Comedications | Concurrent drug classes (statins, antihypertensives) | 180 days pre-index | | Healthcare utilization | Hospitalizations, ED visits, outpatient visits, distinct prescribers | 365 days pre-index | | Disease severity proxies | Number of specialist visits, prior procedures, lab orders | 365 days pre-index | | Frailty indicators | Skilled nursing facility use, home oxygen, wheelchair claims | 365 days pre-index | | Calendar time | Year/quarter of index date | At index date |

Rule: Always include a measure of healthcare utilization intensity. Patients who interact more with the healthcare system are more likely to receive new drugs and to have outcomes detected — this is a major confounder in claims data.

Proxy variables and the healthy-user bias

Claims data lack direct measures of lifestyle (smoking, BMI, exercise, diet). Patients who initiate preventive medications (e.g., statins, vaccines) tend to be healthier and more health-conscious. This healthy-user/healthy-adherer bias can make new drugs appear protective simply because their users are healthier. Mitigate by:

  • Including preventive care markers (flu vaccination, cancer screening) as covariates.
  • Using negative control outcomes to detect residual healthy-user bias.
  • Reporting the E-value to quantify how strong unmeasured healthy-user confounding would need to be.

7. Time-Varying Confounding and Marginal Structural Models

Standard regression fails when a confounder is both:

  • Affected by prior treatment (e.g., lab values change because of the drug), AND
  • A predictor of future treatment and outcome.

Adjusting for such a confounder blocks part of the treatment effect (over-adjustment); not adjusting leaves confounding. This is the treatment-confounder feedback problem.

Solution: Marginal Structural Models (MSMs) with stabilized IPTW.

Steps:

  1. At each time point, estimate the probability of receiving the observed treatment given past treatment and covariate history (denominator of the weight).
  2. Estimate the probability of receiving the observed treatment given past treatment only (numerator — stabilized weight).
  3. Stabilized weight = cumulative product of (numerator / denominator) over time.
  4. Fit a weighted outcome model (e.g., weighted pooled logistic regression or weighted Cox model) using these weights.

Rules for MSMs:

  • Stabilized weights should have a mean near 1.0. If not, the model is misspecified.
  • Truncate extreme weights (e.g., at 1st and 99th percentiles) and report sensitivity to truncation thresholds.
  • The denominator model must include all time-varying confounders; the numerator model includes only baseline covariates and past treatment.
  • MSMs estimate a marginal (population-average) causal effect, not a conditional one.

8. Sensitivity Analyses for Unmeasured Confounding

No observational study can rule out unmeasured confounding. Quantify its potential impact.

| Method | What it does | When to use | |---|---|---| | E-value | Reports the minimum strength of association (on the risk ratio scale) that an unmeasured confounder would need with both treatment and outcome to explain away the observed effect | Always — report alongside primary results | | Negative control outcomes | Outcomes known to be unaffected by the treatment; a non-null association signals residual bias | Include 3–5 negative controls; if they show associations, the primary result is suspect | | Negative control exposures | Exposures known to be unrelated to the outcome; test whether the analytic pipeline produces null results for them | Useful for validating the study design | | Quantitative bias analysis (QBA) | Formally models the impact of a hypothesized unmeasured confounder with specified prevalence and effect sizes | When a specific unmeasured confounder is suspected (e.g., smoking, BMI in claims data) |

Rule: Every pharmacoepidemiology study should report at minimum the E-value and include at least one negative control an

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet — be the first.

Versions

  • v0.1.0 Imported from the upstream source.