Tutorials › Propensity Score Matching and Instrumental Variables › Sensitivity to Coding Granularity and Lookback Windows

Time-Varying and High-Dimensional Confounding · Tutorial 643 of 699

Sensitivity to Coding Granularity and Lookback Windows

You will learn to compare coding granularities and pre-treatment lookback windows using feature rankings, propensity distributions, balance diagnostics, and effect estimates.

Advanced 13 min read

What You'll Learn

  • Explain why aggregating codes can change feature rankings rather than merely shorten the feature list.
  • Compare clinically justified pre-treatment lookback windows without changing the target estimand by definition.
  • Interpret changes in propensity-score distributions and covariate balance across specifications.
  • Calculate a binary-covariate standardized mean difference and an illustrative feature-ranking score.
  • Use a structured sensitivity analysis to assess whether effect estimates are robust to coding choices.
  • Identify limitations of ranking heuristics and reasons not to choose a specification solely by its estimated effect.

Why Coding and Time Windows Deserve Sensitivity Checks

In high-dimensional propensity-score analyses, the covariates are not simply handed to the analyst as a fixed, unambiguous list. A diagnosis or procedure may be represented by a broad parent code or by several more specific child codes. A recorded condition may be counted if it occurred during the previous six months, two years, or another pre-treatment period. These choices affect which features exist in the analytic data, how frequently they occur, and how they relate to treatment and outcome.

Consequently, changing code granularity or the lookback window can change more than a feature ranking. It can change the fitted propensity scores, the degree of overlap between treatment groups, measured covariate balance, and the resulting effect estimate. A sensitivity analysis makes these dependencies visible. It does not establish which specification is true, nor does stability across specifications prove that confounding has been eliminated.

Definition: Coding granularity is the level of detail at which recorded codes are represented as covariates. A broad parent-code indicator may combine several narrower child-code indicators. A lookback window is the specified pre-treatment period in which records are searched to define covariates. A sensitivity analysis compares results across defensible choices of granularity and window while keeping the study population, treatment definition, outcome, and target estimand as comparable as possible.

What Must Stay Fixed, and What May Vary

Let \(A\) denote treatment, \(Y\) the outcome, and \(X\) the measured pre-treatment covariates. The propensity score is \(e(X)=P(A=1\mid X)\). The choice of coding and lookback window changes the operational construction of \(X\), and therefore may change the fitted score. For a causal interpretation using adjustment, the relevant assumptions include consistency, conditional exchangeability given the adjusted covariates, and positivity: for covariate profiles in the target population, treatment probabilities must not be zero or one. These assumptions are substantive; comparing specifications cannot verify them.

The time origin matters. Covariates should be measured before treatment assignment or initiation, according to the design. Including a code recorded after treatment can condition on a consequence of treatment, a mediator, or a collider, and can introduce bias. A longer lookback is not automatically better: it can capture more history but also include stale information, changes in clinical status, or records that are less relevant to treatment at time zero. A shorter window may better reflect current status but miss important prior conditions.

For an interpretable comparison, keep the eligibility criteria, index date, treatment and comparator, outcome definition, follow-up, estimand, and estimation procedure fixed where possible. State each alternative feature definition explicitly. If changing a window also changes eligibility or the available follow-up, report that as a design change rather than attributing all differences to covariate construction.

1
Specify defensible alternatives.
Choose clinically and operationally plausible code groupings and pre-treatment windows before comparing estimated effects.
2
Rebuild features consistently.
For each specification, define code presence, timing, and missingness using the same index date and data rules.
3
Compare the full adjustment process.
Examine feature rankings, fitted propensity distributions, balance, and effect estimates rather than only the final estimate.
4
Explain differences, not just select a winner.
Investigate which covariates and patients account for changes; report limitations and the prespecified primary specification.

Why Feature Rankings Change

An illustrative high-dimensional ranking heuristic is the product of the absolute log odds ratio for the feature-treatment association and the absolute log odds ratio for the feature-outcome association:

$$ R_j=\left|\log(OR_{A,j})\right|\left|\log(OR_{Y,j})\right|. $$

Here \(OR_{A,j}\) and \(OR_{Y,j}\) are odds ratios for feature \(j\) with treatment and outcome, respectively, as defined by the analysis. The log transformation expresses odds-ratio associations on a symmetric scale: an odds ratio of 2 and an odds ratio of \(1/2\) have equal absolute log magnitude. The product is a ranking device, not an effect estimate, causal criterion, or universal rule for selecting covariates. It may be sensitive to sparse cells and to how features are defined.

Aggregation can change both odds ratios. A parent code combines people with different child-code patterns; the resulting association depends on the mixture of those patterns and their frequencies. It is generally not a simple average of child-code odds ratios. Conversely, finer codes can create rare indicators with unstable estimates or separation. Thus a parent feature may rank above its child features, below them, or differently from each of them. A longer window can also increase prevalence or combine episodes that have different associations with treatment and outcome.

