← Methods repository
concept

Instrumental Variables in Pharmacoepidemiology

A causal-inference method that uses an instrument — a variable affecting treatment receipt but with no pathway to the outcome except through treatment and no shared cause with it (e.g., physician prescribing preference, formulary/policy shocks, distance, genetic variants) — to identify a treatment effect under unmeasured confounding.

Causal_Inference_Methodinstrumental-variablesphysician-preferenceunmeasured-confoundingweak-instrument2slscontrol-functionlocal-average-treatment-effectmendelian-randomization
Methods reference only. Use primary source citations and local policy before applying this in a study protocol, regulatory submission, payer dossier, or clinical decision.

In plain language

Instrumental variables (IV) is a method for estimating how much a treatment actually causes an outcome when hidden patient factors — things like frailty or disease severity that researchers cannot measure — push sicker patients toward one drug and also make bad outcomes more likely. The trick is to find a third variable, called an instrument, that nudges which drug a patient receives but has absolutely no other connection to the outcome. By isolating only the treatment variation driven by that instrument, IV gives an estimate of the treatment effect that is free of the hidden confounding. The method requires strong assumptions that can rarely be fully verified, so it is reserved for situations where standard adjustment methods are not enough.

Instrumental variable (IV) analysis

identifies a treatment effect from observational data without requiring that all confounders be measured. It works by exploiting a third variable Z — the instrument — that perturbs treatment A but is unrelated to the outcome Y except through A. In pharmacoepidemiology the appeal is direct: confounding by indication is often severe and partly unmeasurable (frailty, disease activity, prescriber gestalt), so adjustment-based methods (propensity scores, regression) cannot fully remove it. A valid instrument sidesteps the unmeasured confounder U entirely by introducing variation in treatment that is, by assumption, independent of U. Canonical candidate instruments are physician/facility prescribing preference (the prior patient's or the prescriber's recent share of drug A), policy or formulary shocks (tier changes, prior-authorization rollout, coverage gaps, calendar-time launch discontinuities), geographic/distance instruments (distance to a center able to deliver the treatment), and Mendelian randomization (a germline variant proxying lifelong exposure).

Core conceptual distinction

IV trades measured-confounding assumptions for instrument-validity assumptions, and these are not symmetric in how checkable they are. Three conditions must hold: (1) relevance — Z genuinely shifts A (testable: the first-stage F-statistic / partial R²); (2) independence (exchangeability) — Z shares no common cause with Y and is as-good-as-randomly assigned with respect to U (largely untestable; this is where preference IVs usually break via referral/channeling); (3) exclusion restriction — Z affects Y only through A, with no direct or alternative pathway (untestable; a policy that changes copays also changes monitoring and adherence, violating it). Under these three, IV identifies a bound; to get a point estimate you add a fourth assumption — either monotonicity (no "defiers"), under which the estimand is the local average treatment effect (LATE) among compliers (patients whose treatment is moved by the instrument), or effect homogeneity, under which it equals the ATE. The complier LATE is the honest default reading: it is not the ATE and not the ATT, the complier subpopulation cannot be enumerated from data, and it shifts as the instrument changes — a fact that must be stated in the estimand, not buried.

Pros, cons, and trade-offs

- vs active-comparator-new-user (ACNU) + propensity scores: PS/ACNU is transparent, well-understood by regulators, and yields an interpretable ATT/ATE — but it is helpless against unmeasured confounding by indication, which is the dominant threat in claims. IV can in principle remove unmeasured confounding. Cost: IV answers a complier estimand, has far wider confidence intervals, and a weak or invalid instrument can be more biased than the adjusted regression it was meant to rescue (weak-instrument bias pulls the IV estimate toward the confounded OLS/PS estimate while inflating variance). Prefer ACNU+PS as the primary analysis for almost all comparative questions; reserve IV for when residual indication bias is plausibly large and a genuinely strong, defensible instrument exists. - vs negative-control / E-value sensitivity analysis: negative controls and E-values quantify or falsify the robustness of a confounded estimate but cannot identify a causal effect; IV attempts identification under a different (and stronger) set of assumptions. They are complements: use negative-control outcomes and balance-by-instrument as falsification tests of an IV, not as proof of validity. Prefer IV only when its assumptions are clinically credible and its first stage is strong; otherwise report the confounded estimate with an E-value. - 2SLS vs two-stage residual inclusion (2SRI)/control function: two-stage least squares is consistent for linear/additive contrasts and risk differences but is not generally valid on the hazard ratio or odds-ratio scale (non-collapsibility). 2SRI/control-function or additive-hazard (Aalen) IV models are preferred for binary and time-to-event outcomes; report the estimand on the scale the model actually targets, not a convenient transformation of it.

