Tuesday, February 7, 2012

R code of GLMs for Court Data (Poisson Distribution)

> library(icda)
> data(wafers)
> wafers.loglin <- glm(defects ~ trt + thickness, family = poisson(link="log"),data=wafers)
> summary(wafers.loglin)

Call:
glm(formula = defects ~ trt + thickness, family = poisson(link = "log"),
data = wafers)

Deviance Residuals:
Min 1Q Median 3Q Max
-1.2952 -0.6785 -0.2688 0.6776 1.6307

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.7177 0.1602 10.719 < 2e-16 ***
trtB 0.5878 0.1764 3.332 0.000861 ***
thicknesshigh -0.2296 0.1701 -1.349 0.177246
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for poisson family taken to be 1)

Null deviance: 27.857 on 19 degrees of freedom
Residual deviance: 14.435 on 17 degrees of freedom
AIC: 94.517

Number of Fisher Scoring iterations: 4

> anova(wafers.loglin, test="Chisq")

Analysis of Deviance Table

Model: poisson, link: log

Response: defects
Terms added sequentially (first to last)

Df Deviance Resid. Df Resid. Dev Pr(>Chi)
NULL 19 27.857
trt 1 11.5894 18 16.268 0.0006633 ***
thickness 1 1.8326 17 14.435 0.1758239
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


> wafCI.LR <- confint(wafers.loglin)
> wafCI.LR
2.5 % 97.5 %
(Intercept) 1.3903205 2.0193444
trtB 0.2469096 0.9400962
thicknesshigh -0.5659614 0.1025576
> wafCI.Wald <- confint.default(wafers.loglin)
> wafCI.Wald
2.5 % 97.5 %
(Intercept) 1.4035823 2.0317207
trtB 0.2420819 0.9334915
thicknesshigh -0.5630535 0.1039046