SAS中的PROC GENMOD与R中的glm
我试图用R中的glm复制SAS的PROC GENMOD的结果。我试图拟合的模型是 log[EYij | Yearij,Treati]=Β1+B2Yearij+B3Treati*Yearij 在SAS中,代码和结果为:SAS中的PROC GENMOD与R中的glm,r,sas,R,Sas,我试图用R中的glm复制SAS的PROC GENMOD的结果。我试图拟合的模型是 log[EYij | Yearij,Treati]=Β1+B2Yearij+B3Treati*Yearij 在SAS中,代码和结果为: proc sort data=skin; by id year; run; proc genmod data=skin; class id yearcat; model y=year trt*year / dist=poisson link=log type3 wald waldc
proc sort data=skin; by id year;
run;
proc genmod data=skin;
class id yearcat;
model y=year trt*year / dist=poisson link=log type3 wald waldci;
repeated subject=id / withinsubject=yearcat type=un;
run;
-----------------------------------------------------------------------------------------------
Analysis Of GEE Parameter Estimates
Empirical Standard Error Estimates
Standard 95% Confidence
Parameter Estimate Error Limits Z Pr > |Z|
Intercept -1.3341 0.0815 -1.4938 -1.1743 -16.37 <.0001
year -0.0090 0.0271 -0.0622 0.0441 -0.33 0.7392
year*trt 0.0429 0.0319 -0.0195 0.1053 1.35 0.1781
正如我所希望的,只有三个估计系数,分别是截距、年份和年份*treat
然而,在R中,估计了四个系数,尽管我的模型只指定了三个:
> glm1<-glm(Y~year+treat*year,data=skin,family="poisson")
> summary(glm1)
Call:
glm(formula = Y ~ year + treat * year, family = "poisson", data = skin)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.34810 0.07647 -17.629 <2e-16 ***
year -0.01192 0.02528 -0.472 0.637
treat1 0.05850 0.10468 0.559 0.576
year:treat1 0.03113 0.03454 0.901 0.367
是否有人建议如何在R中指定我的glm命令,以仅获得年份和年份*treat的估计值,而不仅仅是治疗?R将公式a*B解释为a+B+a:B
试一试
R将公式A*B解释为A+B+A:B
试一试
正如user20650所指出的,使用冒号而不是星号只能估计交互项。因此,R码是
glm1<-glm(Y~year+treat:year,data=skin,family="poisson")
正如user20650所指出的,使用冒号而不是星号只能估计交互项。因此,R码是
glm1<-glm(Y~year+treat:year,data=skin,family="poisson")
我会用librarygee的gee来代替。R代码为:
gee(Y ~ year + treat:year, data = skin, family = poisson, corstr = "unstructured", id = id)
我会用librarygee的gee来代替。R代码为:
gee(Y ~ year + treat:year, data = skin, family = poisson, corstr = "unstructured", id = id)
试试看,就是这样!非常感谢你!试试看,就是这样!非常感谢你!