0
votes

I fitted a zero inflated poisson model using gam() from the mgcv package

 ziplss.fit.mixed <- gam(
    list(
      n.ind ~ as.factor(data.type) + s(year) +s(enz,bs="re") + s(clc.3,bs="re") + te(lon, lat), 
      ~ as.factor(data.type) + s(year) + s(enz,bs="re") + s(clc.3,bs="re") + te(lon, lat)),
    family=ziplss(),
    data = dat,
    control = gam.control(keepData = TRUE)
  )

Every time I try to do predictions I get the following message

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels

I even tried to predict using the data I used for the fit. It gives the same error

predict.gam(ziplss.fit.mixed, newdata = ziplss.fit.mixed$data, newdata.guaranteed = TRUE)

If I change back to a regular poisson gam with the same formula then it works.

Any idea why the ziplss option triggers the error ?

Thanks for your help

1

1 Answers

0
votes

For some unknown reason it appears you have to format your variables when predicting from a ziplss family fit.

For instance if you wrote 'as.factor(my.var)' in your model, then your new data must be of class factor.