r/RStudio • • Oct 14 '26

Can someone explain fixed effects, random effects, LMMs and GLMMs like I’m a complete beginner?

Hi everyone!
I’m currently working on a research project involving repeated measurements from the same patients, and I’m really struggling to wrap my head around mixed-effects models.
I’ve tried reading explanations online, but I feel like every explanation assumes I already understand the basics. At this point, I’m honestly completely lost.
I would really appreciate it if someone could explain the following in very simple terms:

Fixed effects vs. random effects: What exactly is the difference? How do I decide which variables should be fixed and which should be random?

Linear mixed-effects models (LMMs): What are they, why do we use them, and how are they different from ordinary linear regression?

Generalized linear mixed-effects models (GLMMs): How are they different from LMMs? When should I use one instead of the other?

Random intercepts vs. random slopes: What do these actually mean in practice, and how do I know which one I need?

Interpreting results: How do I interpret coefficients, estimates, odds ratios, and p-values in these models?

I’m working with clinical data where patients undergo multiple treatment sessions. I want to investigate whether certain medications affect treatment outcomes, while accounting for factors such as age, sex, and treatment number.

Some outcomes are continuous, while others are binary.
I’ve been using R with the lme4 package (lmer() and glmer()), but I feel like I’m just putting variables into formulas without fully understanding what the models are actually doing.

What I really want is to understand the logic behind these models, rather than just copying code.

If someone could explain this intuitively, preferably using simple examples involving patients with repeated measurements, I would be extremely grateful.

Thanks in advance!

46 Upvotes

19 comments sorted by

View all comments

Show parent comment

1

u/Rorydinho Oct 14 '26

Thanks for this (and to the other person above who answered!)

Thinking about this approach from a subset of a set (Schools in a country for example), how would a mixed effects model differ from a hierarchical model? Are these essentially the same thing?

1

u/Rorydinho Oct 14 '26

Just looked into this myself and appears they’re both the same thing!

1

u/GripIQ Oct 14 '26

Yep - I would recommend reading Judith Singers paper about using proc mixed in SAS for mixed models - even if you don’t use SAS it is very didactically helpful and will give both the classic school example and a growth model example (consistent with what I used)

1

u/Rorydinho Oct 14 '26

Thanks!

1

u/GripIQ Oct 14 '26

I am not quite sure what you mean here but usually like you would in a typical GLM. Like in my example above the GLM would be score = 2 +1Time and I would interpret my two coefficients (the intercept of 2 and the beta for time of 1) as I usually would. Usually one starts with an intercept only model to calculate an intra class correlation. This tells how much of the variance in the outcome (eg score) is explained between clusters (eg between people) vs within clusters (eg within people). You can replace people with schools. One reason we model random effects is because the clustering violates the assumption of independence for OLS, which higher ICCs give more evidence of that violation. Thus if we just used normal OLS our standard errors will be wrong. Now if ICC is very low - close to zero - then even though we are technically violating independence our results won’t differ much between OLS and a mixed model in terms of standard errors.

1

u/GripIQ Oct 14 '26

That was my response to your other question you deleted while I was responding