Thanks for the reply!
The reason I was asking about this is that I’ve seen a substantial slow-down in my calls to emmeans functions since brms version 2.14.0 for a large model that includes an ar(1) structure. I thought that the slowdown might have been that the autocorrelation was being included but I guess I was on the wrong track.
Since I have you here, I wonder if you could offer any suggestions for options that might speed up the call to emmeans. Here is a quick example showing what I mean. I created a little dataset complicated enough to bring out the differences between brms versions for a call to an emmeans function (emtrends) - link to model test_model_2022-11-07.rds - Google Drive.
The upshot is that brms v 2.18 takes about twice as long to do the emtrends call as brms v 2.14.0. In my actual model which is much larger than the example below, 2.14.0 is at least 10-20 times faster, making calls to emmeans in 2.18 almost unusable. A quick profile of the calls in each of versions suggested that it might have been due to differences in how the ref_grid is created. It seems that the ref_grid in 2.18 includes the time and grouping factor from the ar(1) structure while brms v 2.14.0 doesn’t.
Do you have any suggestions for how to get the 2.14.0 behavior in 2.18?
Thanks again!
# Fake dataset with trend, grouping factors, largish
x1 <- c(rep('A', 3000), rep('B', 3000))
x2 <- rnorm(6000, mean = 2, sd = 2)
y_orig <- rnorm(6000, mean = 10, sd = 5)
y_mod <- if_else(x1 == 'A', y_orig-x2, y_orig+x2)
gr <- rep(1:60, each = 100)
gr_mod <- rnorm(60, mean = 1, sd = .5)
gr_mod2 <- rep(gr_mod, each = 100)
t <- rep(1:100, 60)
y_trend <- y_mod+y_mod*t/100
y_final <- y_trend + gr_mod2
df <- data.frame(y = y_final, x1 = x1, x2 = x2, gr = gr, t = t)
fit <- brm(y ~ x1*x2 + (1 | gr) + ar(p = 1, time = t, gr = gr),
data = df,
chains = 4,
cores = 4,
file = 'test_model_2022-11-07')
summary(fit)
# system.time(emm1 <- emtrends(fit, ~ x1, var = 'x2'))
emm1 <- emtrends(fit, ~ x1, var = 'x2')
emm1
# Time for brms version 2.14.0: 0.861, 0.650, 0.850 (mean: 0.787)
# Ref grid for brms version 2.14.0
# > ref_grid(fit, ~ x1, var = 'x2')
# 'emmGrid' object with variables:
# x1 = A, B
# x2 = 1.9879
# Time for brms version 2.18: 1.674, 1.246, 1.363 (mean: 1.43; x1.82 longer)
# Ref grid for brms version 2.18
# > ref_grid(fit, ~ x1, var = 'x2')
# 'emmGrid' object with variables:
# x1 = A, B
# x2 = 1.9879
# t = 50.5
# gr = 30.5