0

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

  • Hi! Could you include a [minimal reproducible example?](https://stackoverflow.com/help/minimal-reproducible-example). Please at least include some data (`dput()`) and which error is returning when you apply the function – Jose Dec 13 '21 at 12:49
  • Hi i have edited my question, Thank you @Jose – Jasmine Helen Dec 15 '21 at 08:49

0 Answers0