2015-05-03 148 views
1

我試圖用GLM複製SAS的PROC GENMOD的結果R.我想,以適應該模型是PROC GENMOD在SAS VS中的R GLM

日誌[E(Y IJ | IJ年,治療)] = Β + B 年份 IJ + B 款待 * 年份IJ

在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()命令來建議獲得的只是估計年和年*治療,而不是單獨治療?

+4

嘗試'glm1 <-glm(Y〜年+治療:年,數據=皮膚,家庭=「泊松」)'。 '*'表示法增加了完整的和交互的術語,':'只增加了相互作用 – user20650

+1

就是這樣!非常感謝! – KES

回答

2

ř解釋式A*B作爲A+B+A:B

嘗試

glm1<-glm(Y~year+treat:year,data=skin,family="poisson") 
summary(glm1) 
1

正如user20650指出的那樣,使用結腸而不是星號將僅估計相互作用項。因此,R代碼是

glm1<-glm(Y~year+treat:year,data=skin,family="poisson")