Tugas Praktikum GLM - Model Linier Terampat untuk Peubah Respon Biner
Latihan 5.38 (Agresti,2015, hal.201)
Adapun data yang akan digunakan dalam latihan ini yaitu:
Dalam mengerjakan soal diatas, maka akan dilakukan tahapan sebagai berikut:
Import Data
library(readxl)
mydata <- read_excel("D:/Pascasarjana/Semester 3/Responsi GLM/data08.xlsx")
mydata## # A tibble: 35 x 4
## Patient d t y
## <dbl> <dbl> <dbl> <dbl>
## 1 1 45 0 0
## 2 2 15 0 0
## 3 3 40 0 1
## 4 4 83 1 1
## 5 5 90 1 1
## 6 6 25 1 1
## 7 7 35 0 1
## 8 8 65 0 1
## 9 9 95 0 1
## 10 10 35 0 1
## # ... with 25 more rows
A. Melakukan Pemodelan
Pemodelan dilakukan dengan menggunakan tiga fungsi hubung yaitu:
1). Logit
logit <- glm( y~ + d + t, family=binomial(link="logit"), data=mydata)
summary(logit)##
## Call:
## glm(formula = y ~ +d + t, family = binomial(link = "logit"),
## data = mydata)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.3802 -0.5358 0.3047 0.7308 1.7821
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -1.41734 1.09457 -1.295 0.19536
## d 0.06868 0.02641 2.600 0.00931 **
## t -1.65895 0.92285 -1.798 0.07224 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 46.180 on 34 degrees of freedom
## Residual deviance: 30.138 on 32 degrees of freedom
## AIC: 36.138
##
## Number of Fisher Scoring iterations: 5
2). Probit
probit <- glm( y~ + d + t, family=binomial(link="probit"), data=mydata)
summary(probit)##
## Call:
## glm(formula = y ~ +d + t, family = binomial(link = "probit"),
## data = mydata)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.3736 -0.5461 0.2972 0.7679 1.7562
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.85469 0.61783 -1.383 0.16655
## d 0.03953 0.01387 2.849 0.00438 **
## t -0.92641 0.51986 -1.782 0.07474 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 46.180 on 34 degrees of freedom
## Residual deviance: 30.341 on 32 degrees of freedom
## AIC: 36.341
##
## Number of Fisher Scoring iterations: 6
3). C-log-log
cloglog <- glm( y~ + d + t, family=binomial(link="cloglog"), data=mydata)
summary(cloglog)##
## Call:
## glm(formula = y ~ +d + t, family = binomial(link = "cloglog"),
## data = mydata)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.3453 -0.7006 0.2906 0.8374 1.6051
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -1.22937 0.64156 -1.916 0.05534 .
## d 0.03674 0.01328 2.765 0.00568 **
## t -0.82034 0.54380 -1.509 0.13142
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 46.180 on 34 degrees of freedom
## Residual deviance: 31.716 on 32 degrees of freedom
## AIC: 37.716
##
## Number of Fisher Scoring iterations: 8
B. Menentukan Model Terbaik
dalam menentukan nilai terbaik dapat dilihat dari nilai AIC dan ROC.
Nilai AIC
Adapun Nilai AIC berdasarkan hasil pemodelan diatas adalah sebagai berikut:
Berdasarkan nilai AIC maka nilai terbaik adalahn yang memiliki nilai AIC terkecil yaitu model Logit.
Kurva ROC
Adapun Kurva ROC untuk masing masing model adalah sebagai berikut:
1) ROC model Logit
library(ROCR)## Warning: package 'ROCR' was built under R version 4.1.3
pred.logit<-prediction(fitted(logit),mydata$y)
perf.logit<-performance(pred.logit,"tpr","fpr")
plot(perf.logit)2) ROC model Probit
pred.probit<-prediction(fitted(probit),mydata$y)
perf.probit<-performance(pred.probit,"tpr","fpr")
plot(perf.probit)3) ROC model C-log-log
pred.cloglog<-prediction(fitted(cloglog),mydata$y)
perf.cloglog<-performance(pred.cloglog,"tpr","fpr")
plot(perf.cloglog)C. Interpretasi Model Terbaik
Berdasarkan tahapan sebelumnya, diperoleh model terbaik adalah dengan menggunalan model logit, sehingga dapat di tuliskan kedalam model sebagai berikut:
selanjutnya untuk melakukan interpretasi maka akan dilakukan penurunan terhadap Xij sehingga di peroleh persamaan sebagai berikut: