17
$\begingroup$

I am analyzing data on "BloodSugar" level (dependent variable) and trying to find its relation with "age", "gender" and "weight" (independent variables) of subjects. I have data collected from subjects sampled in four "city".

Should I use "city" variable as fixed effect or a random effect?

So which is correct:

lm(bloodsugar ~ age + gender + weight + city, mydata)

or:

lmer(bloodsugar ~ age + gender + weight + (1|city), mydata)

Thanks for your help.

Edit: In response to comment by @Dave , I would like to add following: Currently there is no data on relation between my real dependent variable and City. So, relation could be there. Relation with City is not my primary objective but it will be nice to determine that relation also, if it is feasible by proper statistical methods.

$\endgroup$
2
  • 4
    $\begingroup$ Are you interested in those four cities in particular? Say you’ve sampled from New York, Nairobi, Buenos Aires, and Jakarta...would you be interested in subjects from London? $\endgroup$
    – Dave
    Commented Jul 11, 2020 at 3:28
  • $\begingroup$ Currently there is no data on relation between my real dependent variable and City. So, relation could be there. Relation with City is not my primary objective but it will be nice to determine that relation also, if it is feasible by proper statistical methods. $\endgroup$
    – rnso
    Commented Jul 11, 2020 at 17:46

3 Answers 3

17
$\begingroup$

I would advise fitting both. Hopefully they will tell you the same thing. If not, that would be very interesting!

Conceptually, city should be random. You are not specifically interested in estimates for each city for you research question and your sample of cities can be thought of as coming from a wider population of cities. These are good reasons to treat it as random.

The problem is you only have 4 of them so you are asking the software to estimate a variance for a normally distributed variable with only 4 samples so that may not be very reliable.

It is perfectly valid to fit fixed effects and this will control for the non independence within each city. In that case you are treating it a bit like a confounder. The reason for using random intercepts is that with many cities this becomes inconvenient and loses statistical power.

So with only 4, I would do both.

$\endgroup$
1
  • 2
    $\begingroup$ +1 Perfect answer. Logically, a random effect, but the ideal number of categories for a random effect would be something more like 15+ so you can get an reasonable distribution. $\endgroup$
    – Wayne
    Commented Jul 11, 2020 at 19:23
7
$\begingroup$

Robert Long already gave a nice answer, but let me add my three cents. As already noticed by Dave in the comment, when fitting fixed effects models you are asking the question what are the differences between those particular cities, while with random effects model you ask what is the variability between cities. Those are quite different questions to ask.

If you are interested in more in-depth discussion of differences between both types of models, you can check my answer in the Fixed effect vs random effect when all possibilities are included in a mixed effects model thread. It's a different question, but the answer discusses the kind of issues that are closely related to questions as yours.

$\endgroup$
3
  • 1
    $\begingroup$ I am not clear about how these questions differ: "What are the differences between those particular cities?" and "What is the variability between cities?" $\endgroup$
    – rnso
    Commented Jul 11, 2020 at 18:13
  • 1
    $\begingroup$ @rnso in second case you are using those cities to learn how much it can vary (variance) between cities in general, where you threat those as a sample of possible cities. With fixed cities, you have means for cities A, B, C, & D, but can't really say anything about city D that was not present in the data. With random effects, you assume the cities to represent outcomes from same random variable, so you can make guesses what could be the effects for other, potential cities. $\endgroup$
    – Tim
    Commented Jul 11, 2020 at 19:31
  • 2
    $\begingroup$ @rnso this is an important point and it is worth trying to fully understand it. The question Tim links to is indeed a very good one with lots of different opinions and detailed discussions. It illustrates very well why the fixed vs random question is not always as straightforward as my answer to your question here suggests. Tim, (+1) thanks for reminding me about that one, it is indeed a great resource for everyone! $\endgroup$ Commented Jul 12, 2020 at 3:04
7
$\begingroup$

One further remark: If you assume that the city variable might be correlated with the other independent variables (and the blood sugar level), you need to model cities as fixed-effects because it would violate the assumption of independence of the random effects.

An example might be if one city is in Florida where older people with higher blood sugar levels tend to cluster due to the milder winter.

$\endgroup$
2
  • 2
    $\begingroup$ Sounds like a very important point to me while making this decision. Thanks. $\endgroup$
    – rnso
    Commented Jul 11, 2020 at 18:42
  • 2
    $\begingroup$ This is true, however mixed models are surprisingly robust to even excessive correlations between random (grouping variables) and fixed effects. $\endgroup$ Commented Sep 4, 2020 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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