When to use

Comparative effectiveness/safety where (a) confounding by indication is severe and partly unmeasured, (b) a candidate instrument is biologically/administratively plausible and strong (rule of thumb: first-stage F well above 10, ideally >> for partial-effect precision), and (c) you can defend independence and exclusion on substantive grounds and falsify them with negative controls and balance-by-instrument. IV shines for short-term drug effects where preference is stable, and for natural experiments (a formulary delisting, a black-box-warning-driven prescribing shift) that mimic randomization.

When NOT to use — and when it is actively misleading or dangerous

- Weak instrument. A small first-stage F (e.g., < 10, and effectively much higher is needed for tolerable bias) makes the IV estimate biased toward the confounded estimate with enormous variance — strictly worse than the regression you were trying to fix. Report the first stage before the second-stage effect; if it is weak, stop. - Channeling / referral violates independence. If high-risk patients are referred to drug-A-preferring prescribers (frailer patients seen by specialists who favor the newer agent), preference correlates with U and the IV is biased in an unknown direction. Preference IVs are most dangerous precisely when indication bias is worst. - Exclusion is implausible. A policy instrument that also changes copays, monitoring, adherence, or co-prescribing has a direct path to Y; the "instrument" then estimates a tangle of effects. Mendelian instruments fail exclusion under pleiotropy. - The policy question is the ATE/ATT. If decision-makers need the population-average or treated-average effect, a LATE among an unidentifiable complier subgroup may be the wrong target — and silently reporting it as "the" treatment effect is misleading.

Data-source operational depth

