Converting Repeated Measures mixed model formula from SAS to R

前端 未结 2 788
失恋的感觉
失恋的感觉 2020-12-24 10:01

There are several questions and posts about mixed models for more complex experimental designs, so I thought this more simple model would help other beginners in this proces

相关标签:
2条回答
  • 2020-12-24 10:31

    Oooh, this is going to be a tricky one, and if it's even possible using standard nlme functions, is going to take some serious study of Pinheiro/Bates.

    Before you spend the time doing that though, you should make absolutely sure that this is exact model you need. Perhaps there's something else that might fit the story of your data better. Or maybe there's something R can do more easily that is just as good, but not quite the same.

    First, here's my take on what you're doing in SAS with this line:

    repeated / type=cs subject=person group=GROUP;
    

    This type=cs subject=person is inducing correlation between all the measurements on the same person, and that correlation is the same for all pairs of days. The group=GROUP is allowing the correlation for each group to be different.

    In contrast, here's my take on what your R code is doing:

    random = ~ +1 | person,
    correlation=corCompSymm(form=~day|person)
    

    This code is actually adding almost the same effect in two different ways; the random line is adding a random effect for each person, and the correlation line is inducing correlation between all the measurements on the same person. However, these two things are almost identical; if the correlation is positive, you get the exact same result by including either of them. I'm not sure what happens when you include both, but I do know that only one is necessary. Regardless, this code has the same correlation for all individuals, it's not allowing each group to have their own correlation.

    To let each group have their own correlation, I think you have to build a more complicated correlation structure up out of two different pieces; I've never done this but I'm pretty sure I remember Pinheiro/Bates doing it.

    You might consider instead adding a random effect for person and then letting the variance be different for the different groups with weights=varIdent(form=~1|group) (from memory, check my syntax, please). This won't quite be the same but tells a similar story. The story in SAS is that the measurements on some individuals are more correlated than the measurements on other individuals. Thinking about what that means, the measurements for individuals with higher correlation will be closer together than the measurements for individuals with lower correlation. In contrast, the story in R is that the variability of measurements within individuals varies; thinking about that, measurements with higher variability with have lower correlation. So they do tell similar stories, but come at it from opposite sides.

    It is even possible (but I would be surprised) that these two models end up being different parameterizations of the same thing. My intuition is that the overall measurement variability will be different in some way. But even if they aren't the same thing, it would be worth writing out the parameterizations just to be sure you understand them and to make sure that they are appropriately describing the story of your data.

    0 讨论(0)
  • 2020-12-24 10:40

    Please try below:

    model1 <- lme(
      Y ~ GROUP + X1,
      random = ~ GROUP | person,
      correlation = corCompSymm(form = ~ day | person),
      na.action = na.exclude, data = df1, method = "REML"
    )
    summary(model1)
    

    I think random = ~ groupvar | subjvar option with R lme provides similar result of repeated / subject = subjvar group = groupvar option with SAS/MIXED in this case.

    Edit:

    SAS/MIXED

    SAS/MIXED covariance matrix

    R (a revised model2)

    model2 <- lme(
      Y ~ GROUP + X1,
      random = list(person = pdDiag(form = ~ GROUP - 1)),
      correlation = corCompSymm(form = ~ day | person),
      weights = varIdent(form = ~ 1 | GROUP),
      na.action = na.exclude, data = df1, method = "REML"
    )
    summary(model2)
    

    R covariance matrix

    So, I think these covariance structures are very similar (σg1 = τg2 + σ1).

    Edit 2:

    Covariate estimates (SAS/MIXED):

    Variance            person          GROUP TEST        8789.23
    CS                  person          GROUP TEST         125.79
    Variance            person          GROUP CONTROL       82775
    CS                  person          GROUP CONTROL       33297
    

    So

    TEST group diagonal element
      = 125.79 + 8789.23
      = 8915.02
    CONTROL group diagonal element
      = 33297 + 82775
      = 116072
    

    where diagonal element = σk1 + σk2.

    Covariate estimates (R lme):

    Random effects:
     Formula: ~GROUP - 1 | person
     Structure: Diagonal
            GROUP1TEST GROUP2CONTROL Residual
    StdDev:   14.56864       184.692 93.28885
    
    Correlation Structure: Compound symmetry
     Formula: ~day | person 
     Parameter estimate(s):
             Rho 
    -0.009929987 
    Variance function:
     Structure: Different standard deviations per stratum
     Formula: ~1 | GROUP 
     Parameter estimates:
       1TEST 2CONTROL 
    1.000000 3.068837 
    

    So

    TEST group diagonal element
      = 14.56864^2 + (3.068837^0.5 * 93.28885 * -0.009929987) + 93.28885^2
      = 8913.432
    CONTROL group diagonal element
      = 184.692^2  + (3.068837^0.5 * 93.28885 * -0.009929987) + (3.068837 * 93.28885)^2
      = 116070.5
    

    where diagonal element = τg2 + σ1 + σg2.

    0 讨论(0)
提交回复
热议问题