Hi all.
I’m trying to fit multilevel wave models for my research in brms. I’ve beens struggling to get the models to converge on my actual data, so I’ve moved to working with simple simulated examples to try and figure out what might be causing the problem. It seems like the frequency parameter in particular might be causing some issues. I’ve found that even in a simple simulated setting where the only parameter that varies is frequency, the model doesn’t seem to converge. I struggle to get convergence even in situations where I set fairly strong priors on the parameter values that I used to generate the data.
Here’s the sample code:
library("brms")
library("tidyr")
library("tibble")
library("dplyr")
start = Sys.time()
# Generate Wave Params
df_params = tibble(
ID = seq(1,100),
amp = 0.2,
freq = rnorm(100, 1/7, 0.05),
phase = 0,
)
# Generate Data
n = 2000
sd = 0.1
set.seed(1)
df_sim_data = expand_grid(ID = seq(1,100),
time = seq(1,20)) %>%
left_join(df_params,
by = c("ID")) %>%
mutate(epsilon = rnorm(2000,sd=sd),
affect = amp*cos(2*pi*freq*time + phase) + epsilon)
# Fit Model
df_to_fit = df_sim_data %>%
select(ID, time, affect, amp, phase) %>%
mutate(pi = pi)
model_spec = brmsformula(affect ~ amp*cos(2*pi*freq*time + phase),
freq ~ 1 + (1|ID),
nl = TRUE)
model = brm(model_spec,
df_to_fit,
prior = c(prior(normal(0.142857, 0.01), nlpar="freq"),
prior(normal(0.05, 0.01), nlpar="freq", group="ID", class="sd"),
prior(normal(0.1, 0.01), class="sigma")),
iter = 20000,
cores = 4,
file = "regression/freq_fit")
print(Sys.time() - start)
I’ve tried running this up to 80000 iterations, and I’ve also tried a few different priors. The ones included here are the strongest ones i’ve given, but I’ve also tried a uniform prior on the interval [0.05, 0.5] for the frequency intercept, thinking that’s the range of unique frequencies that are possible
Here’s the model summary output from the run above:

And here’s the trace plot:
I’d love guidance what might be the problem and how to address it. Happy to provide more information too if it would be helpful!
Thanks for your help.
Ari





