Advice on a Multilevel Time Series Model

169 views
Skip to first unread message

Jon Fawcett

unread,
Apr 8, 2018, 11:50:54 PM4/8/18
to brms-users
Hey There!

I am trying to fit a multilevel time series model to some physiological data I have from a psychological experiment. Specifically, in this experiment 36 participants completed a cognitive task, which involved 30 trials for each of 3 conditions. For each trial, I have a time series with approximately 200 time points reflecting physiological arousal throughout the trial. This means I have 36 x 30 x 3 x 200 data points (minus some missing data points) that I would like to model hierarchically as a function of condition while treating subject as a random effect. My first thought was to fit some sort of Gaussian Process – but if I even try to do that, R crashes (I suspect it runs out of RAM). I was hoping to get some advice on other, perhaps more economical Bayesian approaches to this sort of modelling problem. I have just now moved on to splines (I have a model running as we speak – but it is moving very, very slowly) using the following code:

brm(formula = y ~ condition + s(time, by = condition) + (1 | id), 
    data = dat,
    family = gaussian(),
    chains = 4,
    cores = 4,
    iter = 2000) -> bm1

Most of these variables should be self-explanatory, but to be clear, y is my physiological measure and id is a unique identifier denoting my participants. Any advice would be appreciated. In particular, it strikes me that this initial model assumes implicitly that all participants share the same waveform (since the smooth term varies only by condition, not id). I anticipate that the wave form itself could vary in subtle ways from subject to subject, but I am not sure how to incorporate this into the model. One step at a time!

In case it matters, I am running this on a fairly recent, upgraded MacBook Pro. I have been fitting models using Stan for a few years now without issue.

Cheers!
Jon

Paul Buerkner

unread,
Apr 11, 2018, 8:45:45 AM4/11/18
to Jon Fawcett, brms-users
Did the model converge well?

If you want to fit a separate spline per id x condition, add

dat$id_condition <- paste0(dat$id, "_", dat$condition)

and then go for

y ~ condition + s(time, by = id_condition) + (1 | id)

The drawback is that you won't immediately get "average" splines across IDs.

--
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/6d890b6c-2ff6-4deb-9869-ee9fdc69d390%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jon Fawcett

unread,
Apr 12, 2018, 2:13:44 PM4/12/18
to brms-users
Thanks for the reply, Paul!
I do not know how well it converged yet. I had to cancel the earlier run because I needed to shut down my computer for an unrelated reason. I restarted sampling once I saw your post, but it has been running for over 24 hours and is not even 30% complete (with 4 chains of 1000 iterations each – I lowered the iterations from 2000 anticipating this issue). I suppose it could be that there is simply too much data for this statistical approach to be feasible given the available resources. I am guessing from your earlier message that there are no easy tips or tricks to speed things up – beyond further downsampling. Before I try that – or adopt a non-Bayesian model – do you have any suggestions with respect to other ways in which BRMS could model a multilevel time series that might be faster?

Beyond that, thanks for such a great package!

Cheers!
Jon

Paul Buerkner

unread,
Apr 12, 2018, 4:40:05 PM4/12/18
to Jon Fawcett, brms-users
not if you are interested in the shape of the relationship. maybe you should get a better computer or cluster somewhere.

--
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+...@googlegroups.com.

To post to this group, send email to brms-...@googlegroups.com.

Paul Buerkner

unread,
Apr 12, 2018, 4:41:12 PM4/12/18
to Jon Fawcett, brms-users
and you can run chains in parallel using the cores argument.
Reply all
Reply to author
Forward
0 new messages