For testing purposes, I would like to fix a nonlinear parameter in a brms
model to a specific value. I had thought this was as simple as using par = val
instead of par ~ <formula>
, but this throws an error in brms
2.9.0. Sorry in advance if I’ve missed this somewhere in the docs.
Here’s a minimal example using code from the vignette:
b <- c(2, 0.75)
x <- rnorm(100)
y <- rnorm(100, mean = b[1] * exp(b[2] * x))
dat1 <- data.frame(x, y)
f <- bf(y ~ b1 * exp(b2 * x),
b1 = 0.5,
b2 ~ 1,
nl = TRUE)
get_prior(f, data = dat1)
Error: Invalid fixed parameters: 'b1'
Please also provide the following information in addition to your question:
- Operating System: OSX
- brms Version: 2.9.0
I don’t think this is possible yet. As far as I know, the only workaround at the moment is to set a very strong prior on the parameter that corresponds to the value you want to fix your parameter to.
Not sure if it’s possible, but perhaps you could do the following instead:
f <- bf(y ~ exp(b2 * x)/2,
b2 ~ 1,
nl = TRUE)
or
f <- bf(y ~ 0.5 * exp(b2 * x),
b2 ~ 1,
nl = TRUE)
Does that work?
Looks like a feature to implement :-)
2 Likes
Can you open an issue on github?
Thanks for the replies! This would be a very useful feature.
Jack: thanks for the suggestion, but I was more using that model as a demonstration – for more complex models the workaround won’t work.
1 Like
I was just searching for how to set constant parameters in brms and came across this thread. This is officially a feature now (@paul.buerkner added it in like January 2020 or something). Search for “Fixing parameters to constants is possible by using the constant function” in the brms docs.
Also here: https://github.com/paul-buerkner/brms/issues/734