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


*

*Once the model has been fitted, how exactly does mixed effects model predict outputs for new patient ids in my testing dataset?

*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? 

 A: 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. 
A: 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. 
