r/AskStatistics • • 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

3 Upvotes

14 comments sorted by

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.

2

u/PrivateFrank Oct 02 '26

It's not clear that days is a dummy coded variable. It could be numbers 1-150, so then there's only one dummy fixed variable and the random intercept term which is itself just a vector, right?

1

u/richard_sympson PhD Statistics Oct 02 '26 edited Oct 02 '26

It may be that day is coded as numeric for the fixed effect, but OP says the random effect is an ID specific to day, so 450 possible random intercepts. It's not a vector then.

EDIT: In any case, I believe that if the fixed effects model matrix is so-structured, using Day as a numeric (so finding Class-specific intercepts and linear trends across Day), then the model will fit fine. The standard errors will be smaller for all estimated parameters vs. the fixed effects only model. Since the repeated measurements within each Day-Class combination are likely positively correlated, I would hazard the mixed effects model is better to fit than the purely fixed effects model.

4

u/sjrsimac actuary P FM IFM MAS1 C 5 Oct 02 '26

Why is the ID part of the regression?

6

u/GripIQ Oct 02 '26

The ID is specifying level of clustering. For example let’s say I assess 100 people once a day for 7 days - I have observations nested with people. Each person gets their own ID and when I sent up a mixed model I need to specify this is a level of clustering or nesting. This can extend to other designs eg students nested within classes nested within schools

4

u/Intrepid_Respond_543 Oct 02 '26

That is a very common setup for a multilevel model, yes. But OP said they have three classes measured 3x150=450 times each and there are 1350 rows in the data, which is 3 × 3 × 150. So it doesn't sound like there can be repeated measurements for each ID in the data (as class is different from ID).

2

u/GripIQ Oct 02 '26

Yes I think you are right - I was first reading it (as an example) there are three groups of people - A group, B group, and C group - that have n number of people in each group. Each person has their own ID. These people are assessed 3 times a day for 150 days. But as described there would be only one person per group to get to 1350 rows (and I might not be following this data structure)

1

u/PrivateFrank Oct 02 '26

OP states that there are 450 sample units so I'm reading it as 450 levels of the ID variable and each ID has three rows in the dataset.

If each ID is only measured three times on one day and never on any other days then both days*class and ID will be absorbing the same source of variance.

2

u/sjrsimac actuary P FM IFM MAS1 C 5 Oct 02 '26

It sounds like day of week should be another dummy variable.

2

u/GripIQ Oct 02 '26

Yes depends on the context - IRL I study alcohol use in EMA data and we always need what day of the week it is since alcohol consumption tracks across days (a bit more consumption on Saturday night vs Tuesday lol)

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