SAS 中的 PROC GENMOD 与 R 中的 glm
PROC GENMOD in SAS vs glm in R
我正在尝试使用 R 中的 glm 复制 SAS 的 PROC GENMOD 的结果。我正在尝试拟合的模型是
log[E(Yij|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 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
如我所愿,估计的系数只有三个,分别是截距、年和年*处理。
然而,在 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() 命令以获得仅年和年*治疗的估计,而不是单独的治疗?
R 将公式 A*B
解释为 A+B+A:B
尝试
glm1<-glm(Y~year+treat:year,data=skin,family="poisson")
summary(glm1)
正如 user20650 指出的那样,使用冒号而不是星号只会估计交互项。因此,R 代码是
glm1<-glm(Y~year+treat:year,data=skin,family="poisson")
我会改用库中的 gee(gee)。 R 代码为:
gee(Y ~ year + treat:year, data = skin, family = poisson, corstr = "unstructured", id = id)
我正在尝试使用 R 中的 glm 复制 SAS 的 PROC GENMOD 的结果。我正在尝试拟合的模型是
log[E(Yij|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 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
如我所愿,估计的系数只有三个,分别是截距、年和年*处理。
然而,在 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() 命令以获得仅年和年*治疗的估计,而不是单独的治疗?
R 将公式 A*B
解释为 A+B+A:B
尝试
glm1<-glm(Y~year+treat:year,data=skin,family="poisson")
summary(glm1)
正如 user20650 指出的那样,使用冒号而不是星号只会估计交互项。因此,R 代码是
glm1<-glm(Y~year+treat:year,data=skin,family="poisson")
我会改用库中的 gee(gee)。 R 代码为:
gee(Y ~ year + treat:year, data = skin, family = poisson, corstr = "unstructured", id = id)