How to change the cut point (cut-off) in glm function?

Asked

Viewed 49 times

4

I have the segiunte database, where I intend to do a logistic regression:

set.seed(1)

dataset <- data.frame(
  x = replicate(6, runif(30, 20, 100)), 
  y = as.factor(sample(0:1, 30, replace = TRUE))
)

Consider the function:

my <- glm(y ~ x.1, family = binomial, data = dataset)
summary(my)
  • Is it possible to modify the cut-off point of the analysis? By default, it comes with .5.

1 answer

4


After adjusting the template, create a vector with the predicted probabilities. For example,

predict(my, newdata = dataset, type = "response")
##         1         2         3         4         5         6         7         8 
## 0.5939177 0.5464655 0.6365774 0.6446637 0.6239940 0.5303579 0.5328488 0.5466660 
##         9        10        11        12        13        14        15        16 
## 0.5503314 0.5417098 0.6458154 0.6415483 0.5260277 0.6029462 0.5471655 0.5380448 
##        17        18        19        20        21        22        23        24 
## 0.5302498 0.5838713 0.6385566 0.5903019 0.5627473 0.5493866 0.4831309 0.5645080 
##        25        26        27        28        29        30 
## 0.6018940 0.5328032 0.4676268 0.4963086 0.5694663 0.5800685

With this created probability vector, it is possible to establish any desired criterion so that the response variable is classified as a positive result. Below I set cutoff points at 0.1, 0.5 and 0.8:

ifelse(predict(my, newdata = dataset, type = "response") > 0.1, 1, 0)
##  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 
##  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1 
## 28 29 30 
##  1  1  1 
ifelse(predict(my, newdata = dataset, type = "response") > 0.5, 1, 0)
##  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 
##  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  0  1  1  1  0 
## 28 29 30 
##  0  1  1 
ifelse(predict(my, newdata = dataset, type = "response") > 0.8, 1, 0)
##  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 
##  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
## 28 29 30 
##  0  0  0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.