z.G<- factor(rep(c("1Male","2Female"),each=4))
x.I<- factor(rep(c("1Support","2Oppose"),each=2,times=2))
y.H<- factor(rep(c("1Support","2Oppose"),times=4))
counts<-c(76,160,6,25,114,181,11,48)
data.frame(z.G,x.I,y.H,counts)## z.G x.I y.H counts
## 1 1Male 1Support 1Support 76
## 2 1Male 1Support 2Oppose 160
## 3 1Male 2Oppose 1Support 6
## 4 1Male 2Oppose 2Oppose 25
## 5 2Female 1Support 1Support 114
## 6 2Female 1Support 2Oppose 181
## 7 2Female 2Oppose 1Support 11
## 8 2Female 2Oppose 2Oppose 48
z.G<- relevel(z.G,ref="2Female")
x.I<- relevel(x.I,ref="2Oppose")
y.H<- relevel(y.H,ref="2Oppose")#Model (GH,GI)
model1<- glm(counts~x.I+y.H+z.G+
x.I*z.G+y.H*z.G,family=poisson(link="log"))
summary(model1)##
## Call:
## glm(formula = counts ~ x.I + y.H + z.G + x.I * z.G + y.H * z.G,
## 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.I1Support 1.6094 0.1426 11.285 < 2e-16 ***
## y.H1Support -0.6054 0.1112 -5.444 5.21e-08 ***
## z.G1Male -0.5749 0.2289 -2.511 0.0120 *
## x.I1Support:z.G1Male 0.4204 0.2384 1.763 0.0778 .
## y.H1Support:z.G1Male -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
#Dugaan
hasildugaan1<-round(fitted(model1),2)
data.frame(z.G,x.I,y.H,counts,hasildugaan1)## z.G x.I y.H counts hasildugaan1
## 1 1Male 1Support 1Support 76 72.48
## 2 1Male 1Support 2Oppose 160 163.52
## 3 1Male 2Oppose 1Support 6 9.52
## 4 1Male 2Oppose 2Oppose 25 21.48
## 5 2Female 1Support 1Support 114 104.17
## 6 2Female 1Support 2Oppose 181 190.83
## 7 2Female 2Oppose 1Support 11 20.83
## 8 2Female 2Oppose 2Oppose 48 38.17
#Model (GH,HI)
model2<- glm(counts~x.I+y.H+z.G+
x.I*y.H+y.H*z.G,family=poisson(link="log"))
summary(model2)##
## Call:
## glm(formula = counts ~ x.I + y.H + z.G + x.I * y.H + y.H * z.G,
## 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.I1Support 1.54142 0.12896 11.953 < 2e-16 ***
## y.H1Support -1.36951 0.27864 -4.915 8.88e-07 ***
## z.G1Male -0.21337 0.09885 -2.158 0.03090 *
## x.I1Support:y.H1Support 0.87239 0.28411 3.071 0.00214 **
## y.H1Support:z.G1Male -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
#Dugaan
hasildugaan2<-round(fitted(model2),2)
data.frame(z.G,x.I,y.H,counts,hasildugaan2)## z.G x.I y.H counts hasildugaan2
## 1 1Male 1Support 1Support 76 75.27
## 2 1Male 1Support 2Oppose 160 152.38
## 3 1Male 2Oppose 1Support 6 6.73
## 4 1Male 2Oppose 2Oppose 25 32.62
## 5 2Female 1Support 1Support 114 114.73
## 6 2Female 1Support 2Oppose 181 188.62
## 7 2Female 2Oppose 1Support 11 10.27
## 8 2Female 2Oppose 2Oppose 48 40.38
#Model (GI,HI)
model3<-glm(counts~x.I+y.H+z.G+
x.I*y.H+x.I*z.G
,family=poisson(link="log"))
summary(model3)##
## Call:
## glm(formula = counts ~ x.I + y.H + z.G + x.I * y.H + x.I * z.G,
## 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.I1Support 1.3759 0.1548 8.886 < 2e-16 ***
## y.H1Support -1.4572 0.2693 -5.411 6.26e-08 ***
## z.G1Male -0.6436 0.2218 -2.901 0.00372 **
## x.I1Support:y.H1Support 0.8724 0.2841 3.071 0.00214 **
## x.I1Support:z.G1Male 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
#Dugaan
hasildugaan3<-round(fitted(model3),2)
data.frame(z.G,x.I,y.H,counts,hasildugaan3)## z.G x.I y.H counts hasildugaan3
## 1 1Male 1Support 1Support 76 84.44
## 2 1Male 1Support 2Oppose 160 151.56
## 3 1Male 2Oppose 1Support 6 5.86
## 4 1Male 2Oppose 2Oppose 25 25.14
## 5 2Female 1Support 1Support 114 105.56
## 6 2Female 1Support 2Oppose 181 189.44
## 7 2Female 2Oppose 1Support 11 11.14
## 8 2Female 2Oppose 2Oppose 48 47.86
#Model (GH,GI,HI)
model4<-glm(counts~x.I+y.H+z.G+
x.I*y.H+x.I*z.G+y.H*z.G
,family=poisson(link="log"))
summary(model4)##
## Call:
## glm(formula = counts ~ x.I + y.H + z.G + x.I * y.H + x.I * z.G +
## y.H * z.G, 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.I1Support 1.3514 0.1575 8.578 < 2e-16 ***
## y.H1Support -1.3750 0.2750 -5.001 5.71e-07 ***
## z.G1Male -0.5976 0.2242 -2.666 0.00768 **
## x.I1Support:y.H1Support 0.8997 0.2852 3.155 0.00160 **
## x.I1Support:z.G1Male 0.4636 0.2406 1.927 0.05401 .
## y.H1Support:z.G1Male -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
#Dugaan
hasildugaan4<-round(fitted(model4),2)
data.frame(z.G,x.I,y.H,counts,hasildugaan4)## z.G x.I y.H counts hasildugaan4
## 1 1Male 1Support 1Support 76 76.91
## 2 1Male 1Support 2Oppose 160 159.09
## 3 1Male 2Oppose 1Support 6 5.09
## 4 1Male 2Oppose 2Oppose 25 25.91
## 5 2Female 1Support 1Support 114 113.09
## 6 2Female 1Support 2Oppose 181 181.91
## 7 2Female 2Oppose 1Support 11 11.91
## 8 2Female 2Oppose 2Oppose 48 47.09
Selanjutnya untuk menunjukkan model that lack the HI term fit poorly dilakukan uji hipotesis antara conditional model on G dengan homogenous model sebagai berikut:
summary(model4)##
## Call:
## glm(formula = counts ~ x.I + y.H + z.G + x.I * y.H + x.I * z.G +
## y.H * z.G, 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.I1Support 1.3514 0.1575 8.578 < 2e-16 ***
## y.H1Support -1.3750 0.2750 -5.001 5.71e-07 ***
## z.G1Male -0.5976 0.2242 -2.666 0.00768 **
## x.I1Support:y.H1Support 0.8997 0.2852 3.155 0.00160 **
## x.I1Support:z.G1Male 0.4636 0.2406 1.927 0.05401 .
## y.H1Support:z.G1Male -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
Nilai Z:
nilaiZ1<-qnorm(0.05/2,lower.tail = F)
nilaiZ1## [1] 1.959964
Nilai Standard Error:
seGH<-summary(model4)$coefficient[7,2]
seGH## [1] 0.1749361
Selang Kepercayaan:
Z1<- seGH*nilaiZ1
Z1## [1] 0.3428684
#Selang Kepercayaan 95% yang terbentuk untuk GH yaitu:
print(paste(exp(model4$coefficient[7]-Z1), "<= lambda <=", exp(model4$coefficient[7]+Z1))) ## [1] "0.551849969717742 <= lambda <= 1.09555131116043"
Jadi, dari hasil diatas dapat diperoleh bahwa 95% selang kepercayaan Wald sesuai dengan nilai pada soal yaitu (0.5518, 1.0956) untuk odds ratio GH (Gender dan Health care costs opinion). Artinya, dengan tingkat kepercayaan 95%, odds ratio GH terletak antara 0.55 dan 1.10. Interpretasi: Karena nilai odds ratio GH pada selang kepercayaan mengandung angka 1 maka masuk akal bila gender (G) tidak punya pengaruh nyata terhadap Health care costs opinion (H) pada kasus ini.
Selang Kepercayaan 95% Wald untuk odds ratio GI (Gender dan Information program opinion) sebagai berikut: Model (GH,GI,HI) merupakan model homogenous sehingga kita dapat menggunakan model 4 pada syntax yang digunakan,
Selang kepercayaan 95 % wald dihitung dengan rumus: \[
\exp(\hat{\lambda}\pm Z_{\alpha /2}(SE))
\]
Diketahui:
\(Z_{\alpha /2}=Z_{0.05/2}=1.96\)
\(SE=\text{standard error untuk GI= }0.240615\)
atau dengan program sebagai berikut:
Nilai Z:
nilaiZ2<-qnorm(0.05/2,lower.tail = F)
nilaiZ2## [1] 1.959964
Nilai Standar Error:
seGI<-summary(model4)$coefficient[6,2]
seGI## [1] 0.240615
Selang Kepercayaan:
Z2<- seGI*nilaiZ2
Z2## [1] 0.4715968
#Selang Kepercayaan 95% yang terbentuk untuk GH yaitu:
print(paste(exp(model4$coefficient[6]-Z2), "<= lambda <=", exp(model4$coefficient[6]+Z2))) ## [1] "0.9920474547683 <= lambda <= 2.54774646862082"
Sehingga berdasarkan hasil selang kepercayaan yang diperoleh bagi GH dan GI diperoleh nilai selang kepercayaan yang mengandung angka 1 maka dapat dikatakan gender (G) tidak berpengaruh terhadap opini dalam kasus ini