I'm trying to predict values with a linear mixed model and new data, but I keep getting errors that both functions I'm trying (predict.lme
from nlme
, and predict.merMod
from lme4
) do not exist. The packages are installed and loaded.
I first tried using predict.lme
(nlme
). I note that I've installed and loaded the package, since obviously this is a reason the function may not be found.
But I get this error:
Error in predict.lme(object = PlotModel.best, newdata = PlotInvData_predict,:
could not find function "predict.lme"
I've had random problems with nlme
before, so I decide to try predict.merMod
(lme4
), but I get the same error that that function can't be found. I thought maybe those functions can't handle the interval argument that the regular predict function can. I get rid of that, and it still doesn't work. I tested other functions in those packages, and they work just fine. So something is wrong with my workflow, but I can't figure out what. It's the same workflow as with the regular predict function, which I've used just fine.
What am I doing wrong?
Here's the new data:
PlotInvData_predict <- read.csv(file="D:/ThesisPart2/Data/PlotInvData_predict.csv", header=TRUE, sep=",")
Heres the model:
PlotModel.best <- lmer(d_InvCov ~ TimeSinceDist + UnitArea_ha + (1|MgmtSame)+ (1|LandMgmt.1), PlotInvData)
Then I first tried using predict.lme
(nlme
). I note that I've installed and loaded the package, since obviously this is a reason the function may not be found.
install.packages("nlme")
library(nlme)
p_bd <- predict.lme(object=PlotModel.best, newdata=PlotInvData_predict, interval="confidence")
Here's the error, again:
Error in predict.lme(object = PlotModel.best, newdata = PlotInvData_predict, :
could not find function "predict.lme"
When using the regular predict function with a different model (linear model), I would get something like this as a result:
fit lwr upr
1 1.098959 0.5803632 1.617556
2 1.156005 0.6627035 1.649306
3 1.213050 0.7408797 1.685220
4 1.270095 0.8143122 1.725879
5 1.327141 0.8824762 1.771805
6 1.384186 0.9449715 1.823401
7 1.441231 1.0015871 1.880875