Sketching the model results from a glmmTMB object.

328 views
Skip to first unread message

Diego Pavon

unread,
Apr 13, 2018, 8:32:03 AM4/13/18
to tmb-...@googlegroups.com
Dear users

I am having troubles making the figures of the results of a model that looks like this:

mod_unprotIBA2 <- glmmTMB(LogAbu ~ Anomaly_std + NEnessSpp_std + Unprotected_IBA + Winter_std
                         + Unprotected_IBA * Winter_std + NEnessSpp_std * Unprotected_IBA + Winter_std * NEnessSpp_std + Anomaly_std * NEnessSpp_std
                         + Winter_std * NEnessSpp_std * Unprotected_IBA
                         + (1|site) + (1|species),
                         family = gaussian,
                         control = glmmTMBControl(optCtrl = list(iter.max = 2000000, eval.max = 2000000), profile = TRUE, collect = FALSE),
                         data = UnprotIBA)





I have a code to sketch the model results but I do not seem to be able to calculate the predicted values from that model. I first create an X matrix:

X <- model.matrix(~ Anomaly_std + NEnessSpp_std + Unprotected_IBA + Winter_std
                  + Unprotected_IBA * Winter_std + NEnessSpp_std * Unprotected_IBA + Winter_std * NEnessSpp_std + Anomaly_std * NEnessSpp_std
                  + Winter_std * NEnessSpp_std * Unprotected_IBA, data = NewData)

And then I calculate the predicted values:

NewData$Pred <- predict(mod_unprotIBA2, NewData, level = 0) # this does NOT work


or


NewData$Pred <- X %*% fixef(mod_unprotIBA2)

and I get the error:
Error in X %*% fixef(mod_unprotIBA2) : 
  requires numeric/complex matrix/vector arguments


Do you have an idea how to calculate the predicted values from a glmmTMB object so that I can draw the figures?
I acknowledge that I have not provided any data. I thought it is a technical question which does not require data. But if you do need, I can provide the model as .rds

Thank you very much for your help and have a nice weekend!

Best

Diego




--
Diego Pavón Jordán
Finnish Museum of Natural History
PO BOX 17 

Koen van Benthem

unread,
Apr 13, 2018, 5:00:48 PM4/13/18
to Diego Pavon, tmb-...@googlegroups.com
Dear Diego,

I think that when you extract the fixed effects of the model, you'll have to specify which part of the fixed effects you want to have (either zero-inflated or conditional). In you case, there seems to be no zero-inflation, so you will probably want the conditional part. Maybe X %*% fixef(mod_unprotIBA2)$cond gives you better results.

Hope this helps, otherwise hopefully somebody else will provide a better answer!

Best

Koen

--
To post to this group, send email to us...@tmb-project.org. Before posting, please check the wiki and issuetracker at https://github.com/kaskr/adcomp/. Please try to create a simple repeatable example to go with your question (e.g issues 154, 134, 51). Use the issuetracker to report bugs.
---
You received this message because you are subscribed to the Google Groups "TMB Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmb-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tmb-users/CAD93_FqZgppVb1vHu7mBLNbCQ25B1vu%3D_6Dk-iqYOifMgCzosQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Diego Pavon

unread,
Apr 16, 2018, 2:58:16 AM4/16/18
to Koen van Benthem, tmb-...@googlegroups.com
Dear Koen and all,

Thanks a lot! that worked. And obviously, I got stuck in the next step, which is to calculate the standard errors for the predicted values. These, I typically calculate them as:

SE <- sqrt(  diag(X %*%vcov(mod_unprotIBA2) %*% t(X))  ) 

So, all the sigmas are in the diagonal in the variance-covariance matrix.
 
I guess this command does not get these. Do you have any idea how to extract these from a glmmTMB object?


Thank you very much in advance.

Best

Diego

Diego Pavon

unread,
Apr 16, 2018, 3:04:50 AM4/16/18
to Koen van Benthem, tmb-...@googlegroups.com
Ok,

I used the same command (vcov(model)$cond) to get them.

Thank you very much!

Best

Diego

Reply all
Reply to author
Forward
0 new messages