[R-sig-ME] predict() with varying betas (newparams)

Ben Bolker bbolker at gmail.com
Wed Apr 1 04:24:44 CEST 2015


Hans Ekbrand <hans.ekbrand at ...> writes:

> 
> Dear list,
> 
> I would like to predict() in lme4 using new betas. In order to try out
> the option newparams I tried the following:
> 

> I don't understand what theta is, but I did find a slot in the fitted
> object, my.fit, so I just passed that vector and hoped for the best 
> 
> I would have expected the results to be identical. What am I missing?
> 
> The long term objective is to calculate average marginal effects from
> a glmer() object by using predict() with betas sampled from a
> multivariate distribution, like
> 

 [snip]

Good question.  I'll look into it, I don't understand what's going
on here since for the most part we've been using newparams=
and it has looked sensible -- and your application looks sensible.

A reproducible example:

library(lme4)
gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
             data = cbpp, family = binomial)
mean(predict(gm1,newdata=model.frame(gm1),type="response"))
mean(predict(gm1,newdata=model.frame(gm1),
             newparams=getME(gm1,c("theta","beta")),type="response"))

mean(p0 <- predict(gm1,newdata=model.frame(gm1)))
mean(p1 <- predict(gm1,newdata=model.frame(gm1),
                   newparams=list(beta=fixef(gm1))))
             


>



More information about the R-sig-mixed-models mailing list