5
$\begingroup$

I'm used to specifying mixed models with mathematical notation or in R using the lme4 syntax. Now, I was asked to review a mixed model fitted in SAS. The SAS model is specified as follows

PROC MIXED;
CLASS    animalID treatment week time_of_day;
MODEL    y = treatment week treatment*time_of_day
REPEATED time_of_day*week / SUBJECT=animalID TYPE=cs;
RANDOM   animalID(time_of_day);

I tried to translate this into lme4 syntax (based on the SAS Help Center: MIXED Procedure and lmer for SAS PROC MIXED Users) and think the model above would correspond to the following model in lme4

lmer(y ~ treatment + treatment:time_of_day + week +
         (1|time_of_day:week) + (1|time_of_day:animalID))

with all predictors as factors.

Is this translation correct?

Specifically

  1. Is it correct that treatment*time_of_day just includes the interaction but not the main effect of treatment and time_of_day in SAS?

  2. An effect in the REPEATED statement with compound symmetry covariance structure is equivalent to a random intercept?

  3. The nested notation (animalID(time_of_day)) just includes the random interaction between animalID and time_of_day? No additional main (random) effect of time_of_day?

Bonus Question: Do you know of any other good reference which directly compares how models in SAS and R are specified?

$\endgroup$
1
  • 1
    $\begingroup$ I'm not 100% on all of this, but: 1) correct, treatment|time_of_day would be the main plus interaction. 2) Only under non-negative correlation (which random effects don't allow) and I'm not sure if this applies if you have other random effects also. 3) This will make each unique combination of animalID and time_of_day a separate block in the random effect, I'm not used to this being called an interaction but I guess you could call it that, and definitely yes to the last part of your question. $\endgroup$
    – PBulls
    Oct 17, 2023 at 15:05

1 Answer 1

7
$\begingroup$

Treatment * Time_of_day Interaction: In SAS, the treatment * time_of_day term includes both the interaction and the main effects of treatment and time_of_day. In your lme4 translation, you've correctly included the interaction (treatment:time_of_day), but you should also include the main effects separately if you want them in the model. So, it should be:

lmer(y ~ treatment + time_of_day + treatment:time_of_day + week +
      (1 | time_of_day:week) + (1 | time_of_day:animalID))

This includes the main effects of treatment and time_of_day along with the interaction.

Effect in the REPEATED Statement: In SAS, the REPEATED statement with the TYPE = cs option specifies a compound symmetry covariance structure for the repeated measures. This is equivalent to having a random intercept for time_of_day in the lme4 model. So, I think your translation is correct in including (1 | time_of_day:week).

Nested Notation: Yes, (1 | animalID(time_of_day)) in SAS includes the random interaction between animalID and time_of_day. It does not include an additional main (random) effect of time_of_day, so this seems correct to me.

As for resources, I find this quite helpful:

https://support.sas.com/content/dam/SAS/support/en/books/free-books/sas-programming-for-r-users.pdf

$\endgroup$
3
  • $\begingroup$ Thanks. Are you sure about the automatic inclusion of interaction terms? All that I found so far suggests the opposite. See e.g. SAS Documentation ANOVA Procedure. They always explicitly write the main effects and additionally have the bar (|) notation which seems to be the equivalent of the asterisk (*) in R. $\endgroup$
    – retodomax
    Oct 22, 2023 at 17:17
  • 1
    $\begingroup$ I’m not 100% sure to be honest. Thanks for bringing that up. These things are always a bit frustrating! It’s late here now but I will take another look tomorrow. $\endgroup$ Oct 22, 2023 at 20:03
  • 1
    $\begingroup$ @retodomax sorry for the delay ! I have just had a chance to look at this again, and you are right. In SAS, when you specify an interaction term using the asterisk (), it does *not automatically include the main effects. In SAS, if you want to include the main effects along with the interaction, you need to specify them explicitly. I will update the answer shortly. $\endgroup$ Oct 31, 2023 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.