The basic calculation makes the ranking's sensitivity clear. If a coding decision changes either odds ratio, it changes one or both absolute log terms, and hence can change the product and rank. Even unchanged odds ratios do not guarantee unchanged rank if other features' values change. Ranking stability should therefore be evaluated across the full feature set, not inferred from one prominent code.

Worked Example: Parent and Child Codes Reorder the Ranking

Suppose a hypothetical claims analysis represents a clinical concept either by two child codes, C1 and C2, or by a single parent code P. In the granular representation, estimated treatment-association odds ratios are 3.083 for C1 and 16.71 for C2; corresponding outcome-association odds ratios are 5.082 and 2.267. Under parent coding, the corresponding odds ratios are 9.000 and 4.636. These are illustrative estimates from the hypothetical data, not causal effects.

For C1, the ranking score is:

$$ R_{C1}=|\log(3.083)|\,|\log(5.082)| \approx 1.1259\times1.6257 \approx 1.830. $$

For C2, it is:

$$ R_{C2}=|\log(16.71)|\,|\log(2.267)| \approx 2.816007344\times0.818457371 \approx 2.30478197 \approx 2.305. $$

After aggregation, the parent-code score is:

$$ R_P=|\log(9.000)|\,|\log(4.636)| \approx 2.1972\times1.5339 \approx 3.370. $$

Thus the granular ranking places C2 above C1, while the parent code's score exceeds both child-code scores. This change does not show that the parent code is the correct adjustment variable. It shows that the heuristic ranking depends on the representation. The analyst should inspect code meaning, prevalence, uncertainty, balance, and the causal role of the feature before deciding how to represent it.

Compare Scores, Balance, and Estimates Together

A useful comparison includes more than the top-ranked features. For each coding and window specification, record the number of features, their prevalence, and the stability of rankings. For example, if the top five lists share three features, their Jaccard similarity is \(3/(5+5-3)=3/7\approx0.429\). This describes overlap between lists, not whether either list is causally adequate.

Also examine propensity-score distributions by treatment group, including their ranges or selected quantiles, and assess covariate balance after the intended matching or weighting procedure. A propensity model can have good apparent prediction while producing poor overlap or residual imbalance. A changed score distribution is a warning to investigate, not by itself proof that one model is preferable. In high-dimensional settings, inspect important clinical features and feature blocks as well as aggregate summaries.

For a binary covariate, a standardized mean difference before or after adjustment can be calculated as:

$$ SMD=\frac{\hat p_1-\hat p_0} {\sqrt{\{\hat p_1(1-\hat p_1)+\hat p_0(1-\hat p_0)\}/2}}, $$

where \(\hat p_1\) and \(\hat p_0\) are the covariate prevalences in the treated and control groups, using the appropriate weighted or matched summaries for a post-adjustment diagnostic. Comparing the same diagnostic across specifications helps identify whether a window or coding choice improves one feature while worsening another. No single threshold certifies adequate balance in every application.

Worked Example: A Longer Window Changes Overlap and Balance

In a hypothetical cohort, investigators compare a 12-month and a 36-month pre-treatment lookback, with the same 1,000 eligible people and treatment definition. The following are illustrative fitted-score quantiles and post-weighting summaries:

SpecificationPropensity-score 5th–95th percentilesPost-weighting prevalence: treatedPost-weighting prevalence: controlWeighted outcome risks: treated / control
12-month window0.12–0.780.300.180.180 / 0.250
36-month window0.08–0.940.340.260.200 / 0.240

For the 12-month specification, the binary covariate's post-weighting standardized mean difference is:

$$ SMD= \frac{0.30-0.18} {\sqrt{\{0.30(0.70)+0.18(0.82)\}/2}} = \frac{0.12}{\sqrt{0.1788}} \approx 0.284. $$

For the 36-month specification:

$$ SMD= \frac{0.34-0.26} {\sqrt{\{0.34(0.66)+0.26(0.74)\}/2}} = \frac{0.08}{\sqrt{0.2084}} \approx 0.175. $$

The longer window has a smaller absolute standardized difference for this covariate, but its 5th–95th percentile range extends closer to one. That combination calls for checking overlap and weight stability rather than declaring the longer window superior. The displayed risk differences are treated minus control: \(0.180-0.250=-0.070\), or -7.0 percentage points, for 12 months; and \(0.200-0.240=-0.040\), or -4.0 percentage points, for 36 months. These are estimates under the respective adjustment specifications. Their 3.0-percentage-point difference may reflect changed adjustment, weighting, and finite-sample behavior; it is not evidence that the lookback itself caused an outcome change.

Separate Specification Sensitivity From Model Failure

