My dataset contains variables of two levels, say individuals and regions. Each level has features. Note that the level2 features are repeated within each level2_ID.
example_data <- data.frame(level1_ID = c(1, 2, 3, 4, 5),
level1_depend = c(17, 32, 27, 30, 31),
level1_feat1 = c(21, 45, 25, 34, 32),
level1_feat2 = c(32, 67, 35, 41, 43),
level2_ID = c(1, 1, 2, 2, 2),
level2_feat1 = c(27, 27, 32, 32, 32),
level2_feat2 = c(11, 11, 14, 14, 14))
I would like to add the features of level2 as predictors in the model as well. Adding them as blocks in the model like this:
lmer(level1_depend ~ level1_feat1 + level1_feat2 + (level2_feat1 | level2_ID),
data = example_data)
seems not to be right, because the level2 features are constant in each level2_ID value. How do I add the level2 features appropriate?
Thanks for helping!