prediction without random effect and autocor

54 views
Skip to first unread message

Antonio José Cañada Martínez

unread,
Apr 16, 2018, 11:48:07 AM4/16/18
to brms-users

I have some problems getting predictions from a  mixed model with autocor. When I fit a mixed model with just one covariable and try to get the fitted without the random effect I use re_formula = NA, and the predictions should be equals for the same value on the covariable, but it doesn’t happen. When I try to predict without autocor it works fine.

 

I show you a toy example to guide you.

 

set.seed(123)

data <- data.frame(nhc = factor(rep(1:5, each = 10)), time = seq(0.5,5, by = 0.5),

                   con = rlnorm(50,0.3428,0.614))

library(brms)

library(splines)

no_work <- brm(con ~ ns(time,4) + (1|nhc),

             data = data, autocor = cor_ar(~time|nhc),  control = list(adapt_delta = 0.99))

work <- brm(con ~ ns(time,4) + (1|nhc),

             data = data,  control = list(adapt_delta = 0.99))

 

data.frame(Prediction=exp(fitted(no_work, re_formula = NA)[,1]), nhc=data$nhc, time=data$time)

data.frame(Prediction=exp(fitted(work, re_formula = NA)[,1]), nhc=data$nhc, time=data$time)

 

The prediction for the same time should be the same, but with autocor it is not. 

Paul Buerkner

unread,
Apr 16, 2018, 11:59:15 AM4/16/18
to Antonio José Cañada Martínez, brms-users
That's because when using cor_ar(~time|nhc) it will change its predictions based on the observed responses (which you implictely pass to fitted as well) and because they are different, predictions will differ as well. If you want to model AR-autocorrelation within the residual covariance matrix, go for cor_ar(~time|nhc, cov = TRUE). Then, fitted() will no longer be affected by the autocorrelation structure (but predict() still is).

--
You received this message because you are subscribed to the Google Groups "brms-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brms-users+unsubscribe@googlegroups.com.
To post to this group, send email to brms-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brms-users/dae8477d-41bb-40c4-b00d-0cea49ea4207%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages