Hi everyone,
I’m trying to set up my first non-linear hierarchical model with the help of brms, but I’m not sure I’m doing it right. I would be grateful if anyone could point me in the right direction!
Data:
Study participants (“id”) had to give repeated estimates (“estimate”) about positions on a ruler ranging from 0-18’278. The actual positions are coded as “actual”. Dataset (dropbox link).
Plot:
Individual estimates are more or less logarithmic.
Analysis:
I want to fit a non-linear model to this to determine the best fitting base of the logarithmic function. I did this as follows (pooled model):
data <- read.csv("sz_data_brms.csv")
prior1 <- prior(normal(1,2), class="b", nlpar = "b1", lb=1)
fit1 <- brm(bf(estimate ~ log(actual)/log(b1), b1 ~ 1, nl = TRUE), data = data, prior = prior1)
print(fit1,5)
I set a lower bound (>1) to the prior of b1 to avoid negative values. As stan does not have a logarithmic function with freely specifiable base, I implemented it as log(x)/log(b) which equals log_b(x).
This worked fine (no fitting problems and reasonable estimate).
Now, I would like to allow the base of the logarithm to vary between participants. I set up the model like this:
prior2 <- prior(normal(1,2), class="b", nlpar = "b1", lb=1)
fit2 <- brm(bf(estimate ~ log(actual)/log(b1), b1 ~ 1 + (1|id), nl = TRUE), data = data, prior = prior2)
print(fit2,5)
However, this model arrives at an unreasonable estimate, has problems with the effective sample size, convergence and divergent transitions and takes a long time to fit, indicating that there is something substantially wrong with it.
I’m sure I did something wrong and I tried to look up the model specification for non-linear models with bf() here, but I could not figure out where the error lies exactly. Would be thankful for any pointers!
Thanks,
Yvonne