ron-r
3/27/2014 - 12:49 PM

From http://stats.stackexchange.com/questions/4830/better-classification-of-default-in-logistic-regression

m <- glm(default ~ (age + employ + address + income + debtinc + 
                    creddebt + othdebt + ed)^2,
   family=binomial(), data=df)
p <- predict(m, newdata=df, type="response")

getMisclass <- function(cutoff, p, labels){
   pred <- factor(1*(p > cutoff), labels=c("No Default", "Default")) 
   t <- table(pred, labels)
   cat("cutoff ", cutoff, ":\n")
   print(t)
   cat("correct    :", round(sum(t[c(1,4)])/sum(t), 2),"\n")
   cat("correct No :", round(t[1]/sum(t[,1]), 2),"\n")
   cat("correct Yes:", round(t[4]/sum(t[,2]), 2),"\n\n")
   invisible(t)
}
cutoffs <- seq(.1,.9,by=.1)
sapply(cutoffs, getMisclass, p=p, labels=df$default)