I have fit a longitudinal Gaussian model in brms on a data set of about 400,000 individual observations and with a couple of hierarchical/penalized terms. See the formula below.
brmsformula(
y ~ s(time, k = 5) + s(time, state, k = 5, bs = "fs") + subgroup + (1 | subgroup:state),
decomp = "QR"
)
So we have a
- a global average time trend
- state-specific average time trends, shrunken towards the global trend
- state varying intercepts
- global subgroup effects
- subgroup varying intercepts within states.
There are about 70 states and within each state, there are exactly 6 subgroups nested. Time data is discrete in 30 equally-spaced steps, but obviously modeled continuously. All continuous variables are scaled to mean 0 and SD 1.
The model does what it should do and converged well, but fitting with configuration …
chains = 2,
iter = 5e3,
warmup = 1e3,
control = list(adapt_delta = 0.825),
prior = c(set_prior("exponential(1)", class = "sigma"),
set_prior("exponential(1)", class = "sd"),
set_prior("exponential(1)", class = "sds"),
set_prior("normal(0,2)", class = "Intercept"),
set_prior("normal(0,2)", class = "b")
),
backend = "cmdstanr",
normalize = FALSE,
threads = threading(16)
… took about 5 days on 32 CPUs.
Are there obvious ways to speed that up, e.g., by setting up the model more cleverly?
An initial idea I had:
Exploiting sufficient statistics. Since there is only identity link and Gaussian error, is this a way to go here - even though other aspects of the model are rather complex? Are there examples of how to set up such a model (I guess, only based on means and SE by strata?) in brms
?