Tutorials › Marginal Structural Models › A Continuous-Dose Worked Example

Inverse Probability of Treatment Weights · Tutorial 127 of 501

A Continuous-Dose Worked Example

Work through fitting a conditional normal dose model and calculating continuous-treatment weights from observed dose densities.

Advanced 12 min read

What You'll Learn

  • Specify a conditional normal model for a continuous dose given pre-dose history
  • Estimate group-specific means and a common variance by maximum likelihood
  • Evaluate fitted dose densities and calculate inverse-density weights
  • Explain why a density is not a probability and why continuous-treatment weights depend on measurement units
  • Identify model and positivity problems that can make calculated weights unreliable

From Treatment Probabilities to Dose Densities

For a discrete treatment, an inverse-probability weight uses the probability of the treatment actually received, conditional on the observed history. A continuous dose does not have a positive probability of equaling any one exact value under a continuous distribution. The corresponding quantity is a density evaluated at the observed dose. This tutorial works through that calculation at one decision time in a small longitudinal dataset.

The example uses a binary summary \(H_t\) of the history measured before dose \(A_t\). In an application, the history may include past covariates and past treatments; the important ordering is that it is measured before the current dose. The calculation below is for one decision time only, not a product of weights across times.

Definition: Let \(A_t\) be a continuous treatment dose and \(H_t\) the observed history immediately before that dose. If \(f(a\mid h)\) is the conditional density of \(A_t\) given \(H_t=h\), the unstabilized inverse-density weight for an individual with observed dose \(a\) and history \(h\) is $$ W_t=\frac{1}{f(a\mid h)}. $$ In practice, a fitted conditional density \(\hat f\) gives the estimated weight \(\hat W_t=1/\hat f(a\mid h)\). The density is evaluated at the individual's observed dose.

This calculation requires a model for the conditional dose distribution. For the worked example, assume that doses are conditionally independent across individuals and that, given history group \(h\), the dose follows a normal distribution with group-specific mean \(\mu_h\) and a common variance \(\sigma^2>0\):

$$ A_i\mid H_i=h \sim N(\mu_h,\sigma^2), \qquad f(a\mid h)=\frac{1}{\sqrt{2\pi\sigma^2}} \exp\left\{-\frac{(a-\mu_h)^2}{2\sigma^2}\right\}. $$

For a causal interpretation of inverse-probability weighting, additional design and causal assumptions are needed, including consistency, adequate control of treatment-confounder history, and positivity. At the calculation stage, the fitted density must also be a reasonable description of the observed conditional dose distribution. A small dataset can illustrate arithmetic, but it cannot establish those assumptions.

Fitting the Conditional Normal Model

Consider six individuals observed at the same eligible decision time. The history indicator is recorded before the dose. Fit a separate mean for each history group and one common variance.

IndividualPre-dose history \(H_i\)Observed dose \(A_i\)
101
202
303
413
514
615

Worked Example: Fit the Group Means and Common Variance

For \(H_i=0\), the three doses are \(1,2,3\), so \(\hat\mu_0=(1+2+3)/3=2\). For \(H_i=1\), the doses are \(3,4,5\), so \(\hat\mu_1=(3+4+5)/3=4\). The residuals, in individual order, are \(-1,0,1,-1,0,1\).

The residual sum of squares is \(1+0+1+1+0+1=4\). Under maximum likelihood, the estimate of the common variance divides this sum by the total number of observations, six: \(\hat\sigma^2=4/6=2/3\). Thus the fitted conditional distributions are \(\hat A\mid H=0\sim N(2,2/3)\) and \(\hat A\mid H=1\sim N(4,2/3)\).

This is the maximum-likelihood variance estimate, not the degrees-of-freedom-adjusted residual variance. The distinction matters when reproducing fitted densities from a specified likelihood.

Result: With \(n_h\) independent normal observations in each group, separate means \(\mu_h\), and one common variance, the maximum-likelihood estimates are $$ \hat\mu_h=\bar A_h, \qquad \hat\sigma^2=\frac{1}{n}\sum_h\sum_{i:H_i=h}(A_i-\bar A_h)^2, \qquad n=\sum_h n_h, $$ provided the residual sum of squares is positive.