- Claims (FFS vs MA): Preference IVs require a stable prescriber/facility identifier (rendering or prescribing NPI) and enough prior initiations per provider to estimate a non-noisy preference; providers with few patients give a noisy instrument that behaves like a weak one. The preference must be time-updated and lagged (e.g., the provider's drug-A share over the prior N initiations excluding the index patient) to avoid leaking future information. Critical failure mode: Medicare Advantage person-time lacks fee-for-service claims, so a provider's apparent prescribing mix is computed on a non-random, FFS-only subset of their panel — biasing the instrument; restrict preference construction to enrollees with observable Part A/B/D and exclude MA-only person-time. Differential competing risks by exposure in the elderly (the newer drug is channeled to frailer patients with higher death rates) corrupt both the outcome and any survival-scale IV — use cause-specific or additive-hazard IV and a competing-events sensitivity analysis. - EHR: Clinician practice style and facility are often available and richer than claims, but site-level severity and referral patterns are strong independence violations, and visit-driven capture means the instrument and outcome are differentially observed for patients who leave the system. Link to pharmacy fills to confirm the instrument actually moved dispensing, not just ordering. - Registry: Genetic (Mendelian) and facility instruments may be available; registries are strong for outcomes/severity but usually weak for complete exposure — link to claims for the full fill history that defines treatment A. - Linked claims–EHR–vital records: Best substrate (EHR severity to test independence, claims completeness for exposure, a death index for competing risks), but linkage selection and order/fill/service-date discrepancies must be reconciled before the instrument and time zero are assigned. Watch immortal time in procedure/initiation studies: defining the instrument or exposure using events that can only occur after a period of guaranteed survival manufactures bias that no IV can repair.

Worked claims example (physician-preference IV)

Question: 90-day risk of major bleeding with apixaban vs warfarin among adults newly initiating oral anticoagulation for atrial fibrillation in a commercial + Medicare FFS database, where frailty (an unmeasured confounder) drives both drug choice and bleeding. (1) Cohort: age ≥18, an AF diagnosis in the baseline window, and 365 days of continuous medical + pharmacy enrollment with observable FFS claims (exclude MA-only person-time) before the index fill; new-user washout = no oral anticoagulant fill in the prior 365 days; index_date = first qualifying fill (`fill_date`); arm assigned from the NDC dispensed that day. (2) Instrument: for each index patient, identify the prescribing NPI and compute that prescriber's apixaban share over their previous qualifying initiations (lagged, excluding the index patient); require ≥5 prior initiations or the preference is too noisy. A common binary form: prescriber's most recent prior patient received apixaban (1) vs warfarin (0). (3) First stage: regress `treated` (apixaban=1) on the preference instrument plus measured covariates and report the F-statistic — proceed only if it is comfortably strong. (4) Falsification: tabulate measured baseline covariates (age, CHA₂DS₂-VASc components, prior bleeds, renal codes, utilization) across instrument levels — strong imbalance signals an independence violation (channeling); add a negative-control outcome (e.g., an event neither drug should affect) and confirm the instrument has no effect on it. (5) Estimation: because bleeding is a time-to-event outcome subject to the competing risk of death (differentially higher in frailer warfarin recipients), prefer an additive-hazard (Aalen) IV or a 2SRI control-function model over naïve 2SLS on a hazard ratio; if reporting a 90-day risk difference, 2SLS on the binary 90-day indicator is defensible. (6) Interpretation: the estimate is the LATE among preference compliers — patients whose drug was determined by their prescriber's leaning — not the ATE; state this, report the first-stage F and the balance-by-instrument table, and run sensitivity analyses on the preference lag length, the ≥5-initiation threshold, and competing-risk handling.

Interpreting the output

Using the prescribing-preference IV study above, the two-stage least-squares (2SLS) procedure yields a local average treatment effect (LATE). In the six-patient illustration, the instrument-driven contrast among compliers corresponds to a risk difference of −1.00 (illustrative only; real studies require thousands of patients for a stable estimate).

Formal interpretation: The IV estimate is the LATE among compliers — patients whose treatment choice was determined by the prescriber's preference instrument rather than by their own clinical severity or preferences. It is not the ATE across all patients, nor the effect for always-takers or never-takers. Validity requires all three IV assumptions: relevance (the instrument predicts treatment, with first-stage F-statistic substantially above 10); independence (the prior patient's drug choice shares no hidden cause with the current patient's bleeding risk); and the exclusion restriction (the only causal pathway from the instrument to the outcome runs through treatment received). A violation of the exclusion restriction — for example, if frailer patients cluster with warfarin-preferring prescribers — biases the LATE in a direction that cannot be determined from the data alone. The confidence interval is wider than a propensity-adjusted estimate because IV uses only the instrument-explained variation in treatment.

Practical interpretation: Apixaban appeared to reduce 90-day major bleeding among patients whose drug was determined by their prescriber's habit rather than by their own clinical profile. This protection does not necessarily extend to all AF patients initiating anticoagulation — the complier population (those swayed by prescriber preference) may be systematically different from always-takers or never-takers.

Worked example

Scenario

A researcher wants to know whether apixaban causes fewer major bleeds than warfarin among patients newly starting a blood thinner for atrial fibrillation. The problem: frailer patients are more likely to receive warfarin (confounding by indication), and frailty also raises bleeding risk. Frailty is not recorded in claims data, so propensity-score adjustment cannot fully remove the bias. The researcher uses physician prescribing preference as an instrument: for each new patient, she looks at what blood thinner that patient's prescriber gave their previous qualifying patient. This prior-patient drug choice is used as the instrument because it reflects the prescriber's personal habit rather than anything about the current patient.

Dataset

Each row is a new atrial-fibrillation patient. The instrument (Z) is the drug the prescriber gave their immediately prior patient. Treatment (A) is the drug this patient actually received. Outcome (Y) is major bleed within 90 days (1=yes).

person_idprescriber_idinstrument_Z_prior_drugtreatment_A_receivedoutcome_Y_bleed_90d
pt-001dr-11apixabanapixaban
pt-002dr-11apixabanapixaban
pt-003dr-22warfarinwarfarin1
pt-004dr-22warfarinwarfarin1
pt-005dr-33apixabanwarfarin
pt-006dr-33warfarinapixaban

Steps

  • Assumption 1 — Relevance: the instrument must actually shift treatment. In this dataset, when the prior patient received apixaban, the current patient received apixaban 3 out of 4 times (75%); when the prior patient received warfarin, the current patient received warfarin 3 out of 4 times (75%). The instrument is correlated with treatment received, satisfying relevance. In a real study this is tested statistically: the first-stage F-statistic should be well above 10.

  • Assumption 2 — Independence: the prior patient's drug was not chosen because of anything about the current patient, so the instrument shares no hidden cause with the current patient's outcome. This is the hardest assumption. It would be violated if, for example, frailer patients were consistently referred to the same prescribers who favor warfarin — then the instrument would be correlated with frailty (the hidden confounder), not just prescriber habit.

  • Assumption 3 — Exclusion restriction: the only way the prior patient's drug choice can affect the current patient's bleeding risk is by influencing which drug the current patient actually takes. It has no direct biological or social pathway to the current patient's outcome.

  • Because all three assumptions hold by design in this toy example, the variation in treatment that is explained by the instrument is treated as free of unmeasured confounding. In a two-stage estimation, the first stage predicts each patient's treatment from the instrument; the second stage estimates the effect of that predicted (instrument-driven) treatment on bleeding. The result is called the local average treatment effect (LATE) among compliers — patients whose drug was determined by the prescriber's habit.

Result

In this illustration: among the 4 patients whose treatment matched the instrument's direction (pts 001, 002, 003, 004), 2 out of 4 had a bleed in the warfarin group (pts 003, 004) versus 0 out of 2 in the apixaban group (pts 001, 002). The IV approach attributes this difference to the treatment, not to frailty, because the instrument — not patient severity — drove the prescribing. The estimated risk difference is −1.00 (0 bleeds in the apixaban arm versus 2 in the warfarin arm, each arm having 2 compliers) in this tiny example (illustrative only; real studies need thousands of patients for a stable estimate). The honest label for this number is the LATE among compliers — patients for whom the prescriber's habit changed their drug — not the average effect across all patients.

Runnable example

python implementation

Physician-preference IV for a continuous or risk-difference (linear-probability) estimand. Required inputs (cleaned, one row per new initiator): cohort : person_id, prescriber_npi, index_date, treated (1=study drug, 0=comparator), outcome (continuous OR 0/1...

import pandas as pd
import numpy as np
from linearmodels.iv import IV2SLS

MIN_PRIOR = 5  # providers with fewer prior initiations give a noisy (weak-acting) instrument

def add_preference_instrument(cohort: pd.DataFrame, inits: pd.DataFrame) -> pd.DataFrame:
    # Lagged provider preference = share of study drug among that prescriber's earlier initiations.
    inits = inits.sort_values(["prescriber_npi", "fill_date"])
    inits["cum_treated"] = inits.groupby("prescriber_npi")["treated"].cumsum() - inits["treated"]
    inits["cum_n"]       = inits.groupby("prescriber_npi").cumcount()            # count of PRIOR initiations
    inits["pref"]        = np.where(inits["cum_n"] >= MIN_PRIOR,
                                    inits["cum_treated"] / inits["cum_n"], np.nan)
    key = ["prescriber_npi", "fill_date", "treated"]
    out = cohort.merge(inits[key + ["pref"]],
                       left_on=["prescriber_npi", "index_date", "treated"],
                       right_on=key, how="left").drop(columns=["fill_date"])
    return out.dropna(subset=["pref"])

def fit_preference_iv(df: pd.DataFrame, covars=("age", "cci")):
    const = pd.Series(1.0, index=df.index, name="const")
    exog = pd.concat([const, df[list(covars)]], axis=1)  # measured covariates enter both stages
    # 2SLS: outcome ~ [treated endogenous, instrumented by pref] + exogenous covariates.
    # linearmodels reports the first-stage partial F in res.first_stage; read it BEFORE the effect.
    res = IV2SLS(dependent=df["outcome"], exog=exog,
                 endog=df[["treated"]], instruments=df[["pref"]]).fit(cov_type="robust")
    return res

# res = fit_preference_iv(add_preference_instrument(cohort, inits))
# print(res.first_stage)        # partial F on `pref`; proceed only if comfortably strong (>> 10)
# print(res.params["treated"])  # LATE among preference compliers (NOT the ATE)
r implementation

Physician-preference IV with explicit weak-instrument and Wu-Hausman diagnostics. Inputs mirror the Python version: cohort : person_id, prescriber_npi, index_date (Date), treated (0/1), outcome (continuous or 0/1), age, cci inits : prescriber_npi, fill_date...

library(data.table)
library(ivreg)
MIN_PRIOR <- 5L

add_preference_instrument <- function(cohort, inits) {
  setDT(cohort); setDT(inits)
  setorder(inits, prescriber_npi, fill_date)
  # Lagged share of study drug among each prescriber's PRIOR initiations (exclude current row).
  inits[, cum_treated := cumsum(treated) - treated, by = prescriber_npi]
  inits[, cum_n       := seq_len(.N) - 1L,           by = prescriber_npi]
  inits[, pref := fifelse(cum_n >= MIN_PRIOR, cum_treated / cum_n, NA_real_)]
  out <- merge(cohort, inits[, .(prescriber_npi, fill_date, treated, pref)],
               by.x = c("prescriber_npi", "index_date", "treated"),
               by.y = c("prescriber_npi", "fill_date",  "treated"), all.x = TRUE)
  out[!is.na(pref)]
}

fit_preference_iv <- function(df) {
  # outcome ~ treated + covars | pref + covars  (treated instrumented by preference)
  fit <- ivreg(outcome ~ treated + age + cci | pref + age + cci, data = df)
  summary(fit, diagnostics = TRUE)  # weak-instrument F, Wu-Hausman, Sargan
}

# df  <- add_preference_instrument(cohort, inits)
# fit_preference_iv(df)             # coefficient on `treated` = complier LATE