Praktikum 10
Materi: Model Log Linear untuk Data Respon Poisson
Penyelesaian dengan bantuan program R
Definisi Peubah
X = Information Program Opinion (I)
Y = Health Care Opinion (H)
Z = Gender (G)
## Program R P10 Materi Praktikum (2) Problem 8.1 (Agresti,hlm.347) ##
##=====================##
# INPUT DATA
##=====================##
z.gender<-factor(rep(c("1M","2F"),each=4))
x.IO<-factor(rep(c("1support","2oppose"),each=2,times=2))
y.HO<-factor(rep(c("1support","2oppose"),times=4))
counts<-c(76,160,6,25,114,181,11,48)
data.frame(z.gender,x.IO,y.HO,counts)
## z.gender x.IO y.HO counts
## 1 1M 1support 1support 76
## 2 1M 1support 2oppose 160
## 3 1M 2oppose 1support 6
## 4 1M 2oppose 2oppose 25
## 5 2F 1support 1support 114
## 6 2F 1support 2oppose 181
## 7 2F 2oppose 1support 11
## 8 2F 2oppose 2oppose 48
##=============================##
# Penentuan kategori reference
##=============================##
x.IO<-relevel(x.IO,ref="2oppose")
y.HO<-relevel(y.HO,ref="2oppose")
z.gender<-relevel(z.gender,ref="2F")
##=====================##
# Model 1: Saturated model
##=====================##
#saturated
model1<- glm(counts~x.IO+y.HO+z.gender+x.IO*y.HO+x.IO*z.gender+ y.HO*z.gender+x.IO*y.HO*z.gender,
family=poisson("link"=log))
summary(model1)
##
## Call:
## glm(formula = counts ~ x.IO + y.HO + z.gender + x.IO * y.HO +
## x.IO * z.gender + y.HO * z.gender + x.IO * y.HO * z.gender,
## family = poisson(link = log))
##
## Deviance Residuals:
## [1] 0 0 0 0 0 0 0 0
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 3.87120 0.14434 26.820 < 2e-16 ***
## x.IO1support 1.32730 0.16235 8.175 2.95e-16 ***
## y.HO1support -1.47331 0.33428 -4.407 1.05e-05 ***
## z.gender1M -0.65233 0.24664 -2.645 0.00817 **
## x.IO1support:y.HO1support 1.01101 0.35502 2.848 0.00440 **
## x.IO1support:z.gender1M 0.52900 0.26946 1.963 0.04962 *
## y.HO1support:z.gender1M 0.04619 0.56428 0.082 0.93476
## x.IO1support:y.HO1support:z.gender1M -0.32833 0.59339 -0.553 0.58005
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 4.4582e+02 on 7 degrees of freedom
## Residual deviance: -2.1094e-14 on 0 degrees of freedom
## AIC: 61.382
##
## Number of Fisher Scoring iterations: 3
##=====================##
#Model 2: Interaksi XY XZ YZ (Interaksi GH,GI,HI)
##=====================##
#Homogenous Model
model2 <- glm(counts~x.IO+y.HO+z.gender+x.IO*y.HO+x.IO*z.gender+ y.HO*z.gender,
family=poisson("link"=log))
summary(model2)
##
## Call:
## glm(formula = counts ~ x.IO + y.HO + z.gender + x.IO * y.HO +
## x.IO * z.gender + y.HO * z.gender, family = poisson(link = log))
##
## Deviance Residuals:
## 1 2 3 4 5 6 7 8
## -0.10362 0.07183 0.39073 -0.17923 0.08516 -0.06730 -0.26626 0.13173
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 3.8521 0.1415 27.219 < 2e-16 ***
## x.IO1support 1.3514 0.1575 8.578 < 2e-16 ***
## y.HO1support -1.3750 0.2750 -5.001 5.71e-07 ***
## z.gender1M -0.5976 0.2242 -2.666 0.00768 **
## x.IO1support:y.HO1support 0.8997 0.2852 3.155 0.00160 **
## x.IO1support:z.gender1M 0.4636 0.2406 1.927 0.05401 .
## y.HO1support:z.gender1M -0.2516 0.1749 -1.438 0.15035
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 445.82335 on 7 degrees of freedom
## Residual deviance: 0.30072 on 1 degrees of freedom
## AIC: 59.683
##
## Number of Fisher Scoring iterations: 4
##chisquare table
qchisq(0.05,1,lower.tail=FALSE)
## [1] 3.841459
##=====================##
#Menguji interaksi YZ
#Model 3: Interaksi XY XZ (Interaksi GI,HI)
##=====================##
#Conditional Association on X (tanpa YZ/GH)
model3<-glm(counts~x.IO+y.HO+z.gender+x.IO*y.HO+x.IO*z.gender,
family=poisson("link"=log))
summary(model3)
##
## Call:
## glm(formula = counts ~ x.IO + y.HO + z.gender + x.IO * y.HO +
## x.IO * z.gender, family = poisson(link = log))
##
## Deviance Residuals:
## 1 2 3 4 5 6 7 8
## -0.93493 0.67971 0.05945 -0.02883 0.81131 -0.61817 -0.04336 0.02087
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 3.8682 0.1398 27.675 < 2e-16 ***
## x.IO1support 1.3759 0.1548 8.886 < 2e-16 ***
## y.HO1support -1.4572 0.2693 -5.411 6.26e-08 ***
## z.gender1M -0.6436 0.2218 -2.901 0.00372 **
## x.IO1support:y.HO1support 0.8724 0.2841 3.071 0.00214 **
## x.IO1support:z.gender1M 0.4204 0.2384 1.763 0.07782 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 445.8233 on 7 degrees of freedom
## Residual deviance: 2.3831 on 2 degrees of freedom
## AIC: 59.765
##
## Number of Fisher Scoring iterations: 3
##chisquare table
qchisq(0.05,1,lower.tail=FALSE)
## [1] 3.841459
##=====================##
#Menguji interaksi XZ
#Model 4: Interaksi XY YZ (Interaksi GH,HI)
##=====================##
#Conditional Association on Y (tanpa XZ/GI)
model4<-glm(counts~x.IO+y.HO+z.gender+x.IO*y.HO+y.HO*z.gender,
family=poisson("link"=log))
summary(model4)
##
## Call:
## glm(formula = counts ~ x.IO + y.HO + z.gender + x.IO * y.HO +
## y.HO * z.gender, family = poisson(link = log))
##
## Deviance Residuals:
## 1 2 3 4 5 6 7 8
## 0.08450 0.61232 -0.28835 -1.39207 -0.06863 -0.55869 0.22653 1.16424
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 3.69832 0.12510 29.563 < 2e-16 ***
## x.IO1support 1.54142 0.12896 11.953 < 2e-16 ***
## y.HO1support -1.36951 0.27864 -4.915 8.88e-07 ***
## z.gender1M -0.21337 0.09885 -2.158 0.03090 *
## x.IO1support:y.HO1support 0.87239 0.28411 3.071 0.00214 **
## y.HO1support:z.gender1M -0.20823 0.17311 -1.203 0.22903
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 445.8233 on 7 degrees of freedom
## Residual deviance: 4.1267 on 2 degrees of freedom
## AIC: 61.509
##
## Number of Fisher Scoring iterations: 4
##chisquare table
qchisq(0.05,1,lower.tail=FALSE)
## [1] 3.841459
##=====================##
#Menguji interaksi XY
#Model 5: Interaksi XZ YZ (Interaksi GH,GI)
##=====================##
#Conditional Association on Z (tanpa XY/HI)
model5<-glm(counts~x.IO+y.HO+z.gender+x.IO*z.gender+y.HO*z.gender,
family=poisson("link"=log))
summary(model5)
##
## Call:
## glm(formula = counts ~ x.IO + y.HO + z.gender + x.IO * z.gender +
## y.HO * z.gender, family = poisson(link = log))
##
## Deviance Residuals:
## 1 2 3 4 5 6 7 8
## 0.4103 -0.2763 -1.2251 0.7402 0.9489 -0.7181 -2.3699 1.5298
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 3.6420 0.1360 26.783 < 2e-16 ***
## x.IO1support 1.6094 0.1426 11.285 < 2e-16 ***
## y.HO1support -0.6054 0.1112 -5.444 5.21e-08 ***
## z.gender1M -0.5749 0.2289 -2.511 0.0120 *
## x.IO1support:z.gender1M 0.4204 0.2384 1.763 0.0778 .
## y.HO1support:z.gender1M -0.2082 0.1731 -1.203 0.2290
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 445.823 on 7 degrees of freedom
## Residual deviance: 11.666 on 2 degrees of freedom
## AIC: 69.048
##
## Number of Fisher Scoring iterations: 4
##chisquare table
qchisq(0.05,1,lower.tail=FALSE)
## [1] 3.841459
For model (GH, GI, HI) berarti mengacu pada model homogenous.
##=====================##
#Model 2: Interaksi XY XZ YZ (Interaksi GH,GI,HI)
##=====================##
#Homogenous Model
model2 <- glm(counts~x.IO+y.HO+z.gender+x.IO*y.HO+x.IO*z.gender+ y.HO*z.gender,
family=poisson("link"=log))
summary(model2)
##
## Call:
## glm(formula = counts ~ x.IO + y.HO + z.gender + x.IO * y.HO +
## x.IO * z.gender + y.HO * z.gender, family = poisson(link = log))
##
## Deviance Residuals:
## 1 2 3 4 5 6 7 8
## -0.10362 0.07183 0.39073 -0.17923 0.08516 -0.06730 -0.26626 0.13173
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 3.8521 0.1415 27.219 < 2e-16 ***
## x.IO1support 1.3514 0.1575 8.578 < 2e-16 ***
## y.HO1support -1.3750 0.2750 -5.001 5.71e-07 ***
## z.gender1M -0.5976 0.2242 -2.666 0.00768 **
## x.IO1support:y.HO1support 0.8997 0.2852 3.155 0.00160 **
## x.IO1support:z.gender1M 0.4636 0.2406 1.927 0.05401 .
## y.HO1support:z.gender1M -0.2516 0.1749 -1.438 0.15035
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 445.82335 on 7 degrees of freedom
## Residual deviance: 0.30072 on 1 degrees of freedom
## AIC: 59.683
##
## Number of Fisher Scoring iterations: 4