I've surfed the web and haven't found a satisfactory answer for this.
How would I generate a prediction interval for from a lmer object for each observation in the test dataset?
train_ind <- sample(seq(1:nrow(iris)), size = nrow(iris)/2, replace = F)
TRAIN <- iris[train_ind,]
TEST <- iris[-train_ind,]
m1 <- lmer(Sepal.Length ~ Sepal.Width + Petal.Length + (1|Species), data = TRAIN)
interval has no argument with predict. sim apparently doesn't work so I need to use an mcmc function that comes with LMER and draw from quantiles?
We just released a package called
merToolswhich eases this process. It does not provide a complete prediction interval because it skips the step of simulating thethetaterms in themerMod, but it does produce an interval that accounts for the variation in the fixed effect coefficients, random effect coefficients, and the residual error in the model. It's also pretty fast.It's that easy, you can change the values you want returned, return all simulated values of yhat, and you can also adjust the width of the prediction interval you are interested in obtaining.