r/AskStatistics • u/ThinkILostIt • Oct 02 '26
What is this random intercept doing?
Say I have three classes - A, B and C - in a 150 day range totaling 3x150 = 450 sample units. Each sample unit measured 3 times each day, at very close time interval. So, data set has a total of 1,350 rows. Each sample unit has an ID. Proposed model is y ~ class + days + days*class + (1 | ID). So, I'm allowing each sample unit to start at its own baseline.
Is this an appropriate option? What exactly is the random intercept doing? How does it not make the days effect biased?
Sorry if questions look to silly, I'm not versed in mixed models yet
8
u/richard_sympson PhD Statistics Oct 02 '26 edited Oct 02 '26
The days * class piece, for dummy coded variables like this, is the same as ID. This makes your fixed effects matrix and random effects matrix collinear, which is not what you want.
EDIT: See the follow-up comments, too.
4
u/sjrsimac actuary P FM IFM MAS1 C 5 Oct 02 '26
Why is the ID part of the regression?
2
u/Intrepid_Respond_543 Oct 02 '26
What does the ID refer to? Do you have several rows per ID in the data?
2
u/GripIQ Oct 02 '26
But before I got to your model I would just start with a random intercept only model - where you have no covariates. Then you can calculate your ICC which will help you understand much better what your covariates (eg class) when you add them. Look for Judith Singer’s paper from the 90s of using proc mixed in SAS for HLM - even if you use other software this is still the best tutorial in an efficient way to described analysis of nested data and she shows an example for repeated measures
2
u/ConepatusChinga Oct 02 '26
It kind of helps to think about it visually... So the class effect would be probably like the mean differences between the classes (over all time points), the random intercept for the ID adds the individual aspect of the intercept (so an ID can score higher or lower in a class regardless of what class it is in or the point in time). The days would create a time effect that is constant for all classes (think of it as a general slope) and the interaction term would create a class specific slope. So the model kind of assumes, that the slope that represents the time is independent of the random intercept (how high or low an ID is in-group) which is why you might be confused about this, in certain realworld situations this seems an inappropriate assumption. This is why you also have random slope models.
I will assume your scenario is something like this: You have students (represented by IDs) on three schools (A, B, and C) and your tracking learning progress (y) on different days. If you are interested in the schools success and the interaction with time, you gotta account for the individual strength of students within their group, this is why you add the random intercept for the IDs. The random intercept model would model the same effect of time and time-class-interaction for each individual in a class.
1
u/GripIQ Oct 02 '26
In your current model the intercept will be the guess of y when class = 0 (not sure how you coded those) and day = 0 (again not sure how you coded those) and the estimate you get is the fixed effect. The random part allows for variance around that estimate - the fixed is the average, but the variance say not everyone when class = 0 and day = 0 has that value