1

I want to find a threshold value so I can classify which observation is classified to be sucess or not. But I am a confused about how to use the package for logistic regression. For example my glm model is

library(vcd)
library(ggplot2)
library(dplyr)
library(MLmetrics)
library(pROC)
d=read.delim("http://dnett.github.io/S510/Disease.txt")
d$disease=factor(d$disease)
d$ses=factor(d$ses)
d$sector=factor(d$sector)

model=glm(disease~age+sector, family=binomial(link=logit), data=d)

Where success is defined as disease = 1. Here we have sector as a categorical variable. When we want to produce a confusion matrix then we have to find the threshold value.

pred = factor(ifelse(model$fitted.values<0.5,0,1)) #here i choose 0.5 as the threshold value
confussionMat=confusionMatrix(pred_d$disease)

So my question is, how can we find the threshold value with OptimalCutPoints package in R for my GLM model. In that package, I want to use Sensitivity Equal to Specitifity method. But I don't get how it works for GLM model. Thank you

  • It would be easier for us to help you if you could edit your question to include a [Minimal Working Example](https://stackoverflow.com/q/5963269/452096). Also, note that sensitivity and specificity suffer from similar problems as [accuracy](https://stats.stackexchange.com/q/312780/1352). It makes more sense to set thresholds [based on costs of decisions](https://stats.stackexchange.com/q/312119/1352). – Stephan Kolassa Dec 13 '21 at 07:05
  • I have edited my question, thank you – Jasmine Helen Dec 13 '21 at 08:23
  • Your code will not work for us, since we don't have your data. Consider creating your own (minimal!) dataset, or using one of the built-in ones. – Stephan Kolassa Dec 13 '21 at 08:27
  • Could you describe in plain English what you are trying to achieve? What you need the cutpoints for? – Tim Dec 13 '21 at 09:13
  • Probability models do not use cutpoints. Any cutpoints not based on formal utilities will be arbitrary. Probability models are about estimating _tendencies_. – Frank Harrell Dec 13 '21 at 13:49
  • I have edited my question with data (for example). I want to find the threshold value for predicting the outcome as success or not, based on method in OptimalCutPoints package. Thank you – Jasmine Helen Dec 15 '21 at 04:37

0 Answers0