[R-sig-Geo] Error in mixed model spatial prediction

Dechen Lham dechen@|h@m @end|ng |rom |eu@uzh@ch
Tue Nov 12 13:51:51 CET 2019


Hi all,

I am trying to do a mixed logistic model prediction on a rasterstack (3 layers) as below and it gives me this error.:

# model response is a integer (0,1)
model1 <- glmer(loss ~ Location + Presence_Absence_SPP + density_am +
                                       (1|grid_id), family = binomial("logit"), data=DATA)

# rs is raster layer composed of 2 layers of factors and 1 layer of numeric variable.
mod_pred <- predict(rs, m1, type="response", index=1:3)

# error
Error in `contrasts<-`(`*tmp*`, value = contrasts.arg[[nn]]) : 
  contrasts apply only to factors

# i tried to do with re.form=~0, based on some suggestions on the net. But think it is not correct to do this, otherwise the model is a glm predictions and not a mixed model predictions. 

With or without re.form=~0, i get the same error. Could anyone suggest one can make such predictions using rasterstack in r? I checked my raster rs structure and the variables have class like the ones in model1. So i am unable to understand what i am doing wrong. Some help is highly appreciated.

Best



More information about the R-sig-Geo mailing list