Analisis Data Kategorik - kusmansadik.files.wordpress.com · 10.11.2017 · Misalkan ada tiga...

Preview:

Citation preview

Model Log-Linear(Bagian 2)

Dr. Kusman Sadik, M.Si

Program Studi Magister (S2)

Departemen Statistika IPB, 2017/2018

2

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:

3

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

4

Lihat : Azen, hlm. 145

5

** 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 <- relevel(z.gen, ref="2Fem")

x.rel <- relevel(x.rel, ref="3Con")

y.god <- 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)

6

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

7

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

8

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

9

10

11

12

13

To determine whether the three-way interaction term in the

saturated model

H1: ≠ 0

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

18

19

20

21

22

23

1. Gunakan Program R untuk menyelesaikan Problem 7.1 (Azen,

hlm.177) .

24

25

2. Gunakan Program R untuk menyelesaikan Problem 8.1 (Agresti,

hlm. 347) .

26

27

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 2nd. New

York: Wiley.

3. Pustaka lain yang relevan.

28

Bisa di-download di

kusmansadik.wordpress.com

29

Terima Kasih

Recommended