5
$\begingroup$

I am working with mixed effects models and I am still a bit confused.

While I have read multiple explanations of what the differences between nested and crossed random effects are, I am not sure how to apply them to my data. I have read the following explanation already: Crossed vs nested random effects: how do they differ and how are they specified correctly in lme4?

My dataset is about people living in different cities. Thus, I have multiple nationalities as one variable (nationality of the person living in a city) and cities as another variable (the city the person lives in). What I want to see with my model is whether nationalities differ overall and whether they also differ between each city (e.g. whether someone with the nationality "Japan" living in San Francisco is different in terms of my dependent variable when compared to other Japanese that live somewhere else).

To answer this question, I thought about using a nested model, but I am not sure whether this is possible in my scenario. What is confusing to me is the example about class rooms and schools as described in the link above. While I understand that one class is part of only one school (nested), I am not sure whether this can also be said for nationalities. Especially in regards to the following: In my dataset, one and the same individual can only be observed in one city but the overall nationality factor can be observed in multiple cities. In other words: Person A134 lives in San Francisco and is Japanese. However, he is not the only Japanese person and I have Japanese people living in Tokyo, but also living in, London and other cities)

Would it still be possible to use a nested model or is it an issue that the nationality "Japan" appears across all cities? If not, I am not sure how else to answer my question.

The nested random effect I thought of would look like:

lmer(dependent_variable ~ variable1 + variable2 + (1|nationality/city), data=data)

Furthermore, what would the difference in interpretation be if the following model was used? What would change in terms of interpretation?

lmer(dependent_variable ~ variable1 + variable2 + (1|nationality) * (1|city), data=data)

EDIT: I am not sure, but maybe the following is what I am looking for? How does it differ from the two above?:

lmer(dependent_variable ~ variable1 + variable2 + (1|nationality:city), data=data)
$\endgroup$
  • $\begingroup$ You can allow for interaction between city and nationality. $\endgroup$ – cbeleites unhappy with SX Jul 1 at 14:13
  • $\begingroup$ Hi @cbeleitesunhappywithSX! Thanks for your quick comment! Not sure, but this would also mean that neither of them can be used as a random effect, correct? $\endgroup$ – lole_emily Jul 1 at 14:16
  • $\begingroup$ @cbeleitesunhappywithSX I think I got what you mean! If I understand correctly, you were suggesting to opt for lmer(dependent_variable ~ variable 1 + variable 2 + (1|city)*(1|nationality)? $\endgroup$ – lole_emily Jul 1 at 14:54
  • $\begingroup$ I don't think that is what they meant. It sounds like you may have crossed factors for nationality and city, however you seem to be interested in fixed effects, not random effects. What is the size of your dataset ? How many persons, nationalities and cities ? $\endgroup$ – Robert Long Jul 1 at 15:21
  • $\begingroup$ Hey @RobertLong! Thanks for replying! I am interested in the random effects between nationalities and also cities. Also, I expect that the same nationality might have different effects and also that they might be different between cities in terms of my dependent variable. My Dataset is very large (~100.000 persons, 120 nationalities, 10 cities) $\endgroup$ – lole_emily Jul 1 at 16:16
4
$\begingroup$

Each person is measured (observed) once.

Person's belong to only one city - that is they are nested in city.

Person's belong to only one nationality - that is, they are nested in nationality.

There is no nesting of nationality in city or vice versa. Hence City and Nationality are crossed factors.

So in a mixed model setting you could fit:

lmer(dependent_variable ~ variable1 + variable2 + (1|nationality) + (1|city), data=data)

However, this will not answer your research question:

What I want to see with my model is whether nationalities differ overall and whether they also differ between each city (e.g. whether someone with the nationality "Japan" living in San Francisco is different in terms of my dependent variable when compared to other Japanese that live somewhere else).

To answer this the most obvious approach is to fit interactions for city and nationality as fixed effects

lm(dependent_variable ~ variable1 + variable2 + nationality*city, data=data)

and this would not be a mixed model. The problem with this is that for many cities and nationalities you are going to have a lot of interation terms.

Finally there is a bit of confusion in your question. You also posit these models:

> lmer(dependent_variable ~ variable1 + variable2 + (1|nationality/city), data=data)

This model says that city is nested in nationality and the software will fit random intercepts for nationality and the nationality:city interaction.

> lmer(dependent_variable ~ variable1 + variable2 + (1|nationality:city), data=data)

This model says that you are fitting random intercepts for the nationality:city only and that is rarely what is warranted.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ hey @RobertLong - thank you very much again for your reply! Ah, i think I'm getting closer to understanding it. In terms of your suggestion with fixed effects: I have 120 nationalities and 10 cities - I think that would make the lm-output too large. Also, I do not just want to see whether the city*nationality makes an impact but also in terms of the other variables in the model (variable1, variable2). Variable1 for example is "income". Hence, why I thought of "random effects". Could you also please explain why the last model with nationality:city is rarely warrented? Thank you! $\endgroup$ – lole_emily Jul 1 at 16:21
  • $\begingroup$ @lole_emily the last model fits random intercepts ony for unique combinations of nationality and city, which implies that repeated measures or nesting only occurs in those combinations, and not in nationality or city seperately. $\endgroup$ – Robert Long Jul 1 at 16:58
  • $\begingroup$ @lole_emily I think you might need to ask a new question about how to handle interactions between two or more categorical variables with a large number of levels each when you are specificlly interested in the estimates for the individual levels/contrasts. I dont think you can answer that with those variables as random effects...I have answered the question asked in the title about crossed or nested random effects, but that question is not your actual research question. I think you will get better responses by asking a new question about that $\endgroup$ – Robert Long Jul 1 at 17:01
  • 1
    $\begingroup$ great, thank you! I have accepted your answer! Just one more question, if you don't mind - regarding the unique combinations fit of nationality and city: You said that it implies that nesting only occurs in those combinations. Not sure, maybe I am misunderstanding something, but since each person is only nested in one city/nationality combination (Person A123 is only Japanese as nationality and only lives in San Francisco and nowhere else) - isn't this something I could go for in my model? Thank you! $\endgroup$ – lole_emily Jul 1 at 18:32
  • $\begingroup$ @lole_emily I don't think so because all that you will get from the model output, apart from the fixed effects, is the variance of that random intercept (which will be assumed to be normally distributed). You don't get estimates for all the individual levels/combinations. You can extract all the random effects, but you can't do any tests on them so I don't see how that will answer your question. But it's an interesting idea - you could suggest that as one idea you had when you write the new question. Also, feel free to ping me in this thread so I can take a look at the new question. $\endgroup$ – Robert Long Jul 1 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.