Worked answers with reasoning. References point to the
lecture notes PDF
and the notes pages. Questions 12–15 use
hw4_sleep.csv
(18 subjects × 10 days of sleep restriction, Reaction in ms, Days 0–9,
Subject, and the baseline covariates Sex (F/M) and Age; balanced, no
missing values).
Answer: A birth cohort is followed from age 2 to 10, recording each child’s BMI every six months.
Notes §2.1: “Longitudinal data refers to repeated observations taken on individuals.” The defining feature is repeated measurements on the same subject over time, so each child contributes a vector $\mathbf{Y}i = (Y{i1}, \dots, Y_{in})^T$ whose components are correlated — the thing the whole of Part 2 is built to handle. BMI every six months on the same children for eight years is exactly this (and would answer the three research questions: shape of the BMI trajectory, group differences, group × time).
Why the others are wrong — each has one measurement per person, so no within-subject correlation and nothing longitudinal to model:
Answer: While it does not introduce bias, ignoring the correlation tends to lead to underestimating the uncertainty about our estimates.
Notes §2.1: “This correlation must be accounted for in order to obtain valid inference.” The Lecture 8.4 comparison is the demonstration: for the dental interaction model the GEE and the mixed model gave identical coefficients (17.37, $-1.03$, 0.48, 0.30) but different standard errors and $p$-values — the point estimates do not depend on how the correlation is handled, the inference does. Treating $N \times n$ positively correlated measurements as $N \times n$ independent ones claims more information than the data contain, so SEs come out too small and tests too optimistic. (With positive within-subject correlation this is the usual direction; the general point is that the uncertainty is wrong, and typically understated.)
Why the others are wrong:
Answer: The ability to include random effects (e.g., subject-specific intercepts/slopes) to model within-cluster correlation.
Notes §2.2: “The mean response is modeled as a combination of population characteristics (fixed effects) assumed to be shared by all individuals, while subject-specific effects (random effects) are unique to a particular individual — hence the term, mixed effects.” The random effect $b_i$ in $Y_{ij} = X_{ij}\beta + b_i + \epsilon_{ij}$ is what induces the within-person covariance ($\text{Cov}(Y_{ij}, Y_{ik}) = \sigma_b^2$, compound symmetry) and what a GLM has no term for.
Why the others are wrong:
Answer: Participant.
The random intercepts model is $Y_{ij} = X_{ij}\beta + b_i + \epsilon_{ij}$ with
$b_i \sim N(0, \sigma_b^2)$ — the random effect is indexed by $i$, the individual.
Each participant’s three blood pressure readings (baseline, week 4, week 8) share the
same $b_i$, that person’s deviation from the population intercept, and that shared
term is what induces the within-person correlation. In R: (1 | id) — “each id gets
its own random intercept” (Video 35 script).
Why the others are wrong:
Answer: GEEs estimate marginal (population-averaged) effects, whereas LMMs estimate conditional (subject-specific) effects via random effects.
Notes §2.3: the distinction between “marginal models” and “mixed effects models” — “the former are often referred to as population-average models and the latter as subject-specific models.” A marginal model’s mean depends only on covariates, with no random effects, and GEE is its estimation method; $\hat\beta$ “describe[s] the effects of covariates on the population mean response.” The mixed model conditions on $b_i$: $E(Y_{ij} \mid b_i)$. The ECG example is the proof that this is not just words — drug effect $e^{0.57} = 1.77$ (marginal, GEE) vs. $e^{0.89} = 2.4$ (subject-specific, GLMM) on the same data.
Why the others are wrong:
geeglm output shows scale and
$\alpha$ instead of a random-effects block.Answer: Compound symmetry.
With $Y_{ij} = X_{ij}\beta + b_i + \epsilon_{ij}$, $b_i \sim N(0, \sigma_b^2)$, $\epsilon_{ij} \sim N(0, \sigma^2)$ independent (homoscedastic, independent residuals), every measurement on person $i$ shares the same $b_i$:
\[\text{Var}(Y_{ij}) = \sigma_b^2 + \sigma^2, \qquad \text{Cov}(Y_{ij}, Y_{ik}) = \sigma_b^2 \quad (j \ne k)\] \[\Sigma_i = \begin{pmatrix} \sigma_b^2 + \sigma^2 & \sigma_b^2 & \cdots & \sigma_b^2 \\ \sigma_b^2 & \sigma_b^2 + \sigma^2 & \cdots & \sigma_b^2 \\ \cdot & \cdot & \ddots & \cdot \\ \sigma_b^2 & \sigma_b^2 & \cdots & \sigma_b^2 + \sigma^2 \end{pmatrix}\]Constant variance on the diagonal, the same covariance everywhere off it: the
correlation between any two occasions is $\rho = \sigma_b^2/(\sigma_b^2 + \sigma^2)$,
the ICC, no matter how far apart they are. Notes §2.2: “This model induces the
following compound symmetry pattern.” (geepack calls the same thing
"exchangeable".)
Why the others are wrong — each lets the correlation depend on which pair of times, which one shared intercept cannot produce:
Answer: Because dropout of longitudinal measurements depends on the event time (informative dropout), and the survival model should relate risk to the true biomarker rather than its error-prone measurements.
Notes §2.4 gives three subtleties that make the separate-models approach “not quite right”; this option is the first and third:
Why the others are wrong:
tmerge) is exactly that, and the separate-models approach uses it.piecewise / spline / weibull part of method = "spline-PH-GH" chooses.Answer: It assumes that the covariance is larger between observations that are closer together in time.
Notes §2.2, AR(1): constant variance, and correlation $\rho^{\lvert j - k \rvert}$ between occasions $j$ and $k$,
\[\Sigma_i = \sigma^2 \begin{pmatrix} 1 & \rho & \rho^2 & \cdots & \rho^{n-1} \\ \rho & 1 & \rho & \cdots & \rho^{n-2} \\ \cdot & \cdot & \ddots & & \cdot \\ \rho^{n-1} & \rho^{n-2} & \cdots & \rho & 1 \end{pmatrix}\]With $0 < \rho < 1$, adjacent measurements correlate at $\rho$, two apart at $\rho^2$, three apart at $\rho^3$ — decaying with separation but never reaching zero. It is the pattern designed to match the §2.1 fact that “correlations decrease with increasing time separation” (and “rarely approach zero”).
Why the others are wrong:
corstr =
"independence"), no within-subject correlation at all.Answer: Tracking changes in blood glucose level in patients over time, measured after every meal for two weeks.
Everything a linear mixed model is for: a continuous outcome, repeated on the same subjects many times, with the question being how it changes over time. Blood glucose is on the lecture’s own list of longitudinal measurements (§1.9 / 7.1). Each patient gets a random intercept (and perhaps slope) for their own glucose level, and the within-patient correlation across ~40 readings is modelled rather than ignored. The measurement times are also irregular and dense — a case for linear (continuous) time rather than indicators, which the mixed model handles.
Why the others are wrong — one measurement per unit, nothing to correlate:
Answer: 0.17
In the random intercepts model the two variance components are $\sigma_b^2 = 7$ (subject effect) and $\sigma^2 = 34$ (error). The proportion of the total variance explained by between-subject variability is the intraclass correlation (notes §2.2):
\[\text{ICC} = \frac{\sigma_b^2}{\sigma_b^2 + \sigma^2} = \frac{7}{7 + 34} = \frac{7}{41} = 0.1707 \to \mathbf{0.17}\]It is also the common correlation between any two fasting-glucose readings on the same person under the induced compound-symmetry structure (Q6). Here it is low — about 83% of the variation is within-person fluctuation, so repeated readings on one individual are only mildly correlated. (The dental data, by contrast, had ICC $\approx 0.63$–$0.68$.)
Script: hw4_q10.R.
Answer: 1.02
Under AR(1) (notes §2.2) every entry is $\Sigma_{jk} = \sigma^2 \rho^{\lvert j - k \rvert}$: one variance, one correlation, and the lag does the rest. Read the known entries:
| Entries | Lag | Value | Gives |
|---|---|---|---|
| diagonal | 0 | 2.00 | $\sigma^2 = 2.00$ |
| off by one | 1 | 1.60 | $\sigma^2 \rho = 1.60 \Rightarrow \rho = 0.8$ |
| off by two | 2 | 1.28 | check: $2.00 \times 0.8^2 = 1.28$ ✓ |
| corners | 3 | $X$ | $\sigma^2 \rho^3 = 2.00 \times 0.512 = 1.024$ |
Baseline and 9 months are three lags apart, so their covariance is the smallest in the matrix — the AR(1) signature from Q8: covariance decays geometrically with time separation. (Equivalently, the correlations are $0.8$, $0.64$, $0.512$.)
Script: hw4_q11.R — rebuilds the full matrix from $\sigma^2$ and $\rho$.
Answer: 1.05
Both models have fixed effects Age*Sex (R expands this to Age, Sex and Age × Sex);
Sex is a factor with F as reference. The LMM adds (1 | Subject).
ols = lm(Reaction ~ Age*Sex, data = sleep)
lmm = lmer(Reaction ~ Age*Sex + (1 | Subject), data = sleep)
| OLS estimate (SE) | LMM estimate (SE) | |
|---|---|---|
| (Intercept) | 389.50 (30.16) | 389.50 (68.07) |
| Age | $-2.654$ (0.833) | $-2.654$ (1.881) |
| SexM | $-80.05$ (66.87) | $-80.05$ (150.93) |
| Age:SexM | 2.463 (2.287) | 2.463 (5.161) |
This is Q2 made concrete. The point estimates are identical — Age and Sex are constant within subject and the design is balanced, so the random intercept changes nothing about $\hat\beta$. The standard errors more than double, because OLS treats 180 reaction times as 180 independent pieces of information about Age, when there are really only 18 subjects with 18 ages; the LMM’s Satterthwaite df of 14 says as much. OLS calls Age significant ($p = 0.002$); the LMM does not ($p = 0.18$). Ignoring the correlation did not bias the estimate — it understated the uncertainty.
Script: hw4_q12_15.R — Q12–Q15 share the dataset, so they live in one script.
Answer: 40.77
From the same LMM, the random-effects block:
| Variance | |
|---|---|
| Subject (Intercept) $\hat\sigma_b^2$ | 1348.5 |
| Residual $\hat\sigma^2$ | 1958.9 |
About 41% of the variation in reaction time is stable between-person differences;
the rest is within-person, day-to-day. (Note Days is excluded, so the sleep-
restriction trend sits in the residual, inflating $\hat\sigma^2$ and deflating the
ICC relative to a model that included it.) Same formula as Q10.
Answer: 256.62
gee.ex = geeglm(Reaction ~ Days + Age*Sex, data = sleep, id = Subject,
corstr = "exchangeable")
| Estimate | |
|---|---|
| (Intercept) | 342.395 |
| Days | 10.467 |
| Age | $-2.654$ |
| SexM | $-80.049$ |
| Age:SexM | 2.463 |
| $\hat\alpha$ | 0.537 |
The marginal mean is just the linear predictor at the covariate values. For a male ($\text{SexM} = 1$), $\text{Days} = 0$, $\text{Age} = 30$:
\[\hat\mu = 342.395 + 10.467 \times 0 + (-2.654) \times 30 + (-80.049) + 2.463 \times 30 = 256.62\]predict(gee.ex, newdata = data.frame(Days = 0, Age = 30, Sex = "M")) returns the
same. Note the Age, Sex and interaction coefficients are identical to the OLS and
LMM values from Q12 (and Days $= 10.47$ is the familiar sleepstudy slope) — a linear
model with a balanced design, so every method agrees on $\hat\beta$.
Answer: 265.45
gee.ar = geeglm(Reaction ~ Days + Age*Sex, data = sleep, id = Subject, corstr = "ar1")
| Estimate | |
|---|---|
| (Intercept) | 353.403 |
| Days | 10.467 |
| Age | $-2.907$ |
| SexM | $-154.142$ |
| Age:SexM | 5.114 |
| $\hat\alpha$ | 0.835 |
This time the coefficients do move (Age $-2.65 \to -2.91$, SexM $-80 \to -154$), and so does the prediction (256.62 $\to$ 265.45). Nothing about Q2 is contradicted: the GEE is consistent under either working correlation, but with a finite sample the weighting $V_i^{-1}$ in the estimating equations $\sum_i D_i^T V_i^{-1}(Y_i - \mu_i) = 0$ differs between exchangeable and AR(1), so the two solutions differ. The Days slope is untouched (10.47 either way) because it is estimated within subjects, where the weights hardly matter; the between-subject coefficients, estimated from only 18 ages and sexes, are the sensitive ones. The AR(1) $\hat\alpha = 0.83$ is the lag-1 correlation of consecutive days; the exchangeable $\hat\alpha = 0.54$ is the average over all lags.
Rows must be ordered by subject and day for corstr = "ar1" to mean what it says;
the file already is, and the script sorts to be safe.