Why the Level of Comparison Matters
An exposure-effect pattern can be described by comparing people with different typical exposures, or by comparing occasions when the same person has different exposures. Those are not interchangeable comparisons. People can differ in physiology, disease severity, baseline effect, or other characteristics that also relate to exposure. A within-person contrast removes stable differences between people from the comparison, but it does not remove changes over time or other occasion-specific influences.
Let \(C_{ij}\) denote the exposure for person \(i\) at occasion \(j\), and let \(Y_{ij}\) denote the corresponding pharmacodynamic effect measured in the appropriately matched window. Assume there are \(N\) people, with \(m_i\) observed occasions for person \(i\). The exposure and effect variables must use consistent units and a scientifically appropriate pairing; these contrasts cannot repair a mismatch between an exposure window and an effect measurement.
Defining the Contrasts
For person \(i\), let \(\bar C_i\) and \(\bar Y_i\) be the means of that person's observed exposures and effects. The within-subject slope is the pooled association between deviations from those person-specific means:
When the denominator is positive, this is the least-squares slope for the within-person deviations, with each observed occasion contributing to the sums. Its units are effect units per exposure unit. It summarizes how effect deviations tend to vary with exposure deviations for the same person, pooling the observed within-person variation. It need not be the same for every person.
A between-subject contrast first reduces each person's repeated observations to \((\bar C_i,\bar Y_i)\). There are two common ways to summarize the resulting pattern, and they answer slightly different weighting questions. The ordinary, unweighted slope treats each person mean as one data point:
This gives equal weight to each person, regardless of how many occasions were observed. If the goal is instead the occasion-count-weighted between-person component of the overall observation-level association, use observation-weighted grand means and weights \(m_i\):
These two between-subject slopes are generally different when occasion counts vary. In particular, using observation-weighted grand means while taking an unweighted sum over the person means is not the ordinary slope across people and is not the occasion-count-weighted slope either.
How the Overall Association Splits Into Two Parts
The distinction can be shown directly by writing each observation as its person mean plus a deviation:
Multiply these expressions and sum over all people and occasions. The cross-products between a within-person deviation and a person mean deviation vanish, because person-specific deviations sum to zero: \(\sum_j(C_{ij}-\bar C_i)=0\) and \(\sum_j(Y_{ij}-\bar Y_i)=0\). Therefore:
The same decomposition holds for exposure sums of squares. Thus the overall observation-level slope combines a within-person component and an occasion-count-weighted between-person component; it is not generally equal to either one alone. The identity is descriptive algebra, not a claim that either component is causal.
Worked Example: Calculating Both Contrasts
Suppose three hypothetical people each have two matched exposure-effect occasions. Exposure is measured in mg/L and effect in arbitrary effect units.
| Person | Occasion 1 \((C,Y)\) | Occasion 2 \((C,Y)\) | Person means \((\bar C_i,\bar Y_i)\) |
|---|---|---|---|
| A | (1, 2) | (3, 4) | (2, 3) |
| B | (2, 5) | (4, 5) | (3, 5) |
| C | (4, 7) | (6, 9) | (5, 8) |
Within-subject calculation. For A, the exposure deviations are \(-1,1\) and the effect deviations are \(-1,1\), so the cross-product sum is \(2\) and exposure sum of squares is \(2\). For B, the exposure deviations are \(-1,1\) and effect deviations are \(0,0\), giving cross-product sum \(0\) and exposure sum of squares \(2\). For C, both deviations are \(-1,1\), giving cross-product sum \(2\) and exposure sum of squares \(2\). Hence:
Across person means, \(\bar C_{\text{people}}=10/3\) mg/L and \(\bar Y_{\text{people}}=16/3\) effect units. The between-subject numerator is \(69/9\), and the exposure sum of squares is \(42/9\). Therefore:
The two positive slopes describe different contrasts, and their magnitudes differ. The within-person value summarizes occasion-to-occasion deviations; the between-person value summarizes differences among these three people’s averages. Neither is automatically an estimate of a causal drug effect.
When the Two Patterns Disagree
A clear disagreement can occur when people with higher typical exposure also have higher typical effects, even though each person's effect falls on occasions of higher exposure. For example, a stable difference in baseline effect could create a positive between-person association, while a within-person association is negative. This is one reason a pooled association across all observations can be misleading: it blends the two levels of comparison.
Worked Example: Opposite Within- and Between-Subject Slopes
Consider hypothetical data for two people. Each person's three occasions have matched exposure \(C\) in mg/L and effect \(Y\) in arbitrary units.
| Person | Occasion 1 \((C,Y)\) | Occasion 2 \((C,Y)\) | Occasion 3 \((C,Y)\) | Means \((\bar C_i,\bar Y_i)\) |
|---|---|---|---|---|
| A | (1, 2) | (2, 1) | (3, 0) | (2, 1) |
| B | (5, 8) | (6, 7) | (7, 6) | (6, 7) |
Within each person, exposure deviations are \(-1,0,1\), and effect deviations are \(1,0,-1\). Each person's cross-product sum is \(-2\) and exposure sum of squares is \(2\). Pooling the two people gives:
For the between-subject contrast, the two means change from \((2,1)\) to \((6,7)\). The slope is \((7-1)/(6-2)=1.500\) effect units per mg/L. Thus the between-person pattern is positive while the within-person pattern is negative. These data alone cannot show why the patterns differ; stable person characteristics, occasion-specific factors, or the small amount of data may matter.
Unequal Occasion Counts and Weighting
When people contribute different numbers of occasions, an unweighted analysis of person means and an observation-weighted analysis give more influence to different parts of the data. The following calculation makes that distinction explicit.
Worked Example: Unweighted Versus Weighted Between-Subject Slopes
Suppose three hypothetical people have person means \((\bar C_i,\bar Y_i)=(0,0),(10,0),(20,10)\), with occasion counts \(m_i=1,1,8\), respectively. Exposure is in mg/L and effect in arbitrary units. Assume each person's observations equal their stated means, so there is no within-person variation.
Ordinary slope across people. The unweighted means across the three people are \(\bar C_{\text{people}}=10\) and \(\bar Y_{\text{people}}=10/3\). The covariance numerator is \(100\), and the exposure sum of squares is \(200\):
Occasion-count-weighted slope. The observation-weighted grand means are \(\bar C=(1(0)+1(10)+8(20))/10=17\) mg/L and \(\bar Y=(1(0)+1(0)+8(10))/10=8\) effect units. The weighted cross-product sum is \(1(-17)(-8)+1(-7)(-8)+8(3)(2)=240\). The weighted exposure sum of squares is \(1(289)+1(49)+8(9)=410\). Thus:
The slopes differ because the third person contributes eight times as many occasions as either other person to the weighted contrast, but only one person mean to the unweighted contrast. The choice should follow the intended summary, not an accidental mixture of centering and weights.
Interpretation, Diagnostics, and Limits
These contrasts are useful for deciding what an observed exposure-effect pattern actually compares. A between-subject pattern may be informative about differences among people, but it can be distorted by differences in baseline status, disease severity, body size, adherence, or other characteristics related to both exposure and effect. A within-subject pattern controls for stable characteristics through centering, but it can still reflect changes in disease, concomitant treatment, time, dose history, adherence, or other occasion-level factors. It can also be sensitive to measurement error and to the range of exposure variation within each person.
Before interpreting a contrast, check that the paired exposure and effect measurements are aligned as intended, that the exposure varies enough to define the slope, and that the person-level means and occasion counts are correctly calculated. Inspect individual trajectories as well as summary slopes: a pooled within-person slope can hide different person-specific patterns, and an extreme individual may dominate if that person has unusually large exposure deviations. If occasions are repeated within people, treating every observation as an independent person for inferential calculations would ignore dependence; these descriptive formulas alone do not provide valid uncertainty estimates.
The main alternatives answer distinct questions. An unweighted between-person slope gives each person's average equal standing. The weighted between-person slope gives people influence in proportion to their number of observed occasions and matches the between component of the observation-level decomposition. The within-person slope uses deviations from individual means. A single pooled slope over all observations blends within- and between-person variation. None is universally best: report which contrast was used and why, and do not interpret a descriptive contrast as a model-based causal effect.
Check Your Understanding
Answer each question, then compare with the solutions.
- In one sentence, distinguish what a within-subject slope compares from what an unweighted between-subject slope compares.
- For person means \((1,2)\) and \((3,6)\), calculate the unweighted between-subject slope in effect units per exposure unit.
- Why can a positive between-subject slope coexist with a negative within-subject slope?
- Three people have equal person means \((0,0),(2,2),(4,4)\), but occasion counts \(1,1,8\). Which slope gives each person equal influence: the unweighted or weighted between-subject slope?
Solutions. 1. The within-subject slope relates deviations from each person's own exposure and effect means; the unweighted between-subject slope relates the person means, giving each person equal weight. 2. With two points, the slope is \((6-2)/(3-1)=2.000\) effect units per exposure unit. 3. People with higher average exposure may also have higher stable baseline effects, even if exposure increases within each person coincide with decreasing effects. 4. The unweighted slope gives each person equal influence; the weighted slope gives more influence to the person with eight occasions.