LMEpredict {REEMtree} | R Documentation |
This function generalizes predict.lme
by allowing it to generate predictions for groups that were not included in the original lme
estimation (by setting random effects to 0 or estimating them from other observations in that group).
LMEpredict(lmeObject, newdata, id = NULL, targetName = NULL, EstimateRandomEffects = TRUE)
lmeObject |
an object inheriting from class lme , representing a fitted linear mixed-effects model. |
newdata |
a data frame to be used for obtaining the predictions. (Unlike predict.lme , this is not optional.) |
id |
a vector of group identifiers (required only when EstimateRandomEffects is TRUE ) |
targetName |
a string giving the name of the target variable (required only when EstimateRandomEffects is TRUE ) |
EstimateRandomEffects |
if TRUE , the fitted values include the estimated random effects; otherwise, the predictions are based only on the covariates and ignore the random effects |
This function fills in some gaps in the function predict.lme
that occur when random effects are not estimated for certain groups, but we can estimate them from the new data. If there are no observations in a group with a non-missing value of the target variable, we set the random effects for that group to 0. If there are observations for the target variable for a particular group, the estimated random effect for that group is estimated based on the difference between the fitted values of the fixed effects and the non-missing observations.
a vector with the predictions
Rebecca Sela rsela@stern.nyu.edu
Sela, Rebecca J., and Simonoff, Jeffrey S., “RE-EM Trees: A New Data Mining Approach for Longitudinal Data”.
fm1 <- lme(distance ~ age, Orthodont, random = ~ 1 | Subject) newOrth <- data.frame(Sex = c("Female","Female","Male","Male"), age = c(10, 12, 2, 4), distance = c(25, 26, NA, NA), Subject = c("F30","F30","M30","M30")) # The original LME prediction (without and with random effects) predict(fm1, newOrth, level = 0:1) LMEpredict(fm1, newOrth, EstimateRandomEffects=FALSE) LMEpredict(fm1, newOrth, id=newOrth$Subject, targetName="distance", EstimateRandomEffects=TRUE)