glm(Y ~ X1 + X2 + X3, family=poisson(link="log"),data=mydata)
glm(Y ~ X1 + X2 + X3, family=poisson(link="log"),data=mydata)
> data(breslow.dat,package = "robust") #導入robust包中的breslow數據 > names(breslow.dat) #變量名稱 [1] "ID" "Y1" "Y2" "Y3" "Y4" "Base" "Age" "Trt" "Ysum" "sumY" "Age10" [12] "Base4" > summary(breslow.dat[c(6,7,8,10)]) #得到六、七、八、10的變量數據等同於 breslow.dat[,c(6,7,8,10)] Base Age Trt sumY Min. : 6.00 Min. :18.00 placebo :28 Min. : 0.00 1st Qu.: 12.00 1st Qu.:23.00 progabide:31 1st Qu.: 11.50 Median : 22.00 Median :28.00 Median : 16.00 Mean : 31.22 Mean :28.34 Mean : 33.05 3rd Qu.: 41.00 3rd Qu.:32.00 3rd Qu.: 36.00 Max. :151.00 Max. :42.00 Max. :302.00 #繪製圖形觀察基本的狀況 > opar <- par(no.readonly = TRUE) #複製一份圖形設置 > par(mfrow = c(1,2)) #修改參數 > attach(breslow.dat) > hist(sumY,breaks = 20,xlab="Seizure Count", + main="Distribution of Seizure") > boxplot(sumY~Trt,xlab ="Treatment",main="Group Comparisons") > par(opar) #還原原來的設置
> data(breslow.dat,package = "robust") #導入robust包中的breslow數據
> names(breslow.dat) #變量名稱
[1] "ID" "Y1" "Y2" "Y3" "Y4" "Base" "Age" "Trt" "Ysum" "sumY" "Age10"
[12] "Base4"
> summary(breslow.dat[c(6,7,8,10)]) #得到六、七、八、10的變量數據等同於 breslow.dat[,c(6,7,8,10)]
Base Age Trt sumY
Min. : 6.00 Min. :18.00 placebo :28 Min. : 0.00
1st Qu.: 12.00 1st Qu.:23.00 progabide:31 1st Qu.: 11.50
Median : 22.00 Median :28.00 Median : 16.00
Mean : 31.22 Mean :28.34 Mean : 33.05
3rd Qu.: 41.00 3rd Qu.:32.00 3rd Qu.: 36.00
Max. :151.00 Max. :42.00 Max. :302.00
#繪製圖形觀察基本的狀況
> opar <- par(no.readonly = TRUE) #複製一份圖形設置
> par(mfrow = c(1,2)) #修改參數
> attach(breslow.dat)
> hist(sumY,breaks = 20,xlab="Seizure Count",
+ main="Distribution of Seizure")
> boxplot(sumY~Trt,xlab ="Treatment",main="Group Comparisons")
> par(opar) #還原原來的設置
#擬合泊松迴歸 > fit <- glm(sumY ~ Base + Age + Trt, data=breslow.dat, family=poisson()) # family = poisson() > summary(fit) Call: glm(formula = sumY ~ Base + Age + Trt, family = poisson(), data = breslow.dat) Deviance Residuals: Min 1Q Median 3Q Max -6.0569 -2.0433 -0.9397 0.7929 11.0061 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) 1.9488259 0.1356191 14.370 < 2e-16 *** Base 0.0226517 0.0005093 44.476 < 2e-16 *** Age 0.0227401 0.0040240 5.651 1.59e-08 *** Trtprogabide -0.1527009 0.0478051 -3.194 0.0014 ** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for poisson family taken to be 1) Null deviance: 2122.73 on 58 degrees of freedom Residual deviance: 559.44 on 55 degrees of freedom AIC: 850.71 Number of Fisher Scoring iterations: 5
#擬合泊松迴歸
> fit <- glm(sumY ~ Base + Age + Trt, data=breslow.dat, family=poisson()) # family = poisson()
> summary(fit)
Call:
glm(formula = sumY ~ Base + Age + Trt, family = poisson(), data = breslow.dat)
Deviance Residuals:
Min 1Q Median 3Q Max
-6.0569 -2.0433 -0.9397 0.7929 11.0061
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.9488259 0.1356191 14.370 < 2e-16 ***
Base 0.0226517 0.0005093 44.476 < 2e-16 ***
Age 0.0227401 0.0040240 5.651 1.59e-08 ***
Trtprogabide -0.1527009 0.0478051 -3.194 0.0014 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 2122.73 on 58 degrees of freedom
Residual deviance: 559.44 on 55 degrees of freedom
AIC: 850.71
Number of Fisher Scoring iterations: 5