Independent Gaussian random intercepts and random slopes give marginal within-group covariance . In
lme4, separate terms (1 | group) and (0 + x | group) impose zero intercept-slope covariance; (1 + x | group) estimates it. This independence restriction depends on the predictor origin: replacing by transforms the intercept effect to , generally correlated with .Given Gaussian random intercept and random slope , let the conditional incidence rate be . The normal moment-generating function gives the displayed marginal rate, with . Thus the conditional annual rate ratio for a cluster is , whereas the marginal rate ratio also contains covariance and variance terms. Centering at a chosen year makes intercept heterogeneity refer directly to that year.
Past exam of the mathematics course of the University of Cambridge 2009 iii Paper 102 4 c Solution Created 2026-10-03 Updated 2026-10-14
Center time at 2008 by setting , and initially ignore the explanatory covariates. A Poisson generalized linear mixed model addressing both heterogeneity questions isHere describes between-village variation of log rates in 2008, while describes heterogeneity of annual log-rate changes. The latent 2008 rate has median , mean and coefficient of variation . A central 95% interval for latent village rates is ; the corresponding interval for village-specific annual rate ratios is . These describe heterogeneity, not confidence intervals for estimated fixed effects.
Fit an intercept-only random-effects model and then add a correlated random slope. Compare them with a parametric bootstrap of the likelihood improvement: the null slope variance is on the boundary, so an ordinary fixed-effect chi-squared reference is not automatically valid. Inspect uncertainty in both variance components, shrinkage of village-specific estimates, residual overdispersion and remaining serial correlation. A negative-binomial conditional model can distinguish additional within-village count variation from persistent village differences when the data support it.
By the marginal mean of a Poisson random-slope model, the marginal log rate is , so marginal curvature can arise even when each village has a straight conditional log trend. Numerical variance estimates and evidence of heterogeneous slopes cannot be obtained for 32 villages from two displayed trajectories.
Past exam of the mathematics course of the University of Cambridge 2013 iii Paper 30 4 a Solution Created 2026-10-03 Updated 2026-10-07
Measurements from the same person share baseline strength and likely share an individual response to training. An ordinary linear model with independent errors treats all 600 readings as independent conditional on week; that fails to represent their within-person correlation. The regression residuals can remain associated even when the population mean is linear in time. A random intercept captures differences in baseline strength, and a random slope can additionally describe differences in progress.
Past exam of the mathematics course of the University of Cambridge 2013 iii Paper 30 4 c Solution Created 2026-10-03 Updated 2026-10-07
Allow each subject to have a separate baseline and slope through a correlated random-intercept and random-slope model:The subject random effects are independent of all measurement errors, and subjects are independent. The within-person covariance between times is , with an additional when the same reading is used twice.
Prefer the model with a random slope. The maximum likelihood estimation refits improve twice the log-likelihood by while adding two covariance statistical parameters. Both the Akaike information criterion ( to ) and Bayesian information criterion ( to ) strongly favour it. The printed nominal likelihood-ratio test is overwhelming. The usual reference chi-squared distribution with two statistical degrees of freedom is not an exact regular calibration, since zero slope variance is a boundary and the intercept–slope correlation is then unidentified; a design-specific parametric bootstrap could calibrate it. This qualification does not undermine the substantial descriptive improvement shown by both information criteria.
The preferred fit estimates population mean baseline strength kg and weekly gain kg/week. The between-person baseline standard deviation is kg, and the between-person slope standard deviation is kg/week. Their estimated correlation is weakly positive, giving random-effect covariance about kg/week; its uncertainty is not supplied. The measurement-error standard deviation is kg. The printed instead describes the correlation between the estimated fixed effects, not between the subject random effects. These statistical parameter estimates come from restricted maximum likelihood; the model comparison uses the separate maximum likelihood estimation fits.
The population mean fitted trajectory is kg. HenceUsing the reported slope standard error, an approximate 95% confidence interval for the population mean gain is kg; a Student t confidence interval with 499 statistical degrees of freedom is almost identical.
Successful individuals can improve far more than the average. Their latent ten-week gains have fitted normal distributionA clear estimate for an upper-performing group uses a between-person slope quantile: the 95th percentile is kg, and the 97.5th percentile is about kg. The upper 5% of fitted underlying gains begin around 73 kg. These are person-to-person performance quantiles, not confidence intervals for the population mean. Identifying the best observed trainee would require that person's data or fitted subject random effects; the aggregate output cannot identify a literal maximum. If performance means the observed difference of endpoint readings, add the measurement-error variance to the latent gain variance.
Past exam of the mathematics course of the University of Cambridge 2016 iii Paper 206 1 e Solution Created 2026-10-03 Updated 2026-10-06
The fitted formula and coefficient table describe a random-slope linear mixed model:with random effects independent of the errors. There is a common fixed intercept, a population slope , and a laboratory random slope deviation . In
tumour1, the three laboratory slopes are unrelated unknown fixed coefficients. Here they are modelled as draws from a common normal distribution; estimated laboratory deviations are shrunk toward zero. After integrating out , observations in laboratory have covariance , so they are marginally dependent even when their conditional errors are independent.The displayed command contains a source inconsistency:
size ~ 1 + (0 + days | lab) would impose zero population slope and could not produce the displayed fixed days coefficient. The output corresponds to size ~ days + (0 + days | lab). Its estimates are , and . The estimated daily increase averaged over the laboratory population isbecause .A random slope is appropriate if these laboratories can reasonably be viewed as exchangeable representatives of a larger population and the goal includes population inference or predictions for other laboratories. If these particular three laboratories are the whole set of interest, or have systematic differences incompatible with exchangeability, laboratory-specific fixed slopes are preferable. Only three groups give weak information about between-laboratory variance; the mixed model does not itself resolve possible nonlinear growth. Its population mean is distinct from a realized finite-group average .
Past exam of the mathematics course of the University of Cambridge 2016 iii Paper 206 1 f Solution 2026-10-06
Retain the random-slope linear mixed model of part (e), but replace the within-laboratory independent error covariance by continuous-time autoregressive residual correlation:Errors from different laboratories remain independent and are independent of the random slopes. The resulting marginal covariance within laboratory isThe exponential decay applies to the conditional errors, not the entire marginal correlation, which also contains the shared random slope.
Use Here
nlme, since lme4::lmer does not fit this general residual correlation structure. With a data frame containing the observed variables, suitable code islibrary(nlme)
dat <- data.frame(size = size, days = days, lab = lab)
dat <- dat[order(dat$lab, dat$days), ]
tumour_cor <- lme(size ~ days,
random = ~ 0 + days | lab,
correlation = corCAR1(form = ~ days | lab),
data = dat, method = "REML")corCAR1 estimates , the error correlation one day apart; correlation at separation is . This works for noninteger or unequally spaced days. At equally spaced integer days, corAR1(form = ~ days | lab) gives the corresponding discrete-time construction when its parameter is positive. Distinct times within each error series are required: separate tumours with repeated day values should have separate series identifiers or an additional independent-error component, rather than being assigned perfectly correlated errors. The continuous-time autoregressive residual correlation documentation describes the grouping and continuous-time conventions: stat.ethz.ch/R-manual/R-patched/library/nlme/html/corCAR1.html. The fixed days term here follows the fitted output rather than the inconsistent command in part (e). Past exam of the mathematics course of the University of Cambridge 2016 iii Paper 206 6 a Solution Created 2026-10-03 Updated 2026-10-06
Write for stirring rate of observation in furnace . The independent random-intercept and random-slope model isErrors and random effects are independent. The separate R terms
(1 | furnace) and (0 + stir | furnace) impose independent random intercepts and random slopes; (1 + stir | furnace) would instead estimate their covariance as well. The estimates areThe corresponding estimated standard deviations are , , and ; they are not additional parameters.For a furnace with predictor vector , the marginal formulation, obtained by integrating the Gaussian random effects, isindependently across furnaces. In particular,In stacked notation , , giving the Gaussian linear mixed model marginal law with .
The residual-versus-fitted plot on page 17 has residuals of both signs over the fitted range, with no convincing smooth curvature or clear fan shape. Its quantile-quantile plot is roughly straight in the central region, with some tail departures and a few large negative residuals. There is no decisive visible violation, but investigate those observations. These plots mainly address conditional observation errors; they do not validate the distribution of furnace random effects or independence within furnaces. With only three furnaces, normality and the variance of the random effects are especially difficult to assess.
Past exam of the mathematics course of the University of Cambridge 2016 iii Paper 206 6 c Solution Created 2026-10-03 Updated 2026-10-06
The restricted maximum likelihood procedure estimates covariance parameters from error contrasts that remove the unknown fixed effects. Let have rank and choose an full-rank matrix with . Then has a likelihood involving the variance parameters but not . Maximizing that likelihood is restricted maximum likelihood. An equivalent restricted likelihood from orthogonal error contrasts, up to terms independent of , iswhereAfter estimating , use generalized least squares for and the conditional modes from part (b). In an independent-error normal linear model, this covariance procedure reduces to estimating by instead of .
The two models being compared have different fixed-effect spaces, so their error contrasts, dimensions, and restricted likelihoods differ. Their REML values are not likelihoods of the same transformed data and must not be used directly for this fixed-effect likelihood-ratio test. Refit both with ordinary maximum likelihood, integrating out the random effects but retaining the original response vector, and maximize each model's marginal likelihood.
The null hypothesis is , leaving the random slope variance free; the alternative permits a nonzero population stirring effect. The supplied test has , one extra fixed coefficient, and approximate p-value . Retain the fixed stirring-rate effect at 5%. A mean-zero random slope cannot substitute for an estimated nonzero population slope. The asymptotic calibration assumes regular nuisance covariance parameters and should be interpreted cautiously with only three furnaces; simulation can provide a better finite-sample calibration.
Past exam of the mathematics course of the University of Cambridge 2016 iii Paper 206 6 d Solution Created 2026-10-03 Updated 2026-10-06
The comparison removes the random slope and tests against , while retaining the same fixed intercept and slope. A variance cannot be negative, so zero is a boundary point of the parameter space. The regular Wilks theorem assumptions behind an ordinary likelihood-ratio test fail. Consequently the default chi-squared p-value from
anova is not reliably calibrated for this variance-component likelihood-ratio test at a boundary. This is different from the fixed-slope test in part (c). The reference to strength_model1 means the earlier object strength_model; no separate model 1 object was defined.A useful alternative is a parametric bootstrap. Fit the null random-intercept model, then simulate data on the actual predictor values and furnace grouping by generating null intercept effects and observation errors from its fitted Gaussian distribution. Refit null and alternative models to each simulated dataset using the same likelihood method and compute the same likelihood-ratio statistic. If is the observed statistic, estimate its upper-tail probability byThis incorporates the zero-variance boundary and the actual small group count. It is a fitted-null simulation approximation because nuisance parameters are estimated, not a universally exact test. Since both models have the same fixed-effect space, a similarly calibrated restricted-likelihood statistic is also possible. Under suitable asymptotics for a single identifiable added variance component the familiar limiting law is , but using the bootstrap avoids relying on that approximation with only three groups. There is no supplied statistic or calibrated bootstrap result here from which to decide whether the slope variance is required.
Past exam of the mathematics course of the University of Cambridge 2016 iii Paper 206 6 e Solution Created 2026-10-03 Updated 2026-10-06
The generalized additive mixed model fitswhere denotes the furnace random intercept and is a centered penalized cubic regression spline. Its wiggly components have a mixed-model representation; there is no explicit furnace-specific random slope in this formula.
The plotted smooth gives no evidence that a nonparametric fixed effect is needed. It is essentially a straight rising line, and
s(stir,1) indicates effective degrees of freedom close to one. The wider bands at extreme stirring rates reflect uncertainty, not detected nonlinearity. A linear fixed stirring effect is adequate on this evidence.If the three supplied Akaike information criterion values are on a common valid likelihood basis, choose
strength_model3, the fixed linear slope plus random-intercept model: its AIC is smallest, versus for the additional random slope and for the smooth. The differences are and , respectively, so especially the random-slope comparison represents modest support rather than decisive evidence. Retaining the population slope is consistent with part (c); this choice removes only its random variation.There is a likelihood-basis caveat in the literal printed commands. The supplied ranking favours the simpler random-intercept model; the displayed original calls alone do not certify that ranking as a consistent ML comparison. This distinction is particularly relevant when the smooth changes the fixed-effect space. The Gaussian
lmer fits by REML by default, whereas the Gaussian gamm call defaults to ML; direct AIC on these objects need not compare the same type of likelihood. Moreover the earlier ML ANOVA prints for strength_model, whereas this table prints , so these numbers should not silently be treated as one identical ML fit. To obtain a defensible common comparison, fit all candidates to the same observations by ML:fit_slope <- update(strength_model, REML = FALSE)
fit_intercept <- update(strength_model3, REML = FALSE)
fit_smooth <- mgcv::gamm(strength ~ s(stir, bs = "cr"),
random = list(furnace = ~ 1), method = "ML")
AIC(fit_slope, fit_intercept, fit_smooth$lme)gamm ML default and mixed-model representation are documented at stat.ethz.ch/R-manual/R-devel/library/mgcv/html/gamm.html. Past exam of the mathematics course of the University of Cambridge 2017 iii Paper 206 3 e Solution Created 2026-10-03 Updated 2026-10-05
There is a genuine syntax error in the printed command: With the default Gaussian family, this generalized additive mixed model isHere across doctors, is an estimated covariance matrix, and the Gaussian errors have variance and are independent of the random effects. The formula
random=list(...) must be a separate argument, following a comma rather than a plus. The intended call ismodel2 <- gamm(npres ~ s(age, bs="cr") + s(wbc, bs="cr"), random=list(doctor=~age))~age includes a random intercept as well as a random slope; it does not force these two effects to be uncorrelated.The random intercept allows different prescribing baselines, and the random slope allows doctor-specific linear modifications to the population age curve. Conditional on these effects the observations are independent under the model, whereas two patients of the same doctor have additional covariance . This accounts for clustered data and avoids treating doctor variation as independent patient-level noise. The population smooth and doctor-specific predictions are different targets. With only four doctors, estimates of the random-effect covariance can be imprecise; the Gaussian support issue for counts also remains. The new model accounts for doctor-specific baselines and age slopes.
Past exam of the mathematics course of the University of Cambridge 2017 iii Paper 206 4 a Solution Created 2026-10-03 Updated 2026-10-05
The random-slope linear mixed model iswith independence between the random effects and errors. The estimates areIncubators are treated as exchangeable representatives of possible growth environments, so a random slope permits their growth rates to differ while estimating a population mean growth rate. The formula
0+hours deliberately removes a random intercept: larvae are assigned only after hatching, so it is reasonable to assume no incubator-specific baseline at time zero. Random assignment supports this common-baseline assumption in expectation; it does not prove that observed initial sizes or other baseline differences are exactly identical.For a new incubator, no observations are available to estimate its realized random slope, and its mean effect is zero. Under squared-error loss the best prediction integrates over that effect and the residual error:This is the plug-in conditional expectation given the population parameters, rather than a prediction using a fitted effect from one of the four existing incubators. Ignoring parameter-estimation uncertainty, the prediction variance for a new individual is ; it is not just the uncertainty in the population mean.
Past exam of the mathematics course of the University of Cambridge 2017 iii Paper 206 4 e Solution Created 2026-10-03 Updated 2026-10-05
The command fits a Gaussian generalized additive mixed modelThe population growth curve is a centered penalized regression spline with a cubic regression basis. The incubator term remains a random slope without a random intercept, because
~0+hours removes the intercept. A population linear component is allowed within the smooth's unpenalized part; curvature is penalized rather than being required.A Inspect whether the fitted curve departs materially from an affine function, particularly in regions supported by observations. The effective degrees of freedom near one suggest that the penalization has selected an approximately linear centered smooth. Bands and partial residuals help distinguish convincing curvature from noisy deviations, although pointwise bands are not a simultaneous test of linearity. A formal comparison would need to account for both smoothing selection and the incubator dependence. The smooth plot tests the visual plausibility of a common straight growth curve while retaining incubator-specific slope variation.
gamm fit returns a list with gam and lme components. Plot the population smooth and pointwise uncertainty bands withplot(fly.model2$gam, se=TRUE, residuals=TRUE) Random slope 2026-10-05
A random slope multiplies a predictor by a group-specific latent coefficient. With , a contribution induces covariance for two observations in group . A random slope does not necessarily include a random intercept.