Differences across specifications are informative only when the analysis is checked for failure within each specification. A comparison should flag features that become extremely rare after code splitting, highly prevalent after aggregation, or differently timed across windows. Inspect separation or unstable coefficient estimates, extreme propensity scores or weights, effective sample size, and residual imbalance. If a feature is absent because the required historical data are unavailable, distinguish that from a true zero; otherwise the comparison can conflate data availability with clinical history.

For effect estimates, report the same estimand and units across specifications. Present the primary estimate and uncertainty interval, alongside prespecified sensitivity estimates and diagnostics. If estimates vary materially, investigate which codes, patient subgroups, or overlap regions changed. Do not select the coding level or window because it yields the most favorable estimate or the smallest p-value. That practice uses the outcome to tune the adjustment set and can make uncertainty statements misleading.

Clinically specified covariates provide an important reference point: they make clear which known confounders the feature-generation process is intended to capture. Automated ranking can help prioritize a large set but does not replace causal judgment. Likewise, a flexible propensity model may accommodate complex relationships, but it cannot recover information absent from the chosen covariate definitions or repair lack of positivity. Sensitivity analysis complements these approaches by showing how conclusions depend on plausible operational choices.

Worked Example: Summarizing Ranking and Effect Robustness

A hypothetical analysis compares top-five feature lists under a parent-code/24-month specification and a child-code/12-month specification. Three features appear in both lists, so the Jaccard similarity is:

$$ J=\frac{|S_1\cap S_2|}{|S_1\cup S_2|} =\frac{3}{5+5-3} =\frac{3}{7} \approx0.429. $$

The estimated risk differences are -4.0 percentage points (95% confidence interval -7.0 to -1.0) and -2.0 percentage points (95% confidence interval -5.5 to 1.5), respectively. The point estimates differ by 2.0 percentage points, and the second interval includes zero. The appropriate conclusion is that the estimated association is sensitive to the specification and that the second estimate is less precise relative to zero; it is not that one specification has proven the causal effect absent. The intervals quantify sampling uncertainty under each fitted analysis and do not account automatically for trying multiple specifications.

The analyst next checks whether the changed features correspond to meaningful clinical distinctions, whether the longer window worsens overlap, and whether balance differs for key confounders. If the child codes are clinically distinct, combining them may conceal relevant heterogeneity. If they are extremely sparse, fitting them separately may be unstable. The decision should be defended using design knowledge and diagnostics, while both estimates and their limitations remain visible.

Common Pitfalls and Practical Limits

  • Calling a longer window more complete and therefore better. It may add relevant history, but it may also include stale or poorly timed records. Justify windows clinically and respect the pre-treatment time boundary.
  • Treating a top-ranked feature as a confounder by definition. Ranking measures associations under a particular representation; it does not determine causal role. Consider the causal structure and avoid adjusting for post-treatment variables or inappropriate colliders.
  • Comparing only the final effect estimates. Similar estimates can conceal worsening balance or overlap, while different estimates can arise from legitimate changes in measured covariates. Compare feature lists, score distributions, balance, and uncertainty together.
  • Choosing the specification with the preferred result. This makes the reported analysis outcome-dependent. Predefine a primary specification and report defensible alternatives transparently.
  • Assuming stability proves no unmeasured confounding. All compared specifications may omit the same important confounder. Robustness to coding choices is not a test of exchangeability.

The most defensible conclusion is usually conditional: describe which estimates are stable across plausible definitions, which diagnostics change, and what clinical or data limitations remain. A sensitivity analysis maps dependence on analytic choices; it cannot turn imperfectly measured observational data into randomized evidence.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. Why can a parent-code ranking score exceed the scores for its child codes even when it represents the same broad clinical concept?
  2. For a binary covariate, the post-adjustment prevalences are 0.25 in treated people and 0.15 in controls. Calculate the standardized mean difference using the stated pooled-variance formula.
  3. A longer lookback improves balance for one feature but moves the 95th percentile of propensity scores from 0.80 to 0.97. What should be checked before preferring the longer window?
  4. Two specifications produce similar effect estimates. Does this establish that measured and unmeasured confounding are controlled? Explain.

Solutions. (1) Aggregation changes the feature's prevalence and the mixtures of people represented, so its treatment and outcome odds ratios, and therefore the product of their absolute log values, need not equal or average the child-code scores. (2) The numerator is \(0.25-0.15=0.10\). The denominator is \(\sqrt{\{0.25(0.75)+0.15(0.85)\}/2}=\sqrt{0.1575}\approx0.3969\). Thus \(SMD\approx0.10/0.3969=0.252\). (3) Check full score distributions, overlap, extreme weights, effective sample size, and balance across important covariates; the improved balance on one feature alone is insufficient. (4) No. Similar estimates show only that these estimates are stable to the compared choices to the observed precision. The same unmeasured confounding or omitted covariates may affect every specification.

Clinical Biostats