I’m trying to create a simple linear model with a random intercept and slope, *edit in the brms package in R. This works just fine, but I noticed that my group slope/intercept parameters have almost equivalent estimated error, which as I understand it is by design. Reading the documentation, if I follow, using the gr() by parameter can allow for the modeling of separate variance.
Here is my original formula:
y ~ 1 + x + (1 + x|group)
Which I tried to alter to:
y ~ 1 + x + (1 + x|gr(group, by=x)
This throws an error
Error: Some levels of 'x' correspond to multiple levels of 'group'.
I can try to re-create this with some toy data and post it here, but my sense is that I’ve simply misunderstood the syntax. Any insight would be appreciated.
An optional factor variable, specifying sub-populations of the groups. For each level of the by variable, a separate variance-covariance matrix will be fitted. Levels of the grouping factor must be nested in levels of the by variable.
So I think the problem with x|gr(group, by=x) is the nesting. You need each level of x to correspond to a single level of group.
Thanks for the response. This adjustment throws the same error. Maybe it was unclear, but in this model x is a continuous float predictor and group is a categorical. Is using gr() to estimate separate variances for x amongst each level of group for both slope and intercept parameters the correct approach in that situation?