How to define interaction between 2 categorical covariates and Time and Intervention in a longitudinal model? (in R)

Dears,

Let's assume, that I have a study like this:

1. longitudinal, 3 time points, T1, T2, T3. Let's assume T1 is post-intervention.
2. 2 interventions, A and B
3. 2 categorical covariates: Cov1 (2 levels: Cov1.1, Cov1.2) and Cov2 (2 levels: Cov2.1, Cov2.2) The covariates DO NOT interact with each other.

I want the interaction between Time and Intervention and the covariates to study the impact of the covariates on the intervention at each time point:

1. Whether there are differences between interventions at each time point
2. Whether these differences at all time points are affected by the baseline values of Cov1 and Cov2 (the baseline covariates may have different impact on subsequent time points, but itself they don't change over time).

Response ~ Intervention * Time * Cov1 + Intervention * Time * Cov2 I also saw somewhere also this shortcut: Response ~ (Intervention * Time) * (Cov1 + Cov2)

Or maybe it should be Response ~ Intervention * Time + Intervention * Time * Cov1... ? or Response ~~ Intervention * Time + Intervention : Time : Cov1 + Cov1 + Intervention : Time : Cov2 + Cov2 ?

This is exploratory analysis I will be doing with GEE followed by the analysis of contrasts (in R: emmeans). My data are complete.

My output should look like (using emmeans):

Strata: Time T1:
Cov1.1-TrtA vs. Cov1.1-TrtB
Cov1.2-TrtA vs. Cov1.2-TrtB

Cov2.1-TrtA vs. Cov2.1-TrtB
Cov2.2-TrtA vs. Cov2.2-TrtB


PS: later the pairs for each covariate Cov1 (and Cov2) will be compared to see if in overall Cov1 (and Cov2) affects the effect TrtA vs. TrtB), I mean: [Cov1.1-TrtA vs. Cov1.1-TrtB] vs. [Cov1.2-TrtA vs. Cov1.2-TrtB ] and same for Cov2.

Strata: Time T2:
Cov1.1-TrtA vs. Cov1.1-TrtB
Cov1.2-TrtA vs. Cov1.2-TrtB

Cov2.1-TrtA vs. Cov2.1-TrtB
Cov2.2-TrtA vs. Cov2.2-TrtB

Strata: Time T3:
Cov1.1-TrtA vs. Cov1.1-TrtB
Cov1.2-TrtA vs. Cov1.2-TrtB

Cov2.1-TrtA vs. Cov2.1-TrtB
Cov2.2-TrtA vs. Cov2.2-TrtB


You know my goals, now I need your advice of which formula best reflects my needs. I cannot provide the data, it's just about general idea. I used R syntax, because it's easiest for me to understand the syntax. But if you use any other software, SAS, SPSS, you can provide your own. I need the general idea on how to set up the interactions properly.

EDIT: I just checked, that Response ~ Intervention*Time*(Cov1 + Cov2) gives me sensible model coefficients and it's equivalent to Response ~ Intervention + Time + Intervention:Time + Cov1 + Cov1:Time + Cov1:Intervention + Cov1:Time:Intervention + (same for Cov2)

The second options with Response ~ Intervention*Time + Cov1 + Intervention:Time:Cov1 + Cov2 + Intervention:Time:Cov2 gives me weird coefficients, I missed certain higher-level interactions.

• Is Time T1 before or after the intervention? Please provide that information by editing the question, as comments are easy to overlook and can be deleted.
– EdM
Commented Mar 29, 2023 at 21:54
• Sure. I forgot to add. Could we consider both? I will have both randomized study (with T1 before intervention, baseline), and an observational one (of the same schema as described) with T1 - post-intervention. If I had to pick one - it's post intervention. Commented Mar 30, 2023 at 0:58

As you note, your "second option" omits almost all of the two-way interactions among predictors (except for the Intervention:Time interaction) while maintaining the 3-way interactions. Omitting lower-level terms or interactions while including higher-level interactions is generally not a good idea, as explained on this page.
What might be missing from your model is the baseline Response value as a predictor. That depends on the nature of Response. It often helps to include the pre-intervention values of a Response variable as a predictor, to control for differences between treatment and control groups in the post-intervention Response values. If the Response is a change from a baseline, however, then you don't want include the baseline level as a predictor. This page and this page might help guide your design.
Finally, note that your model with 3-way interactions involving 3 time points requires estimating a large number of coefficients and a correspondingly large sample size. You need to estimate: for individual coefficients, 1 each for Intervention, Cov1, and Cov2 and 2 for Time (5 total individual coefficients); for 2-way interactions, 1 each for Intervention:Cov1 and Intervention:Cov2 and 2 each for the 3 two-way interactions involving Time (8 total 2-way interaction cofficients); for 3-way interactions, 2 for each of them. That's 15 coefficients to estimate beyond an intercept.