regresi logistik ii - wordpress.com...2018/12/12  · 29 1. gunakan program r untuk data horseshoe...

34
Regresi Logistik II (Peubah Bebas : Kategorik) Dr. Kusman Sadik, M.Si Program Studi Pascasarjana Departemen Statistika IPB, 2018/2019

Upload: others

Post on 24-Dec-2019

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

Regresi Logistik II

(Peubah Bebas : Kategorik)

Dr. Kusman Sadik, M.Si

Program Studi Pascasarjana

Departemen Statistika IPB, 2018/2019

Page 2: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

2

In the case of logistic regression, the response variable

is a binary or dichotomous variable, which means it

can only take on one of two possible values.

Case: logistic regression models in which the

predictors are categorical or qualitative variables (such

as gender, location, and socioeconomic status).

All of the material on logistic regression modeling remains

the same, but the coding of the predictors (dummy

coding) and interpretation of the regression coefficients

changes due to the categorical nature of the predictors.

Page 3: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

3

The interpretation of the model parameters

(intercept, slope) discussed for continuous predictor

variables does not change fundamentally for

categorical predictor variables.

The main difference between quantitative or

continuous predictors and qualitative or

categorical predictors is that the latter need to be

coded such that (C – 1) indicator variables are

required to represent a total of C categories.

Page 4: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

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.

Page 5: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

5

Page 6: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

6

Page 7: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

7

Page 8: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

8

Page 9: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

9

Page 10: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

10

Page 11: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

11

Page 12: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

12

Page 13: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

13

Inferensia

Page 14: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

14

Catatan : Uji G2 sama dengan Uji Deviance

Page 15: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

15

Page 16: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

16

Pengaruh Interaksi

Page 17: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

17

Page 18: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

18

Gender SES Interaksi

Page 19: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

19

Page 20: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

20

Page 21: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

21

Page 22: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

22

* Model Logistik untuk Data Horseshoe Crab (Agresti, 5.4.4) *

dataku <- read.csv(file="Data-Horseshoe.Crab-Agresti.csv")

c <- factor(dataku[,1])

s <- factor(dataku[,2])

w <- dataku[,3]

wt <- dataku[,4]

sa <- dataku[,5]

y <- c(1:173)

for (i in 1:length(sa)) {

if (sa[i] > 0) (y[i] = 1) else (y[i] = 0)

}

color <- relevel(c, ref="4")

width <- w

data.frame(color,s,width,wt,sa,y)

model <- glm(y ~ color+width, family=binomial("link"=logit))

summary(model)

dugaan <- round(fitted(model),2)

data.frame(color,width,y,dugaan)

Page 23: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

23

Call:

glm(formula = y ~ color+width, family = binomial(link =

logit))

Coefficients:

Estimate Std. Error z value Pr(>|z|)

Intercept -12.7151 2.7617 -4.604 4.14e-06 ***

color1 1.3299 0.8525 1.560 0.1188

color2 1.4023 0.5484 2.557 0.0106 *

color3 1.1061 0.5921 1.868 0.0617 .

width 0.4680 0.1055 4.434 9.26e-06 ***

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’

Null deviance: 225.76 on 172 degrees of freedom

Residual deviance: 187.46 on 168 degrees of freedom

AIC: 197.46

Page 24: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

24

color width y dugaan

1 2 28.3 1 0.87

2 3 26.0 1 0.64

3 3 25.6 0 0.59

4 4 21.0 0 0.05

5 2 29.0 1 0.91

6 1 25.0 1 0.58

7 4 26.2 0 0.39

8 2 24.9 0 0.58

.

.

.

171 2 26.5 1 0.75

172 3 26.1 1 0.65

173 2 24.5 0 0.54

Page 25: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

25

Page 26: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

26

Page 27: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

27

H0 : β1 = β2 = β3 = 0

Call: H0glm(formula = y ~ width, family = binomial(link = logit))

Null deviance : 225.76 on 172 degrees of freedom

Residual deviance: 194.45 on 171 degrees of freedom

AIC: 198.45

Call: H1glm(formula = y ~ color + width, family = binomial(link =

logit))

Null deviance : 225.76 on 172 degrees of freedom

Residual deviance: 187.46 on 168 degrees of freedom

AIC: 197.46

Apa kesimpulan dari uji deviance tersebut?

Page 28: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

28

Page 29: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

29

1. Gunakan Program R untuk data Horseshoe Crabs Revisited

(Agresti, sub-bab 5.4.4 ) .

a. Lakukan pemodelan regresi logistik dengan peubah bebasnya

adalah Width (x) dan Color (c). Bandingkan hasil output R

dengan output SAS di dalam buku Agresti. Jelaskan

interpretasinya.

b. Lakukan pemodelan regresi logistik dengan peubah bebasnya

adalah Width (x), Color (c), dan Spine (s), tanpa interaksi.

Apakah Spine berpengaruh nyata? Gunakan uji Deviance

untuk = 0.05.

c. Pada model bagian (b) di atas, lalukan uji Deviance pada

= 0.05 untuk mengetahui apakah ada interaksi antara Color

dan Spine. Jelaskan interpretasinya.

Page 30: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

30

2. Gunakan Program R untuk menyelesaikan Problems 9.5 (Azen,

hlm. 241 ) .

Page 31: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

31

Page 32: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

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

York: Wiley.

3. Pustaka lain yang relevan.

Page 33: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

33

Bisa di-download di

kusmansadik.wordpress.com

Page 34: Regresi Logistik II - WordPress.com...2018/12/12  · 29 1. Gunakan Program R untuk data Horseshoe Crabs Revisited (Agresti, sub-bab 5.4.4 ) . a. Lakukan pemodelan regresi logistik

34

Terima Kasih