# Menampilkan 50 data pertama dari total 500 data
# untuk melihat karakteristik data yang dibangkitkan
dataku <- data.frame(x,y,n,p)
head(dataku,50)
# Perbandingan link-function
# ketika Y menyebar ExactBinomial
model_logit <- glm(y_data ~ x, family=binomial(link="logit"))
model_probit <- glm(y_data ~ x, family=binomial(link="probit"))
model_cloglog <- glm(y_data ~ x, family=binomial(link="cloglog"))
summary(model_logit)
##
## Call:
## glm(formula = y_data ~ x, family = binomial(link = "logit"))
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 1.57475 0.05086 30.96 <2e-16 ***
## x 2.55874 0.06109 41.89 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 6088.38 on 499 degrees of freedom
## Residual deviance: 374.71 on 498 degrees of freedom
## AIC: 994.54
##
## Number of Fisher Scoring iterations: 6
##
## Call:
## glm(formula = y_data ~ x, family = binomial(link = "probit"))
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.84949 0.02625 32.37 <2e-16 ***
## x 1.39915 0.02979 46.97 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 6088.38 on 499 degrees of freedom
## Residual deviance: 403.53 on 498 degrees of freedom
## AIC: 1023.4
##
## Number of Fisher Scoring iterations: 6
##
## Call:
## glm(formula = y_data ~ x, family = binomial(link = "cloglog"))
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.29645 0.02196 13.50 <2e-16 ***
## x 1.26015 0.02958 42.61 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 6088.38 on 499 degrees of freedom
## Residual deviance: 638.96 on 498 degrees of freedom
## AIC: 1258.8
##
## Number of Fisher Scoring iterations: 9
# Menghitung metrik evaluasi
library(caret)
conf_logit <- confusionMatrix(factor(pred_logit), factor(data_ind$y), positive = "1")
conf_probit <- confusionMatrix(factor(pred_probit), factor(data_ind$y), positive = "1")
conf_cloglog <- confusionMatrix(factor(pred_cloglog), factor(data_ind$y), positive = "1")
hasil <- data.frame(
Model = c("Logit", "Probit", "Cloglog"),
Sensitivitas = c(conf_logit$byClass["Sensitivity"],
conf_probit$byClass["Sensitivity"],
conf_cloglog$byClass["Sensitivity"]),
Akurasi = c(conf_logit$overall["Accuracy"],
conf_probit$overall["Accuracy"],
conf_cloglog$overall["Accuracy"]),
Presisi = c(conf_logit$byClass["Precision"],
conf_probit$byClass["Precision"],
conf_cloglog$byClass["Precision"]),
F1_Score = c(conf_logit$byClass["F1"],
conf_probit$byClass["F1"],
conf_cloglog$byClass["F1"])
)