简体   繁体   English

转换混合模型,重复测量从SAS到R.

[英]Convert mixed model with repeated measures from SAS to R

I have been trying to convert a repeated measures model from SAS to R, since a collaborator will do the analysis but does not have SAS. 我一直在尝试将重复测量模型从SAS转换为R,因为合作者将进行分析但没有SAS。 We are dealing with 4 groups, 8 to 10 animals per group, and then 5 time points for each animal. 我们正在处理4组,每组8到10只动物,然后每只动物5个时间点。 The mock data file is available here https://drive.google.com/file/d/0B-WfycVUQyhaVGU2MUpuQkg4Mk0/edit?usp=sharing as a Rdata file and here https://drive.google.com/file/d/0B-WfycVUQyhaR0JtZ0V4VjRkTk0/edit?usp=sharing as an excel file: 模拟数据文件可在此处获得https://drive.google.com/file/d/0B-WfycVUQyhaVGU2MUpuQkg4Mk0/edit?usp=sharing作为Rdata文件,此处https://drive.google.com/file/d/ 0B-WfycVUQyhaR0JtZ0V4VjRkTk0 / edit?usp =作为excel文件共享

The original SAS code (1) is : 原始的SAS代码(1)是:

proc mixed data=essai.data_test method=reml;
    class group time mice;
    model param = group time group*time / ddfm=kr;
    repeated time / type=un subject=mice group=group;
run;

Which gives : 这使 :

    Type 3 Tests des effets fixes
               DDL     DDL     Valeur
Effet         Num.    Res.          F    Pr > F
group            3    15.8       1.58    0.2344
time             4    25.2      10.11    <.0001
group*time      12    13.6       1.66    0.1852

I know that R does not handle degrees of freedom in the same way as SAS does, so I am first trying to obtain results similar to (2) : 我知道R不像SAS那样处理自由度,所以我首先尝试获得类似于(2)的结果:

proc mixed data=essai.data_test method=reml;
    class group time mice;
    model param = group time group*time;
    repeated time / type=un subject=mice group=group;
run;

I have found some hints here Converting Repeated Measures mixed model formula from SAS to R and when specifying a compound symmetry correlation matrix this works perfectly. 我在这里找到了一些提示将重复测量混合模型公式从SAS转换为R,并且在指定复合对称相关矩阵时,这非常有效。 However, I am not able to obtain the same thing for a general correlation matrix. 但是,对于一般相关矩阵,我无法获得相同的东西。

With (2) in SAS, I obtain the following results : 使用SAS中的(2),我得到以下结果:

   Type 3 Tests des effets fixes
              DDL     DDL     Valeur
Effet         Num.    Res.          F    Pr > F
group            3      32       1.71    0.1852
time             4     128      11.21    <.0001
group*time      12     128       2.73    0.0026

Using the following R code : 使用以下R代码:

options(contrasts=c('contr.sum','contr.poly'))
mod <- lme(param~group*time, random=list(mice=pdDiag(form=~group-1)),
            correlation = corSymm(form=~1|mice),
            weights = varIdent(form=~1|group),
            na.action = na.exclude, data = data, method = "REML")
anova(mod,type="marginal")

I obtain: 我获得:

            numDF denDF   F-value p-value
(Intercept)     1   128 1373.8471  <.0001
group           3    32    1.5571  0.2189
time            4   128   10.0628  <.0001
group:time     12   128    1.6416  0.0880

The degrees of freedom are similar, but not the tests on fixed effects and I don't know where this comes from. 自由度是相似的,但不是对固定效应的测试,我不知道它来自何处。 Would anyone have any idea of what I am doing wrong here? 谁能知道我在这里做错了什么?

Your R code differs from the SAS code in multiple ways. 您的R代码以多种方式与SAS代码不同。 Some of them are fixable, but I was not able to fix all the aspects to reproduce the SAS analysis. 其中一些是可修复的,但我无法修复所有方面来重现SAS分析。

  1. The R code fits a mixed effects model with a random mice effect, while the SAS code fits a generalized linear model that allows correlation between the residuals, but there are no random effects (because there is no RANDOM statement). R代码适合具有随机mice效果的混合效果模型,而SAS代码适合允许残差之间相关性的广义线性模型,但没有随机效应(因为没有RANDOM语句)。 In R you would have to use the gls function from the same nlme package. 在R中,您必须使用相同nlme包中的gls函数。

  2. In the R code all observations within the same group have the same variance, while in the SAS code you have an unstructured covariance matrix, that is each time-point within each group has its own variance. 在R代码中,同一组内的所有观察具有相同的方差,而在SAS代码中,您具有非结构化协方差矩阵,即每个组内的每个时间点都有自己的方差。 You can achieve the same effect by using weights=varIdent(form=~1|group*time) . 使用weights=varIdent(form=~1|group*time)可以达到相同的效果。

  3. In the R code the correlation matrix is the same for every mouse regardless of group. 在R代码中,无论组如何,每个鼠标的相关矩阵都是相同的。 In the SAS code each group has its own correlation matrix. 在SAS代码中,每个组都有自己的相关矩阵。 This is the part that I don't know how to reproduce in R. 这是我不知道如何在R中重现的部分。

I have to note that the R model seems to be more meaningful - SAS estimates way too many variances and correlations (which, by the way, you can see meaningfully arranged using the R and RCORR options to the repeated statement). 我必须注意到R模型似乎更有意义 - SAS估计方差和相关性太多(顺便说一下,你可以看到使用RRCORR选项对repeated语句进行有意义的排列)。

"In the R code the correlation matrix is the same for every mouse regardless of group. In the SAS code each group has its own correlation matrix. This is the part that I don't know how to reproduce in R." “在R代码中,无论组如何,每个鼠标的相关矩阵都是相同的。在SAS代码中,每个组都有自己的相关矩阵。这是我不知道如何在R中重现的部分。” - Try: correlation=corSymm(~1|group*time) - 尝试:correlation = corSymm(~1 | group * time)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM