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

Hans Ekbrand hans.ekbrand at gmail.com
Wed Apr 1 09:32:54 CEST 2015


> On Wed, Apr 01, 2015 at 02:24:44AM +0000, Ben Bolker wrote:
> > Hans Ekbrand <hans.ekbrand at ...> writes:
> > > 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?

Perhaps it is well-known to you, but I noticed that using re.form = NA
gives exactly the same results as when using newparams

mean(predict(my.fit, newdata = my.fit at frame, type = "response",
		     newparams = list(theta = my.fit at theta, beta = my.fit at beta)))

theta parameter vector not named: assuming same order as internal vector
beta parameter vector not named: assuming same order as internal vector
[1] 0.05619105
mean(predict(my.fit, newdata = my.fit at frame, type = "response", re.form = NA))
[1] 0.05619105

Or, when using your reproducible example (thanks for that, BTW)

gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
       			     data = cbpp, family = binomial)

identical(mean(p1 <- predict(gm1, re.form=NA)), mean(p1 <-
predict(gm1,newdata=model.frame(gm1), newparams=list(beta=fixef(gm1),
theta = gm1 at theta))))
theta parameter vector not named: assuming same order as internal vector
[1] TRUE



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