Hi
I am getting different predictions for two models where the model summaries are exactly the same. The models include a quadratic term. It must be to do with the way I am specifying the newdata or using predict(), but I can't figure it out. Any help is greatly appreciated!
Important background is that I am scaling my predictor variable (YSF) prior to fitting the model because when I used scale() within the model call, predictions did not work when for second variable (not included in the models below). Something similar was described in an older post on this forum.
With regards to the code below, all of the values from summary() are exactly the same for occ1.1 and occ1.2, but when I predict using new data, the predictions are very different. I note that this does not occur if I remove the quadratic term from the model and just fit YSF.
Can you see anything wrong with the way I am specifying the newdata or using predict()?
I have checked that the scaled values in newdata1.2 match with the unscaled values for newdata1.1. I also tried changing the order of scaling and transforming, but that didn't help.
Many thanks.
# scale YSF for model 1.2
umf_list$Woyl@siteCovs$YSF_sc = scale(umf_list$Woyl@siteCovs$YSF)
# store the YSF transformation values
ysf_center <- attr(scale(umf_list$Woyl@siteCovs$YSF), "scaled:center")
ysf_scale <- attr(scale(umf_list$Woyl@siteCovs$YSF), "scaled:scale")
# fit model 1.1 where scaling is done inside the model
occ1.1 = occu(~Track + Season
~scale(YSF) + I(scale(YSF)^2) +
(1|LocationName_numeric) + (1|Year),
data = umf_list$Woyl)
# fit model 1.2 with the pre-scaled YSF
occ1.2 = occu(~Track + Season
~YSF_sc + I(YSF_sc^2) +
(1|LocationName_numeric) + (1|Year),
data = umf_list$Woyl)
# predict the first model (occ1.1)
newdata1.1 = data.frame(YSF = 0:55)
pred1.1 = unmarked::predict(occ1.1, newdata=newdata1.1,
type="state", append=TRUE, re.form = NA)
# predict the second model (occ1.2)
YSF_seq = 0:55
newdata1.2 <- data.frame(YSF_sc = (YSF_seq - ysf_center) / ysf_scale)
pred1.2 = predict(occ1.2, newdata=newdata1.2,
type="state", append=TRUE, re.form = NA)