# How does a fitted linear mixed effects model predict longitudinal output for a new subject?

I fitted a linear mixed effects model using nlme package for aids dataset. Here, CD4 is the CD4 cell count, obstime is the time of observation, and patient is the patient id.

My linear mixed effects model looks like this:

lmeFIT <- lme(CD4 ~ obstime, random = ~ 1|patient, data=aids_train)


I have split my dataset into training and testing set where, my testing set consists of data from 2 subjects and training set consists of data from the remaining subjects. The model shown above, fits random intercepts for different patients in the training dataset. Now, my questions are

1. Once the model has been fitted, how exactly does mixed effects model predict outputs for new patient ids in my testing dataset?
2. All the examples I have seen online show that using mixed effects models we can plot fitted lines with different intercepts for each subject in the training dataset. However, how do we know what the intercept would be for the new dataset in the testing dataset? What is the mathematical explanation for that?

Provided that you have at least one data point for the new patient, you can calculate individualized (dynamic) predictions.

In particular, say that $$y_j^o$$ denotes the observed outcome data for the new patient $$j$$, then you can first obtain an estimate, say $$b_j^*$$ of his/her random effects from the posterior distribution $$[b_j \mid y_j^o, \theta]$$, where $$\theta$$ denotes the model parameters. For example, $$b_j^*$$ is the mean of this posterior distribution. Given this estimate of his/her random effects, you calculate predictions using $$x_j(t) \beta + z_j(t) b_j^*$$, where $$x_j(t)$$ and $$z_j(t)$$ denote the design matrices for the fixed and random effects at the (future) time points of interest, and $$\beta$$ denotes the fixed effects. Standard errors for these predictions can be obtained using a Monte Carlo scheme.

For models fitted by lme() you can obtain these predictions using function IndvPred_lme() from package JMbayes. If you have categorical longitudinal data, you can obtain the same type of individualized predictions using the predict() method for models fitted by the mixed_model() function of the GLMMadaptive package; for more info on the latter, you can also check the vignette.

• This makes sense. So @Dimitris Rizopolous, is this the scheme you use in your JM package for dynamic predictions of longitudinal responses? And then use those predicted values in the joint model to predict survival probablities? Is there a simple step-by-step guide for JM model fitting and dynamic predictions? – rish Sep 19 '18 at 12:38
• You can find material in my website drizopoulos.com – Dimitris Rizopoulos Sep 19 '18 at 13:05
• Thanks a lot @Dimitris Rizopolous.... are there python equivalent packages for these (JMbayes and GLMMadaptive)? – rish Sep 19 '18 at 21:05
• As far as I know no. – Dimitris Rizopoulos Sep 20 '18 at 0:52

The random intercepts for the subjects represent deviations from a mean population-level response. When predicting for a new subject, the fitted random effects are not helpful; this is because there is no way of knowing a priori how that subject's pattern deviates from the population-level response. Instead, the best prediction for any new subject will be the population response by itself.

EDIT: There's no contradiction between the two answers here. @DimitrisRizopoulos makes the assumption that you have some information about the new patient i.e. at least one measurement. In contrast, I am making the assumption that you have no measurements of the new patient - in this case, the population response is the best prediction for any new patient.

• So would it be correct to assume that basically mixed effects models are only useful for analyzing training dataset and for testing dataset it reduces to just a linear model? – rish Sep 18 '18 at 21:25
• @rishrish I'm not entirely sure what you mean. But it's important to note that the population-level response need not be identical to that of a model with fixed effects only. Think about a case where subjects have different numbers of measurements. A model with fixed effects only would have its overall pattern biased towards the pattern shown in the overrepresented subjects. Introducing the random effect should account for this bias and lead to a different population-level pattern - one that makes is more accurate in predicting values for new subjects. – mkt - Reinstate Monica Sep 18 '18 at 21:30
• @rishrish Sure thing, happy to help! – mkt - Reinstate Monica Sep 18 '18 at 21:38
• i think prof. Dimitris Rizopolous's answer seems more relevant. Have a look.. – rish Sep 19 '18 at 12:33
• I'm not aware of any inaccuracy in the answer, but would be happy to be corrected. – mkt - Reinstate Monica Dec 7 '18 at 8:31