Logistic regression - defining reference level in R

blast00 picture blast00 · Apr 25, 2014 · Viewed 23.5k times · Source

I am going nuts trying to figure this out. How can I in R, define the reference level to use in a binary logistic regression? What about the multinomial logistic regression? Right now my code is:

logistic.train.model3 <- glm(class~ x+y+z,
                         family=binomial(link=logit), data=auth, na.action = na.exclude)

my response variable is "YES" and "NO". I want to predict the probability of someone responding with "YES".

I DO NOT want to recode the variable to 0 / 1. Is there a way I can tell the model to predict "YES" ?

Thank you for your help.

Answer

smrt1119 picture smrt1119 · Apr 25, 2014

Assuming you have class saved as a factor, use the relevel() function:

auth$class <- relevel(auth$class, ref = "YES")