[ADMB Users] help with predict function in glmmADMB

Ben Bolker bbolker at gmail.com
Tue May 27 18:48:51 PDT 2014


  That's because no-one's written a predict() method for glmmADMB fits
yet.  Sorry ...  It should be slightly easier to do now that we've
worked out a reasonably sensible interface on the lme4 side (e.g.
figuring out how to let the user specify which random effects to
condition on).  If you want the cheap version (i.e. ignore all random
effects -> predict the population mean effect only), you can just do e.g.:

library(glmmADMB)
data(bacteria,package="MASS")
bacteria$present <- as.numeric(bacteria$y)-1
bfit <-  glmmadmb(present ~ trt + I(week > 2), random = ~ 1 | ID,
                          family = "binomial", data = bacteria)

newdata <- expand.grid(trt=levels(bacteria$trt),
                 week=unique(bacteria$week))
newX <- model.matrix(bfit$formula[-2],newdata)  ## construct new model
matrix
eta <- newX %*% coef(bfit)  ## compute linear predictor
mu <- plogis(eta)  ## inverse-link: would be exp() for a NB model

  Ben Bolker


On 14-05-24 03:07 PM, Rodrigo Barreto wrote:
> Dear all,
> My name is Rodrigo, im trying to fit some models in glmmADMB and cant
> understand what happen with predict function. Please find below an
> reproducible example of my problem, basically when using pakcage MASS,
> my goal works, but with glmmADMB i cant ....can you guys help me? my best...
> 
> #simulating df
> 
> dat <- data.frame(y = sample(x = 1:10, 100, replace=TRUE),
>                    x1 = as.factor(sample(x = 1:6, 100, replace=TRUE)),
>                    x2 = rnorm(100), x3 = as.factor(sample(x=1:2, 100,
> replace=TRUE)))
> 
> 
> #packages
> 
> 
> library(MASS)
> library(glmmADMB)
> 
> 
> # models
> 
> mod1 <- glmmadmb(y ~ x1 + x2 + x3, data=dat)
> 
> mod2 <- glm.nb(y ~ x1 + x2 + x3, data=dat)
> 
> 
> #newdata
> 
> newdata <- data.frame(x1 = as.factor(6), x2 = 2.5, x3 = as.factor(2))
> 
> 
> 
> #using MASS
> 
> predict.glm(mod2, newdata=newdata)
> 
> 
> #using glmmadmb
> 
> predict(mod1, newdata=newdata)
> 
> 
> 
> Rodrigo.
> 
> 
> 
> -- 
> *Doutorando Rodrigo R.P.Barreto 
> Laboratório de Dinâmica de Populações Marinhas,DIMAR, 
> Universidade Federal Rural de Pernambuco UFRPE 
> Departamento de Pesca e Aquicultura, DEPAq. 
> Av. Dom Manoel de Medeiros, S/N, Dois Irmãos, Recife-PE 
> Fone:+**55 **(81) 3320-6518; +55 (11) 4033-9274*
> *FAX: +55 (81) 3320-6501*
> *skype: rrpbarreto*
> 
> 
> _______________________________________________
> Users mailing list
> Users at admb-project.org
> http://lists.admb-project.org/mailman/listinfo/users
> 



More information about the Users mailing list