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

Hans Ekbrand hans.ekbrand at gmail.com
Wed Apr 1 03:45:21 CEST 2015


Dear list,

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

> mean(predict(my.fit, newdata = my.fit at frame, type = "response"))
[1] 0.1445534
> 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

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

  library(MASS) ## 
  n.samples <- 100
  betas <- matrix(mvrnorm(n = n.samples, mu = my.fit at beta, Sigma = vcov(my.fit)), ncol = n.samples, byrow=TRUE)
  new.df <- my.fit at frame
  new.df$Some.var <- my.fit at frame$Some.var - 0.5
  mean(predict(my.fit, newdata = my.fit at frame, type = "response", newparams = list(theta = my.fit at theta, beta = betas[, 1])))
  new.df$Some.var <- my.fit at frame$Some.var + 0.5
  mean(predict(my.fit, newdata = my.fit at frame, type = "response", newparams = list(theta = my.fit at theta, beta = betas[, 1])))
  ... and again with betas[, 2] and so on.



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