我正在尝试将SAS转换为R,以获得重复测量的混合模型.SAS代码如下:
proc mixed data=pd method=reml ;
by set;
class id month arm;
model eff=base arm month arm*month/s;
repeated/subject=id type=un r;
lsmeans arm*month/pdiff cl;
在R中,我有一个数据框设置有月,id,arm作为因子和eff,base作为数字。我需要使用与上述相同的方法为每个治疗组(手臂)和每个月生成p值,以确定它们在每个给定月份的治疗中是否存在显着差异。
我目前在R中复制此内容的尝试是:
eff.lm<-lme(data = pd, fixed= eff~base + arm*month,
random= ~month|ID,
correlation= corSymm(form=~month|ID))
eff.ls<-lsmeans(object= eff.lm, spec = ~arm|month)
comp<-pairs(eff.ls)
pval<-summary(pairs(eff.ls))$p.value
但是,这会在调用lme()后导致以下错误:
Error in if (length(uCov) != maxCov){ :
missing value where TRUE/FALSE needed
In addition: Warning message:
In Ops.factor(unlist(covar),1):'-' not meaningful for factors
作为回应,我将Month更改为Numeric并且模型运行时没有错误,但是pair函数仅在第3.5个月或平均月份生成pvalues,此时我需要每个月的pvalues(1到6)。
pd$month<-as.numeric(pd$month)
eff.lm<-lme(data = pd, fixed= eff~base + arm*month,
random= ~month|ID,
correlation= corSymm(form=~month|ID))
eff.ls<-lsmeans(object= eff.lm, spec = ~arm|month)
comp<-pairs(eff.ls)
pval<-summary(comp)$p.value
print(comp)
> month = 3.5:
contrast estimate SE df t.ratio p.value
1 - 2 -1.6817998 0.2415967 2015 -6.961 <.0001
1 - 3 -1.2286784 0.2415994 2015 -5.086 <.0001
1 - 4 -0.9165385 0.2416426 2015 -3.793 0.0029
1 - 5 -0.7736447 0.2416409 2015 -3.202 0.0234
1 - 6 -0.6709280 0.2416238 2015 -2.777 0.0809
1 - 7 -0.1179885 0.2416134 2015 -0.488 0.9990
2 - 3 0.4531214 0.2415986 2015 1.876 0.4969
2 - 4 0.7652613 0.2416463 2015 3.167 0.0262
2 - 5 0.9081551 0.2416446 2015 3.758 0.0033
2 - 6 1.0108718 0.2416266 2015 4.184 0.0006
2 - 7 1.5638113 0.2416156 2015 6.472 <.0001
3 - 4 0.3121399 0.2416678 2015 1.292 0.8560
3 - 5 0.4550337 0.2416657 2015 1.883 0.4919
3 - 6 0.5577504 0.2416437 2015 2.308 0.2404
3 - 7 1.1106899 0.2416296 2015 4.597 0.0001
4 - 5 0.1428938 0.2415966 2015 0.591 0.9971
4 - 6 0.2456105 0.2415991 2015 1.017 0.9503
4 - 7 0.7985500 0.2416039 2015 3.305 0.0168
5 - 6 0.1027167 0.2415987 2015 0.425 0.9995
5 - 7 0.6556562 0.2416032 2015 2.714 0.0953
6 - 7 0.5529395 0.2415979 2015 2.289 0.2499
P value adjustment: tukey method for comparing a family of 7 estimates
如果有人可以提供有关如何使用NLME包或lme4包在R中复制SAS代码的建议,我们将不胜感激。