全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
5105 8
2012-02-28
以前一直用的SAS, 现在也想学学R, 但在做混合模型的时候,发现 R 和SAS 的结果总是有差别,例如下面的例子,数据见附件。
R 程序:
a =read.table("RIKZ.txt",header=T)
a$fBeach <- factor(a$Beach)
library (nlme)
mixed <- lme(Richness ~ NAP, random = ~1 +NAP| fBeach,data=a)
summary (mixed)

SAS程序
proc mixed data=rikz;
class beach;
model richness=nap /intercept;
random intercept nap/ subject=beach;
run;
但是R 和SAS的结果却不同,这是怎么回事呢?求高人指点!
该数据和R程序见于Mixed Effects Models and Extensions in Ecology with R, P109
SAS程序是我自己写的,是不是有哪里写的不对啊?
附件列表

RIKZ.txt

大小:808 Bytes

 马上下载

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2012-2-28 09:57:15
...
hi, there:
First of all, i would check if they are using the same method; as i know, for SAS, it is REML as default; what about R? it may be ML;if that is true, you would expect some difference in the results.\\jingju

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-2-28 10:01:12
多谢jingju的回复,但是就这个例子来说,SAS和R是一样的,都是REML,不知道问题在哪里?

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-2-28 10:23:30
you are right. the default for R is reml too. so, what do you mean the resuts are different? jingju
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-2-28 10:33:20
运行上述程序后R的结果是:
Linear mixed-effects model fit by REML
Data: a
       AIC      BIC    logLik
  244.3839 254.9511 -116.1919

Random effects:
Formula: ~1 + NAP | fBeach
Structure: General positive-definite, Log-Cholesky parametrization
            StdDev   Corr  
(Intercept) 3.549100 (Intr)
NAP         1.715015 -0.99
Residual    2.702785      

Fixed effects: Richness ~ NAP
                Value Std.Error DF   t-value p-value
(Intercept)  6.588729 1.2647708 35  5.209425   0e+00
NAP         -2.830029 0.7229514 35 -3.914549   4e-04
而SAS的结果是:
The Mixed Procedure

                                                     Fit Statistics

                                          -2 Res Log Likelihood           238.0
                                          AIC (smaller is better)         244.0
                                          AICC (smaller is better)        244.6
                                          BIC (smaller is better)         244.6


                                              Type 3 Tests of Fixed Effects

                                                    Num     Den
                                      Effect         DF      DF    F Value    Pr > F

                                      Intercept       1       8      29.53    0.0006
                                      NAP             1       8      14.51    0.0052
可见两种结果在AIC,BIC, 分母自由度,及最终的P值上都有不同!问题到底出在哪里呢?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-2-28 10:46:43
in sas, df =3 were used but it is 6 in r. so, i doubut the group effect in r can be identical to subject effect in sas.//jingju
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群