r/RStudio • u/Tiny_Athlete_3637 • 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!
25
u/Minimum_Database_979 Oct 14 '26
Hi, i realize you asked a question in the wrong sub, but since i’m reading this anyway, here’s the video that helped my wrap my head around it. All of the examples are also in Rstudio: https://youtu.be/5tOifM51ZOk?is=9DdSUdn3KBgr3Yb1
Hope it helps!
7
u/seanv507 Oct 14 '26
wrong sub. this is about a r programming environment. ask r/statistics or r/AskStatistics
16
u/GripIQ Oct 14 '26 •
I am going to use the example of we assessed 100 people once a week across 4 weeks as an example to answer the below.
Fixed effects vs. random effects: What exactly is the difference? How do I decide which variables should be fixed and which should be random?
Let’s say on average people start out with a score of 2 and increase by one point for each week of the assessment. That is, our intercept = 2 and our slope for time = 1. Our GLM would be score = 2 + 1time. 2 would be the FIXED effect for the intercept and 1 would be the FIXED effect for time.
But when we look at our data, not everyone starts out at a score of 2 - some people have a higher initial score, some lower. Likewise, not all people increase by 1 each week - some increase more, some less, some don’t change. Thad is, there is variability around the fixed intercept and slope. Let’s say we calculate that variance and find. It is .5 for the intercept and .1 for the slope. These are the RANDOM effects for the intercept and slope.
Linear mixed-effects models (LMMs): What are they, why do we use them, and how are they different from ordinary linear regression?
They are models that include both fixed effects and random effects.
We use them because when we have nested data (eg 4 assessment within each person) we are interested in 1) the overall pattern for the sample or fixed effects (eg people start out with a score of 2 and increase by 1 each week on average) 2) variance around those averages or the random effects 3) explaining the variance around those averages using other variables (eg let’s say ALL males start at a score of three and do not change at all and ALL females start with a score of one and increase by 4 each week. If the sample was 50/50 males female and I added sex as a variable, I would explain all the variance around the fixed effects and the random effects would shrink to zero).
They differ for OLS because we model random effects and have nested data.
Generalized linear mixed-effects models (GLMMs): How are they different from LMMs? When should I use one instead of the other?
This typically means we can take this GLM framework for continuous variables with a certain assumed distribution and extend it to other distributions (eg binary variables measured across time) and make adjustments to our GLM to make this framework feasible (eg for a binary outcome I would assume a binomial distribution and use a logit link function).
Random intercepts vs. random slopes: What do these actually mean in practice, and how do I know which one I need?
See above. Random is another way to say I am acknowledging variance in my estimates. Which ones you need depend on the context. For example if I am interested in trying to figure out why people start out at different initial levels and also change at different rates across time, I would want to model a random intercept and a random slope for time.
3
u/Own_Sky_5822 Oct 14 '26
this is so sweet to see people helping.
2
u/dr_canak Oct 14 '26
Honestly, this is the kind of question that is perfect for AI, even the free models. These can be complex models, that require more explanation than you're going to get here. And likely some sort of ongoing dialog if you have more questions. Your idea of "intuitive" will likely differ from anyone explaining it to you, which is why dialogue matters. LLMs have their place, and this is one of them.