AR() model in brms: how to speed it up and for unbalanced panel structure?

Hi,

  1. I am adding in an AR() structure into my brms multilevel model. It increases run time by around 50%. Any way to get around this? My data is non-nested and structured as firms across time, within countries. I have around 280,000 data points across 24 years and 24 countries. The panel is not balanced so some years are missing for most firms. This is the code I added for the AR() structure.

autocor = cor_ar(form = ~ year | firm_identifier , p = 1)

  1. Also note that it is not accounting for the country structure of the data --unsure how best to do that. Nor is it accounting for the fact that the panel is not balanced. Suggestions would be appreciated.

And just to add, in case this is relevant, this multilevel model is estimating fixed effects and group-level random effects at the following levels: year, country, and year:country.…which may be slowing down the AR() process even more?

Many thanks,

  1. I am surprised it does not add more than 50%. I tried to write AR structures as efficiently as possible but I am open to suggestions how to improve the speed further.

  2. If the same firm only exists in a single country, than you don’t need to include country in the AR structure. If, however, the same firm (identifier) exists in multiple countries you should go for something as

autocor = cor_ar(form = ~ year | country:firm_identifier , p = 1)

to make sure the autocorrelation only applies to observations of a firm within a specific country.

2 Likes

This is helpful. Many thanks!

And just to check something (sorry!): is it still the case that:

``I also changed the prior of the AR effect, as beta priors restrict the parameter to [0,1], but autocorrelations may be between [-1,1] or even lie outside this interval if the process is not stationary.‘’

Or is stationarity instead imposed now? Since I couldn’t find this beta prior in the code but I did notice from the Stan code from my brms() model that:

vector<lower=-1,upper=1>[Kar] ar;  // autoregressive effects

Many thanks,

Ilan

A lot of what I wrote in the thread you are pointing to is not up to date anymore.

There are two formulations of ARMA models in brms (controlled by argument cov in cor_arma and related functions). The default ARMA method does not require stationarity to work and as of the current github version of brms, stationarity is no longer enforced.

OK great. Thanks for the update. And what is the main difference between the cov = TRUE and ignoring the cov option?

I have discussed this in some github issue (or discourse thread) but I can’t find it right now. Perhaps you are more lucky than me…

Damn. Can’t find it. But will look further next week.