Model Log-Linear (Bagian 1) Dr. Kusman Sadik, M.Si Program Studi Magister (S2) Departemen Statistika IPB, 2017/2018
Using a log-linear modeling approach is advantageous to conducting inferential tests of the associations in contingency tables because the models can handle more complicated situations. For example, the Breslow Day statistic is limited to 2x2xK tables and estimates of common odds ratios cannot be obtained for tables larger than 2x2. Conversely, a log-linear modeling approach is not restricted to two- or three-way tables so it can be used for testing homogeneous association and estimating common odds ratios in tables of any size. 2
Log-linear models are used to model the cell counts in contingency tables. The ultimate goal of fitting a log-linear model is to estimate parameters that describe the relationships between categorical variables. Specifically, for a set of categorical variables, log-linear models do not really distinguish between explanatory and response variables but rather treat all variables as response variables by modeling the cell counts for all combinations of the levels of the categorical variables included in the model. 3
In general, the number of parameters in a log-linear model depends on the number of categories of the variables of interest. More specifically, in any log-linear model the effect of a categorical variable with a total of C categories requires (C 1) unique parameters. For example, if variable X is gender (with two categories), then C = 2 and only one predictor, thus one parameter, is needed to model the effect of X. 4
When dummy coding is used, the last category of the variable is used as a reference category. Therefore, the parameter associated with the last category is set to zero, and each of the remaining parameters of the model is interpreted relative to the last category. For example, if male is the last category of the gender variable, then the one gender parameter in the log-linear model will be interpreted as the difference between females and males because the parameter reflects the odds for females relative to the reference category, males. 5
6
Instead of representing the parameter associated with the i th variable (X i ) as β i, in log-linear models this parameter is represented by the Greek letter lambda, λ, with the variable indicated in the superscript and the (dummy-coded) indicator of the variable in the subscript. For example, if the variable X has a total of I categories (i = 1, 2,, I), λ i x is the parameter associated with the i th indicator (dummy variable) for X. Similarly, if the variable Y has a total of J categories (j = 1, 2,, J), then λ jy is the parameter associated with the j th indicator for Y. 7
For two categorical variables, the expected cell counts, denoted by μ ij for the cell in the i th row and j th column, are the outcome values from a log-linear model. μij = Eij = (ni+) (n+j)/ (n++) 8
9
In general, main effects in log-linear models are interpreted as odds. The (exponentiated) parameter values associated with X, λ i x, can be interpreted as the odds of being in the i th row versus being in the last row of the table regardless of the value of the other variable, Y. Likewise, the (exponentiated) parameter values associated with Y, λ jy, can be interpreted as the odds of being in the j th column versus being in the last column of the table regardless of the value of the other variable, X. 10
Lihat : Azen, hlm. 140 11
i = 1, 2,..., k : kategori terakhir (i = k) sebagai referensi j = 1, 2,..., m : kategori terakhir (j = m) sebagai referensi λ i X = log odds i = log P X=i P X=k λ j Y = log odds j = log P Y=j P Y=m = log n i./n.. n k. /n.. = log n.j /n.. n.m /n.. 12
Data : Azen, Table.7.2 λ i X = log odds i = log P X=i P X=k = log n i./n.. n k. /n.. λ 1 X = log P X=1 P X=3 λ 2 X = log P X=2 P X=3 λ 3 X = log P X=3 P X=3 = log n 1./n.. = log 450/1776 n 3. /n.. 698/1776 = log n 2./n.. = log 628/1776 n 3. /n.. 698/1776 = log n 3./n.. n 3. /n.. = log 1 = 0 = 0.43897 = 0.10568 13
λ j Y = log odds j = log P Y=j P Y=m = log n.j /n.. n.m /n.. λ 1 Y = log P Y=1 P Y=3 λ 2 Y = log P Y=2 P Y=3 λ 3 Y = log P Y=3 P Y=3 = log n.1/n.. = log 647/1776 n.3 /n.. 274/1776 = log n.2/n.. = log 855/1776 n.3 /n.. 274/1776 = log n.3/n.. n.3 /n.. = log 1 = 0 = 0.859218 = 1.137973 14
Bagaimana menduga λ? Gunakan kategori terakhir untuk X dan Y, untuk data di atas (i=3 dan j=3), sehingga: log(μ 33 ) = λ, karena λ 3 X = λ 3 Y = 0 μ 33 = (n 3. ) (n.3 )/ (n.. ) = (274)(698)/(1776) = 107.6869 λ = log(μ 33 ) = log(107.6869) = 4.67923 15
16
17
18
Program R : Wajib Program SAS : Tambahan 19
** Model Log-Linear untuk Data Tabel 7.2 (Azen, hlm.140) ** ** relevel --> Memilih Kategori Referensi ** ** Model 1 : Tanpa Interaksi ** pol <- factor(rep(c("1lib","2mod","3con"),3)) pre <- factor(rep(c("1bus","2cli","3per"),rep(3,3))) count <- c(70, 195, 382, 324, 332, 199, 56, 101, 117) pol pre <- relevel(pol, ref="3con") <- relevel(pre, ref="3per") data.frame(pol, pre, count) model1 <- glm(count ~ pol + pre, family=poisson("link"=log)) summary(model1) dugaan <- round(fitted(model1),2) data.frame(pol,pre, count, dugaan) 20
pol pre count 1 1Lib 1Bus 70 2 2Mod 1Bus 195 3 3Con 1Bus 382 4 1Lib 2Cli 324 5 2Mod 2Cli 332 6 3Con 2Cli 199 7 1Lib 3Per 56 8 2Mod 3Per 101 9 3Con 3Per 117 21
Coefficients: Estimate Std. Error z value Pr(> z ) (Intercept) 4.67923 0.06723 69.605 < 2e-16 *** pol1lib -0.43897 0.06045-7.261 3.84e-13 *** pol2mod -0.10568 0.05500-1.921 0.0547. pre1bus 0.85922 0.07208 11.921 < 2e-16 *** pre2cli 1.13797 0.06942 16.392 < 2e-16 *** --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05. 0.1 1 (Dispersion parameter for poisson family taken to be 1) Null deviance: 626.32 on 8 degrees of freedom Residual deviance: 247.70 on 4 degrees of freedom AIC: 320 22
pol pre count dugaan 1 1Lib 1Bus 70 163.94 2 2Mod 1Bus 195 228.78 3 3Con 1Bus 382 254.28 4 1Lib 2Cli 324 216.64 5 2Mod 2Cli 332 302.33 6 3Con 2Cli 199 336.03 7 1Lib 3Per 56 69.43 8 2Mod 3Per 101 96.89 9 3Con 3Per 117 107.69 23
When there is evidence for dependency between the row and column variables of a two-way table, the dependency is modeled using two-way interaction terms in the log-linear modeling framework. However, fitting a log-linear model with a two-way interaction to a two-way contingency table is analogous to fitting the saturated model. To illustrate the saturated model using the previous example: 24
25
26
** Model Log-Linear untuk Data Tabel 7.2 (Azen, hlm.140) ** ** relevel --> Memilih Kategori Referensi ** ** Model 2 : Ada Interaksi ** pol <- factor(rep(c("1lib","2mod","3con"),3)) pre <- factor(rep(c("1bus","2cli","3per"),rep(3,3))) count <- c(70, 195, 382, 324, 332, 199, 56, 101, 117) pol pre <- relevel(pol, ref="3con") <- relevel(pre, ref="3per") data.frame(pol, pre, count) Model1 <- glm(count ~ pol + pre + pol*pre, family=poisson("link"=log)) summary(model1) dugaan <- round(fitted(model1),2) data.frame(pol,pre, count, dugaan) 27
Coefficients: Estimate Std. Error z value Pr(> z ) (Intercept) 4.76217 0.09245 51.511 < 2e-16 *** pol1lib -0.73682 0.16249-4.534 5.77e-06 *** pol2mod -0.14705 0.13582-1.083 0.27895 pre1bus 1.18325 0.10566 11.198 < 2e-16 *** pre2cli 0.53113 0.11650 4.559 5.14e-06 *** pol1lib:pre1bus -0.96010 0.20810-4.614 3.96e-06 *** pol2mod:pre1bus -0.52537 0.16185-3.246 0.00117 ** pol1lib:pre2cli 1.22426 0.18578 6.590 4.41e-11 *** pol2mod:pre2cli 0.65888 0.16274 4.049 5.15e-05 *** --- Signif.codes: 0 *** 0.001 ** 0.01 * 0.05. 0.1 1 (Dispersion parameter for poisson family taken to be 1) Null deviance: 6.2632e+02 on 8 degrees of freedom Residual deviance: 9.5701e-14 on 0 degrees of freedom AIC: 80.301 28
29
1. Gunakan Program R untuk menganalisis data yang terdapat pada Tabel 7.2 (Azen, hlm.140) : a. Lakukan pemodelan log-linear dengan menjadikan Conservative dan Perot sebagai pembanding/referensi. Apa interpretasinya? b. Lakukan pemodelan log-linear dengan menjadikan Liberal dan Bush sebagai pembanding/referensi. Apa interpretasinya? c. Berdasarkan dua pendekatan tersebut (a dan b), tentukan penduga bagi ij, untuk i = 1, 2, 3 dan j = 1, 2, 3. Apakah hasilnya berbeda antara (a) dan (b) di atas? d. Lakukan uji hipotesis untuk mengetahui ada tidaknya hubungan antara afiliasi politik dengan pilihan menggunakan model penuh (saturated model). Apa kesimpulan Anda? 30
2. Gunakan Program R untuk melakukan analisis data pada Tabel 2 dibawah ini: a. Tentukan model log-linear dan dugaan parameternya. Apa interpretasinya? b. Berdasarkan model tersebut, tentukan penduga bagi ij, untuk i = 1, 2, 3 dan j = 1, 2, 3, 4. c. Lakukan uji hipotesis untuk mengetahui ada tidaknya hubungan antara afiliasi politik dengan umur menggunakan model penuh (saturated model). Apa kesimpulan Anda? 31
2. 32
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. 33
Bisa di-download di kusmansadik.wordpress.com 34
Terima Kasih 35