Search code examples
rlme4mixed-modelsrandom-effectsrstanarm

Formula difference specifying random effects on slope rstanarm


I believe the same syntax is used with the lme4 package as rstanarm, but I'm having trouble figuring out exactly what the differences are between the different options when fitting a grouped random effect on the slope.

Say we have a model with formula

response ~ fixed + (1 + rand1 | group)

What exactly is the differences in assumptions between that and these three other options:

1:

response ~ fixed + (0 + rand1 | group)

2:

response ~ fixed + (-1 + rand1 | group)

3:

response ~ fixed + (1 + rand1 || group)

I know that here one answer mentioned that the || formula assumes the covariance matrix among the deviations in the parameters by level of group is diagonal, but it's not clear to me how assumptions about the covariance matrix change between that and say the 1st and 2nd options.


Solution

  • Options 1 and 2 should give identical results: from ?formula

    The ‘-’ operator removes the specified terms ... It can also used to remove the intercept term: when fitting a linear model ‘y ~ x - 1’ specifies a line through the origin. A model with no intercept can be also specified as ‘y ~ x + 0’ or ‘y ~ 0 + x’

    (it is true, but not obvious, that this specification applies here).

    if rand1 is categorical (i.e., a factor)

    Because (rand1|group) and (e.g.) (0+rand1|group) both specify a general positive-definite covariance matrix ("unstructured"), you should get the same overall model fit in both cases (barring effects of the prior). The difference is in the meaning of the individual elements of the covariance matrix. With (rand1|group), lme4 sets up the standard treatment contrasts, so that the first row/column of the covariance matrix corresponds to the variance of the intercept (value of the baseline level) across groups; subsequent rows/columns correspond to variances in differences between the baseline level and levels 2, 3, ... n. With (0+rand1|group), the rows/columns are variances of the measured value in the corresponding group.

    if rand1 is continuous

    This case works differently; here rand1 | group gives a random effect of length 2 ({intercept, slope}) with a 2x2 covariance matrix; suppressing the intercept with +0 or -1 will produce a scalar-random-effect model that assumes the intercept is constant across groups but the slope varies (i.e., a single parameter estimate describing the among-group variance in the slope).