r/AskStatistics • • 1d ago

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

/r/RStudio/comments/1x5nbef/can_someone_explain_fixed_effects_random_effects/
16 Upvotes

9 comments sorted by

13

u/SalvatoreEggplant 1d ago

In your scenario --- presumably ---, medications would be a fixed effect.  You care about ibuprofen specifically and aspirin specifically.

Age and Sex are presumably fixed effects.  You are interested in the effect of male and female specifically. You are interested in the effect of specific age of the patient.

Patients would likely be a random effect.  One reason is that treating it this way takes into account the repeated-measures nature of the experimental design.  But also, you don’t care about each patient specifically. If you were assigned a different group of patients, you would be just as happy.  You’re not like, “John specifically reacted well to ibuprofen, but Betty reacted well to aspirin”.

In contrast, if all the men reacted well to ibuprofen and all the women reacted well to aspirin, you want to know that!  That’s why sex is a fixed effect in your model.

8

u/DigThatData 1d ago

I've always found the fixed/mixed/random effects language confusing myself, and strongly prefer the "hierarchical" language bayesian modeling generally prefers. A great book for explaining this stuff (which also prefers this latter language) is Andrew Gelman - Data Analysis Using Regression and Multilevel/Hierarchical Models

2

u/SometimesZero 10h ago

Gelman to the rescue again. He kicks ass.

2

u/DigThatData 5h ago

ikr? everything he touches is straight gold.

12

u/SalvatoreEggplant 1d ago edited 1d ago

Just a simple start…

General linear models and a generalized linear models

A general linear model has the same assumptions as specific general linear models, like anova and linear regression.  Mainly, that the dependent variable is continuous and that errors are normally distributed and homoscedastic.

A generalized linear model can have a different kind of dependent variable.  For example, if you have a binary outcome, you might use logistic regression.  If you have a count dependent variable, you might use Poisson or negative binomial regression.  Also common are beta regression and Gamma regression.

Fixed effects and random effects

There’s a lot that could be said here, but the way I like to think about it. 

Let’s imagine we’re testing students at different schools.  If we care about the results of, say, Mrs. Puff’s Boating School and Springfield Elementary School, specifically.  Like, you may want to compare the results of these two schools. Or if that specific school’s results matter to the interpretation. In that case, School is a fixed effect.

In contrast, if we have a bunch of schools, and we need to account for differences among the schools, but we don’t care about the specific school.  Like if Mrs. Puff’s dropped out the trial and Nevermore Academy was added, we wouldn’t care.  Then we may want to treat School as a random effect.

7

u/SalvatoreEggplant 1d ago

For the most part, results are interpreted the same way as they would be interpreted in an anova or linear regression.

The lmerTest package is very useful if you’re using lmer(). (I’m not sure if it works with glmer() models. I didn’t try it.)

The emmeans package is invaluable and handles many common model objects. https://cran.r-project.org/web/packages/emmeans/vignettes/models.html .  It can give you estimates for effects, or comparisons among effect levels (e.g. post-hoc comparisons among treatments). One cool thing, you can get estimates for effects in logistic regression in terms of odds ratio. (type="response").

I haven’t used the glmmTMB package very much, but it seems to be infinitely useful for creating generalized mixed effects models.

I have some examples of analyses with R code here: https://rcompanion.org/handbook/ . You may find something useful for you there.

1

u/Free_Corgi6715 15h ago

Hey! I am also very new to statistics. I am doing an experiment in a field of psychology and i would need to use R to analyse my data. I have literally no idea how and where to start .. I don't have too much time to start from 0 but did you find any course to learn R or statistics for psychology? 

1

u/DigThatData 5h ago

the book I recommend in this comment is essentially an extremely deep companion to the arm package.

-5

u/StuffyDuckLover 1d ago

Fixed effects are regression parameters like slopes and intercepts.

Random effects are variances around those.

Where do those variances come from you ask? The hierarchical sampling unit!

Students, nested in schools, predicting student math test score, from homework score:

Overall relationship, AKA regression slope is the relationship between students homework scores and the test - fixed effect. The random effect would be the school level variance around that slope (or intercept).

Why you ask? A low variance suggests student scores are independent of the school they went to. A high variance suggests schools account for a large portion of that effect.

See now that wasn’t so hard was it?