Model Log-Linear (Bagian 2) Dr. Kusman Sadik, M.Si Program Studi Pascasarjana Departemen Statistika IPB, 2018/2019
When fitting log-linear models to higher-way tables it is typical to only consider models that are hierarchical in nature. These are models that include all lower-order terms for variables involved in higher-order terms in the model. For a three-way contingency table, with variables X, Y, and Z, the saturated model includes all main effects, all two-way interactions and the three-way interaction, and is represented symbolically as follows: 2
Exp( ) merupakan nilai odds antara kategori pada baris ke-i dengan kategori baris terakhir. Exp( ) merupakan nilai rasio odds antara odds kategori pada baris ke-i dengan kategori baris terakhir dengan odds kategori pada kolom ke-j dengan kategori kolom terakhir 3
Lihat : Azen, hlm. 145 4
** Model Log-Linear untuk Data Tabel 7.4 (Azen, hlm.145) ** ** relevel --> Memilih Kategori Referensi ** ** Model 1 : Interaksi XY XZ YZ ** z.gen <- factor(rep(c("1mal","2fem"),each=3, times=3)) x.rel <- factor(rep(c("1lib","2mod","3con"),each=1, times=6)) y.god <- factor(rep(c("1y","2n","3u"),each=6,times=1)) count <- c(26,82,202,44,113,180,121,128,75,221, 204,124,24,52,74,32,49,43) z.gen x.rel y.god <- relevel(z.gen, ref="2fem") <- relevel(x.rel, ref="3con") <- relevel(y.god, ref="3u") data.frame(z.gen, x.rel, y.god, count) model <- glm(count ~ x.rel + y.god + z.gen + x.rel*y.god + x.rel*z.gen + y.god*z.gen, family=poisson("link"=log)) summary(model) dugaan <- round(fitted(model),2) data.frame(z.gen, x.rel, y.god, count, dugaan) 5
z.gen x.rel y.god count 1 1Mal 1Lib 1Y 26 2 1Mal 2Mod 1Y 82 3 1Mal 3Con 1Y 202 4 2Fem 1Lib 1Y 44 5 2Fem 2Mod 1Y 113 6 2Fem 3Con 1Y 180 7 1Mal 1Lib 2N 121 8 1Mal 2Mod 2N 128 9 1Mal 3Con 2N 75 10 2Fem 1Lib 2N 221 11 2Fem 2Mod 2N 204 12 2Fem 3Con 2N 124 13 1Mal 1Lib 3U 24 14 1Mal 2Mod 3U 52 15 1Mal 3Con 3U 74 16 2Fem 1Lib 3U 32 17 2Fem 2Mod 3U 49 18 2Fem 3Con 3U 43 6
Call: glm(formula = count ~ x.rel + y.god + z.gen + x.rel * y.god + x.rel * z.gen + y.god * z.gen, family = poisson(link = log)) Coefficients: Estimate Std. Error z value Pr(> z ) (Intercept) 3.862595 0.122713 31.477 < 2e-16 *** x.rel1lib -0.511037 0.177163-2.885 0.003920 ** x.rel2mod 0.005771 0.150379 0.038 0.969388 y.god1y 1.367890 0.134994 10.133 < 2e-16 *** y.god2n 0.860606 0.140582 6.122 9.26e-10 *** z.gen1mal 0.377454 0.136017 2.775 0.005519 ** x.rel1lib:y.god1y -0.994715 0.209026-4.759 1.95e-06 *** x.rel2mod:y.god1y -0.548065 0.162483-3.373 0.000743 *** x.rel1lib:y.god2n 1.212754 0.186792 6.493 8.44e-11 *** x.rel2mod:y.god2n 0.615654 0.163938 3.755 0.000173 *** x.rel1lib:z.gen1mal -0.416543 0.131545-3.167 0.001543 ** x.rel2mod:z.gen1mal -0.272968 0.114568-2.383 0.017191 * y.god1y:z.gen1mal -0.334342 0.146372-2.284 0.022360 * y.god2n:z.gen1mal -0.640833 0.142437-4.499 6.83e-06 *** --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05. 0.1 1 Null deviance: 724.8365 on 17 degrees of freedom Residual deviance: 6.5154 on 4 degrees of freedom AIC: 146.38 7
z.gen x.rel y.god count dugaan 1 1Mal 1Lib 1Y 26 28.54 2 1Mal 2Mod 1Y 82 86.34 3 1Mal 3Con 1Y 202 195.12 4 2Fem 1Lib 1Y 44 41.46 5 2Fem 2Mod 1Y 113 108.66 6 2Fem 3Con 1Y 180 186.88 7 1Mal 1Lib 2N 121 115.01 8 1Mal 2Mod 2N 128 122.52 9 1Mal 3Con 2N 75 86.47 10 2Fem 1Lib 2N 221 226.99 11 2Fem 2Mod 2N 204 209.48 12 2Fem 3Con 2N 124 112.53 13 1Mal 1Lib 3U 24 27.45 14 1Mal 2Mod 3U 52 53.14 15 1Mal 3Con 3U 74 69.41 16 2Fem 1Lib 3U 32 28.55 17 2Fem 2Mod 3U 49 47.86 18 2Fem 3Con 3U 43 47.59 8
9
10
Odds X=1 Y=1 = P(X=1 Y=1)/P(X=3 Y=1) Odds X=1 Y=3 P(X=1 Y=3)/P(X=3 Y=3) 11
12
To determine whether the three-way interaction term in the saturated model H 1 : 0 13
Call: glm(formula = count ~ x.rel + y.god + z.gen + x.rel * y.god + x.rel * z.gen + y.god * z.gen + x.rel * y.god * z.gen, family = poisson(link = log)) Null deviance: 7.2484e+02 on 17 degrees of freedom Residual deviance: -4.6851e-14 on 0 degrees of freedom AIC: 147.86 14
Call: glm(formula = count ~ x.rel + y.god + z.gen + x.rel * y.god + x.rel * z.gen + y.god * z.gen, family = poisson(link = log)) Coefficients: Estimate Std. Error z value Pr(> z ) (Intercept) 3.862595 0.122713 31.477 < 2e-16 *** x.rel1lib -0.511037 0.177163-2.885 0.003920 ** x.rel2mod 0.005771 0.150379 0.038 0.969388 y.god1y 1.367890 0.134994 10.133 < 2e-16 *** y.god2n 0.860606 0.140582 6.122 9.26e-10 *** z.gen1mal 0.377454 0.136017 2.775 0.005519 ** x.rel1lib:y.god1y -0.994715 0.209026-4.759 1.95e-06 *** x.rel2mod:y.god1y -0.548065 0.162483-3.373 0.000743 *** x.rel1lib:y.god2n 1.212754 0.186792 6.493 8.44e-11 *** x.rel2mod:y.god2n 0.615654 0.163938 3.755 0.000173 *** x.rel1lib:z.gen1mal -0.416543 0.131545-3.167 0.001543 ** x.rel2mod:z.gen1mal -0.272968 0.114568-2.383 0.017191 * y.god1y:z.gen1mal -0.334342 0.146372-2.284 0.022360 * y.god2n:z.gen1mal -0.640833 0.142437-4.499 6.83e-06 *** --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05. 0.1 1 Null deviance: 724.8365 on 17 degrees of freedom Residual deviance: 6.5154 on 4 degrees of freedom AIC: 146.38 15
Call: glm(formula = count ~ x.rel + y.god + z.gen + x.rel * z.gen + y.god * z.gen, family = poisson(link = log)) Coefficients: Estimate Std. Error z value Pr(> z ) (Intercept) 3.75190 0.09978 37.601 < 2e-16 *** x.rel1lib -0.15559 0.07905-1.968 0.049035 * x.rel2mod 0.05331 0.07493 0.711 0.476792 y.god1y 0.99980 0.10503 9.519 < 2e-16 *** y.god2n 1.48782 0.09943 14.964 < 2e-16 *** z.gen1mal 0.45511 0.13489 3.374 0.000741 *** x.rel1lib:z.gen1mal -0.56353 0.12225-4.610 4.04e-06 *** x.rel2mod:z.gen1mal -0.34575 0.11081-3.120 0.001808 ** y.god1y:z.gen1mal -0.27386 0.14465-1.893 0.058324. y.god2n:z.gen1mal -0.71771 0.14014-5.121 3.03e-07 *** --- Null deviance: 724.84 on 17 degrees of freedom Residual deviance: 256.75 on 8 degrees of freedom AIC: 388.61 16
Nilai deviance dapat digunakan untuk menguji hipotesis ada tidaknya hubungan suatu variabel dengan variabel lainnya. Misalkan ada tiga variabel X, Y, dan Z. Untuk menguji apakah ada hubungan antara X dengan Y, dapat dilakukan dengan membandingkan nilai deviance model (X, Y, Z, XY, XZ, YZ) dengan nilai deviance model (X, Y, Z, XZ, YZ). Jika dari uji hipotesis tersebut menerima model (X, Y, Z, XY, XZ, YZ) maka dapat disimpulkan bahwa ada hubungan yang signifikan antara X dan Y. 17
Model 1 : Deviance: 6.5154 on 4 degrees of freedom AIC : 146.38 Model 2 : Deviance: 256.75 on 8 degrees of freedom AIC : 388.61 Apa kesimpulan dari uji deviance tersebut? 18
χ 2 (α, db) : qchisq(α, db, lower.tail=false) > qchisq(0.05, 4, lower.tail=false) [1] 9.487729 Jadi χ 2 (α = 0.05, db = 4) = 9.497729 19
20
21
22
23
24
25
1. Gunakan Program R untuk menyelesaikan Problem 7.1 (Azen, hlm.177). 26
27
2. Gunakan Program R untuk menyelesaikan Problem 8.1 (Agresti, hlm. 347). 28
29
Pustaka 1. Azen, R. dan Walker, C.R. (2011). Categorical Data Analysis for the Behavioral and Social Sciences. Routledge, Taylor and Francis Group, New York. 2. Agresti, A. (2002). Categorical Data Analysis 2 nd. New York: Wiley. 3. Pustaka lain yang relevan. 30
Bisa di-download di kusmansadik.wordpress.com 31
Terima Kasih 32