2021-06-20 11:57:11 +02:00
|
|
|
load(url("http://ls.home.amu.edu.pl/data_sets/liver_data.RData"))
|
|
|
|
head(liver_data)
|
2021-06-20 10:42:15 +02:00
|
|
|
|
2021-06-20 11:57:11 +02:00
|
|
|
liver_data$condition <- ifelse(liver_data$condition == "Yes", 1, 0)
|
|
|
|
model_1 <- glm(condition ~ bilirubin + ldh, data = liver_data, family = 'binomial')
|
|
|
|
model_1
|
2021-06-20 10:42:15 +02:00
|
|
|
|
2021-06-20 11:57:11 +02:00
|
|
|
summary(model_1)
|
2021-06-20 10:42:15 +02:00
|
|
|
|
2021-06-20 11:57:11 +02:00
|
|
|
step(model_1)
|
2021-06-20 10:42:15 +02:00
|
|
|
|
2021-06-20 11:57:11 +02:00
|
|
|
exp(coef(model_1)[2])
|
|
|
|
exp(coef(model_1)[3])
|
2021-06-20 10:42:15 +02:00
|
|
|
|
2021-06-20 11:57:11 +02:00
|
|
|
install.packages("ROCR")
|
|
|
|
library(ROCR)
|
|
|
|
pred_1 <- prediction(model_1$fitted, liver_data$condition)
|
|
|
|
plot(performance(pred_1, 'tpr', 'fpr'), main = "Model 1")
|
|
|
|
performance(pred_1, 'auc')@y.values
|
2021-06-20 10:42:15 +02:00
|
|
|
|
2021-06-20 11:57:11 +02:00
|
|
|
|
|
|
|
liver_data_new <- data.frame(bilirubin = c(0.9, 2.1, 3.4), ldh = c(100, 200, 300))
|
|
|
|
(predict_glm <- stats::predict(model_1,
|
|
|
|
liver_data_new,
|
|
|
|
type = 'response'))
|
|
|
|
model_1_hat <- coef(model_1)[1] +
|
|
|
|
coef(model_1)[2] * liver_data$bilirubin +
|
|
|
|
coef(model_1)[3] * liver_data$ldh
|
|
|
|
model_1_temp <- seq(min(model_1_hat) - 1, max(model_1_hat) + 2.5, length.out = 100)
|
|
|
|
condition_temp <- exp(model_1_temp) / (1 + exp(model_1_temp))
|
|
|
|
plot(model_1_temp, condition_temp, type = "l", xlab = "X beta", ylab = "condition",
|
|
|
|
xlim = c(-6, 9), ylim = c(-0.1, 1.1))
|
|
|
|
points(model_1_hat, liver_data$condition, pch = 16)
|
|
|
|
points(coef(model_1)[1] +
|
|
|
|
coef(model_1)[2] * liver_data_new$bilirubin +
|
|
|
|
coef(model_1)[3] * liver_data_new$ldh,
|
|
|
|
predict_glm, pch = 16, col = "red")
|