In documentation to glm
I read: "For binomial and quasibinomial families the response can also be specified as a factor (when the first level denotes failure and all others success)" Does it mean that probability of failure or success is being modeled?
I'm trying to apply simple logistic model to "german credit scoring" dataset where there are levels "good" and "bad". To get correct results (higher probability means higher likelihood of being good) I have to assume that Failure=Good
and Success=Bad
. This works, but it is really counterintuitive. I interpret this as - this will model probability of Failure (failed to be bad).
require(ggplot2)
german_data <- read.csv(file="http://archive.ics.uci.edu/ml/machine-learning-databases/statlog/german/german.data",
sep=" ", header=FALSE)
names(german_data) <- c('ca_status','mob','credit_history','purpose','credit_amount','savings',
'present_employment_since','status_sex','installment_rate_income','other_debtors',
'present_residence_since','property','age','other_installment','housing','existing_credits',
'job','liable_maintenance_people','telephone','foreign_worker','gb')
str(german_data)
german_data$gb <- factor(german_data$gb,levels=c(2,1),labels=c("bad","good"))
levels(german_data$gb)[1]
table(german_data$gb)
model <- glm(data=german_data,formula=gb~.,family=binomial(link="logit"))
german_data$prob <- predict(model,newdata=german_data, type="response")
ggplot(data=german_data) + geom_boxplot(aes(y=prob,x=gb)) + coord_flip()