To verify the result, write the likelihood as \(L(\{\mu_h\},\sigma^2)=(2\pi\sigma^2)^{-n/2} \exp\{-\sum_h\sum_{i:H_i=h}(A_i-\mu_h)^2/(2\sigma^2)\}\). For fixed \(\sigma^2\), maximizing this likelihood is equivalent to minimizing the sum of squared residuals. Differentiating that sum with respect to \(\mu_h\) gives \(-2\sum_{i:H_i=h}(A_i-\mu_h)=0\), and hence \(\hat\mu_h=\bar A_h\). Let \(S=\sum_h\sum_{i:H_i=h}(A_i-\bar A_h)^2\). Substitution into the log-likelihood gives \(\ell=-\frac n2\log(2\pi\sigma^2)-S/(2\sigma^2)\). Its derivative with respect to \(\sigma^2\) is \(-n/(2\sigma^2)+S/(2(\sigma^2)^2)\), which is zero at \(\hat\sigma^2=S/n\). When \(S>0\), the log-likelihood increases before this value and decreases after it, so this is the maximum. Here \(S=4>0\), yielding \(4/6=2/3\). \(\square\)

Evaluate the Observed Densities and Weights

Using the fitted parameters, every observed dose in the same history group is evaluated with that group's normal density. In this example the common density prefactor is \(1/\sqrt{2\pi(2/3)}=1/\sqrt{4\pi/3}\approx0.4886\). The weights are reciprocals of the resulting densities.

Worked Example: Calculate All Six Inverse-Density Weights

For individual 1, \(H_1=0\), \(A_1=1\), and the fitted mean is 2. The residual is \(-1\), so

$$ \hat f(1\mid H=0) =\frac{1}{\sqrt{2\pi(2/3)}}\exp\left\{-\frac{(1-2)^2}{2(2/3)}\right\} =0.4886\exp(-0.75) \approx0.2308, \qquad \hat W_1=\frac{1}{0.2308}\approx4.333. $$

For individual 2, the dose equals the fitted group mean. The exponent is zero:

$$ \hat f(2\mid H=0)=0.4886\exp(0)=0.4886, \qquad \hat W_2=\frac{1}{0.4886}\approx2.047. $$

Individual 3 has dose 3 and history 0, so its residual is \(1\). Its squared residual gives the same density as individual 1: approximately \(0.2308\), and its weight is approximately \(4.333\). For individual 4, the dose is 3 and the history-specific mean is 4; the residual is \(-1\), again giving density \(0.2308\) and weight \(4.333\). Individual 5 is at the \(H=1\) mean of 4, giving density \(0.4886\) and weight \(2.047\). Individual 6 has dose 5, one unit above that mean, giving density \(0.2308\) and weight \(4.333\).

In individual order, the fitted weights are therefore approximately \(4.333, 2.047, 4.333, 4.333, 2.047, 4.333\). They are large for doses one unit from their group mean and smaller for doses at the mean because the fitted density is lower away from the mean.

Result: Under the fitted normal model, the inverse-density weight has the form $$ \hat W_i=\sqrt{2\pi\hat\sigma^2}\, \exp\left\{\frac{(A_i-\hat\mu_{H_i})^2}{2\hat\sigma^2}\right\}. $$ For fixed \(\hat\sigma^2\), this weight is minimized at the fitted mean and increases with the squared distance from that mean. This follows directly because the exponential function is increasing and the squared residual is nonnegative.

A density is not a probability: it can exceed one, and its numerical value depends on the measurement scale. Consequently, an inverse-density weight is not unitless. This is an important feature of continuous-treatment weighting, not an arithmetic error.

Worked Example: A Dose Half a Unit From the Mean

For an individual with \(H=1\) and observed dose \(A=4.5\), the fitted mean is 4 and the residual is \(0.5\). The exponent magnitude is \((0.5)^2/[2(2/3)]=0.25/(4/3)=0.1875\). Therefore,

$$ \hat f(4.5\mid H=1)=0.4886\exp(-0.1875)\approx0.4051, \qquad \hat W=\frac{1}{0.4051}\approx2.469. $$

