How can run 2 separate regression models with lmer using only one formula?

Viewed 38

Consider, "y" as the dependent variable and "x1" and "x2" as the independent variables. Consider two categorical variables "GROUPING" and "REGION" with 2 levels each. Consider data_model with all the variables.

Consider 2 lmer models,

data_model_R1 = subset(data_model, REGION=='R1')
formula_R1 = "y ~ 1 + x1 + x2 + (1 + x1 | GROUPING) + (1 + x2 | GROUPING)"
model_R1 = lmer(formula_R1 , data_model_R1)

data_model_R2 = subset(data_model, REGION=='R2')
formula_R2 = "y ~ 1 + x1 + x2 + (1 + x1 | GROUPING) + (1 + x2 | GROUPING)"
model_R2 = lmer(formula_R2 , data_model_R2)

How can I create an equivalent "model" with one formula to get all the coefficients generated in "model_R1" and "model_R2"? Something like,

model = lmer(formula, data_model)
1 Answers

How can I create an equivalent "model" with one formula to get all the coefficients generated in "model_R1" and "model_R2"

You can't really do exactly that. You are splitting the data for each model according to the values of the REGION variable. People typically do this when they expect associations between the predictors and the response to vary, depending on the value of another variable (REGION in this case). However, this is usually a bad idea because it leads to a big loss in statistical power. Instead, a better idea is to fit the interaction between the other variable and whichever variable(s) are expected to have a different association with the response. For example, if we wanted to allow the assocation between x2 and y to vary depending on the value of REGION we would fit:

y ~ 1 + x1 + x2*REGION + (1 + x1 | GROUPING) + (1 + x2 | GROUPING)
Related