8

I was wondering why m below is a legitimate model? If it is, what is the meaning of its random part?

ses is a level-1 predictor and sector a level-2 predictor making their combinations a cross-level interaction.

In other words, I'm asking how a cross-level interaction can be taken to be random in a 2-level model?

UPDATE: How about model mm with sector in the random part?

library(lme4)

hsb <- read.csv('https://raw.githubusercontent.com/rnorouzian/e/master/hsb.csv')

m <- lmer(math ~ ses*sector + (ses:sector | sch.id), data = hsb)

mm <- lmer(math ~ ses+sector + (sector | sch.id), data = hsb) #UPDATE

chl
  • 53,725
rnorouzian
  • 3,986

1 Answers1

9

It's important to remember that an interaction is the product of the two variables.

For example if we have

sch.id  ses  sector
1        1     1
1        2     1
2        3     2
2        4     2

..then the interaction for ses:sector will be:

sch.id  ses  sector  ses:sector
1        1     1        1
1        2     1        2
2        3     2        6
2        4     2        8

So, although sector does not vary with sch.id, the interaction that includes it does, because the other variable, ses, does vary within school.

As such, there is no technical reason why random slopes for such an interaction cannot be included - however it would be odd to fit the first model in the OP - that is, a model with random slopes only for the interaction, since it is impossible to vary an interaction independently of both main effects - so a more appropriate model (provided it is supported by the data) is:

math ~ ses*sector + (ses + ses:sector | sch.id)
Robert Long
  • 60,630
  • 2
    You can try to estimate that model, but it doesn't make much sense as Rob nicely showed in the answer to your previous question - https://stats.stackexchange.com/questions/490919/visualizing-the-folly-of-fitting-random-slopes-for-variables-that-dont-vary-wit – Erik Ruzek Oct 08 '20 at 15:05
  • Yes, that model would not make sense due to the presence sector in the random slopes part. – Robert Long Oct 08 '20 at 15:33