# Advice on modelling longitudinal change of dichotomous dependant variables within clustered data

I'm working with a data set from a multi-school data set and trying to model the relationship between a dichotomous Sleep Status (whether or not they were getting 8 or more hours of sleep per night) measured over two observation points (T1 & T2). Between T1 and T2 participants can change from a yes (≥8h) to a no (<8), vice versa, remain a yes, or remain a no.

There are also 2 conditions (ConditionA vs ConditionB) which applies to the entire school (e.g. schools 1-50 are ConditionA and schools 51-100 are all ConditionB) as part of a natural experiment (change in policy between T1 & T2, that affected some schools). I have some various other covariates to control for statistically (e.g. Sex, SES, etc) that I'm treating as time-invariant because I'm using measurements taken at baseline.

Fundamentally what I am interested in knowing is whether the individuals in Condition1 differ in Sleep Status from those in Condition2 at the follow up (T2) while accounting for their original Sleep Status (participants can go from meeting the status

In summary the key variables are:

• Sleep Status - Dependant variable (self-report ≥8h sleep/night), dichotomous yes (≥8h) or no (<8h) measured at both T1 & T2
• Time - T1 (Baseline) & T2 (Follow-up)
• SchoolID - clustering variable, approximately 100 clusters
• ParticipantID - arbitrary alphanumeric to link longitudinal data, participants are all nested within schools (students not included if they change schools)
• Condition - 2 factor variable, schools are all nested within one of the two conditions (ConditionA vs ConditionB) representing a change in policy that affected some schools but not others
• Sex - stand in for other control covariates that will be included in the model

I know I'm going to use some kind of mixed modelling approach (likely multilevel logistic regression) but am having some difficulty deciding on what variables should be included as an interaction term vs allowing the slopes to vary.

If I were to create a model for a cross sectional data set it would be something along the lines of:

Sleep Status ~ Sex + Condition + (1|SchoolID)

However to address with the longitudinal nature of the data I suspect I should instead be modelling something along the lines of:

Sleep Status.T2 ~ Sex + Sleep Status.T1*Condition + (1|SchoolID)

However, I think I've confused myself somewhat by also considering using a growth model approach or potentially using a nominal logistic regression to account for direction and type of change in the Sleep status (i.e. 4 possible outcomes: 01 (no-yes), 10 (yes-no), 00 (no-no), 11 (yes-yes)).

Any insight or help would be appreciated as it is my first time trying to model change on a dichotomous variable and it's further complicated by the clustered nature of the data.

Your second model, m2 <- glmer(Sleep Status.T2 ~ Sex + Sleep Status.T1*Condition + (1|SchoolID), data=df, family = binomial) is the model I would run with your data. You want to know whether being in Condition B vs. A is associated with an increase or decrease in sleep at t2, adjusting for sleep at t1, and any covariates. The interaction further tests whether any Condition "effect" is enhanced when t1 sleep status is 1 vs. 0. That may or may not be of interest, but it's probably worth looking at. I suggest using the ggeffects package for graphing interactions.
You could run model 1, but you would need to add a random intercept for students: m1 <- glmer(Sleep Status ~ Sex + Condition + (1|StudentID) + (1|SchoolID), data=df, family = binomial). This model does not account for prior sleep status, but does account for within-student correlation in sleep status through the student random intercept. I personally don't think this makes as much sense given your research question.
By the way, you do not need to throw out students who switch schools. lme4 easily handles this. It doesn't give you specific school 1 and school 2 effects without further work, but if that's not of interest, then at least you retain all students. You could additionally add a 0/1 covariate to this model that indicates whether students switched schools.