This is between the weight at the fitted mean, approximately \(2.047\), and the weight one full unit from the mean, approximately \(4.333\), as the squared-residual expression predicts.

Assumptions, Diagnostics, and Comparisons

The conditional normal calculation assumes that the specified history is adequate for modeling dose assignment, that the conditional dose distribution is normal with a common variance across the history groups, and that the fitted model is estimated from appropriate observations at the decision time. A causal analysis additionally needs sequential exchangeability given the observed history and positivity: relevant histories must have support for the doses targeted by the analysis. A normal model has positive density at every real dose, but that mathematical property does not establish adequate empirical support or correct specification.

Diagnostics should focus on the conditional distribution, not just on the group means. Inspect residuals within history strata for skewness, heavy tails, outliers, and changing spread; compare observed dose ranges across histories; and examine the calculated weights for unusually large values. A very small fitted density produces a very large weight, so a few such observations can dominate a weighted analysis. A common variance may be inappropriate if residual spread differs substantially by history. If the normal form or variance structure is implausible, a different conditional density model may be needed; changing the model does not remove the need to check support and fit.

For a binary or multinomial treatment, the observed treatment receives a conditional probability, and the inverse weight is the reciprocal of that probability. For a continuous dose, use the conditional density at the observed dose instead. Replacing that density with a probability of an exact dose is incorrect: under a continuous distribution, the probability of any single exact value is zero. Conversely, a density should not be interpreted as a probability or compared numerically across different dose units without accounting for the scale.

Worked Example: Changing the Dose Unit

Suppose the dose is recorded in units ten times smaller, so the numerical value \(A=1\) becomes \(B=10A=10\). The change-of-variable formula gives \(f_B(b\mid h)=f_A(b/10\mid h)/10\), because \(db/dA=10\). For the first individual's dose, the density changes from approximately \(0.2308\) to \(0.2308/10=0.02308\), and the inverse density changes from \(4.333\) to \(1/0.02308\approx43.33\).

In general, if \(B=cA\) for \(c>0\), then \(f_B(b\mid h)=f_A(b/c\mid h)/c\). This follows from probability preservation: for a small interval \(db\), the corresponding interval in the original units has length \(da=db/c\), so \(f_B(b\mid h)db=f_A(b/c\mid h)db/c\). Thus the inverse density is multiplied by \(c\). The density and weight numbers change with units, while the underlying dose ranking and fitted distribution after conversion do not. \(\square\)

The unit dependence is one reason to report the dose scale and model clearly. It also warns against treating the raw inverse density as a probability weight with an intrinsic unit-free magnitude. This calculation supplies the treatment-density component at one decision time; it does not by itself resolve model misspecification, confounding, or support problems.

Common pitfall: Using \(1/\hat f\) is correct for the specified inverse-density calculation, but calling \(\hat f(a\mid h)\) the probability of observing the exact dose is not. In a continuous model, that exact-dose probability is zero. The correction is to evaluate the density at the observed dose and interpret the result as a scale-dependent inverse-density weight, not as the reciprocal of a point probability.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. With fitted mean 4 and variance \(2/3\), what are the fitted density and inverse-density weight at dose 4?
  2. Under the same model, what are the density and weight at dose 5? Show the exponent used.
  3. If the dose is multiplied by 10, what happens to the density and inverse-density weight at the corresponding dose?
  4. Why is a very large inverse-density weight a reason to inspect the model and data?

Solutions. (1) The residual is zero, so the density is \(1/\sqrt{4\pi/3}\approx0.4886\), and the weight is \(1/0.4886\approx2.047\). (2) The residual is \(1\), giving exponent \(-1/[2(2/3)]=-0.75\); hence the density is \(0.4886\exp(-0.75)\approx0.2308\), and the weight is approximately \(4.333\). (3) The density is divided by 10 and its reciprocal is multiplied by 10, by the change-of-variable formula. (4) A large weight corresponds to a small fitted density at the observed dose. It can indicate sparse support, an unusual observation, or a poorly fitting conditional density model, and can make weighted results sensitive to that observation.

Clinical Biostats