Hi,
I’m fitting a non-linear model with brms, where I am interested in estimating the effects of a treatment on the variation of some data, which has a sigmoid form. I have had success so far with something like this, where y is the variable I’m hoping to predict, t is time, and treatment is a categorical variable with three levels.
formula <- (
bf(y ~ shift + scale * inv_logit(slope * (t - offset))
, sigma ~ 1 + t:treatment
, family = brmsfamily("gaussian", link='identity', link_sigma="identity")
, nl=TRUE
)
+ lf(offset ~ 1, slope ~ 1, scale ~ 1, shift ~ 1)
)
I’d now like to also see if I can also use treatment in estimating the variation of some of the non-linear parameters. Essentially, I am curious if the change in variation of treatment can be apportioned to specific non-linear parameters varying less, or if it simply reduces the residual variation.
However, when I try something like this:
formula <- (
bf(y ~ shift + scale * inv_logit(slope * (t - offset))
, sigma ~ 1 + t:treatment
, family = brmsfamily("gaussian", link='identity', link_sigma="identity")
, nl=TRUE
)
+ lf(slope ~ 1, sigma ~ treatment)
+ lf(offset ~ 1, scale ~ 1, shift ~ 1)
)
I get the output “Replacing initial definitions of parameters ‘sigma’”.
How do I also model the non-linear parameter “slope” with a distribution where I can predict the parameters?
One idea I had was to explicitly code slope as a latent variable, and provide a column full of NaNs when fitting the model:
formula <- (
bf(y ~ shift + scale * inv_logit(mi(slope) * (t - offset))
, sigma ~ 1 + t:treatment
, family = brmsfamily("gaussian", link='identity', link_sigma="identity")
, nl=TRUE
)
+ bf(slope | mi() ~ 1, sigma ~ treatment)
+ lf(offset ~ 1, scale ~ 1, shift ~ 1, resp="y")
)
This seems to produce the right model structure. However, I wanted to check if this is in fact the way to go about this and that I’m not introducing any errors here? In particular, down the line I’d actually like to fit a multivariate model, and if I wanted to take the same approach for two outcome variables I’d need to add separate latent variables for them - which is pretty daunting when I think about it 😅
Are there any other ways of achieving this that keep the complexity low?
EDIT: After attempting to make the latent variable approach work, I don’t actually think it works, as the missing variable operator doesn’t seem to work in non-linear formulas.
R version 4.0.2 (2020-06-22)
brms_2.16.1