3
$\begingroup$

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()

enter image description here

$\endgroup$
4
$\begingroup$

The probability of 'success' is what's being modelled, in glm & in a fairly common terminology: though it really doesn't matter; you get equivalent models however you code the different levels of the response (the coefficients simply switch sign).

In any case, the way you've set it up in your example bad is the first level ('failure')—good is therefore 'success'. And even if you're modelling the probability of something bad—a production defect, a death—you don't have to call it a success, you can just call it what it is.

| cite | improve this answer | |
$\endgroup$
3
$\begingroup$

Which level of a two-level dependent variable is called "success" and which is "failure" is fairly arbitrary, from the point of view of the statistics. From your code, it is clear you had the success/failure variable coded as 2 = bad and 1 = good. You could just as easily have coded it 2 = good and 1 = bad. Then it would line up with your intuition.

As long as you know what the software is doing, it's not a problem.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.