Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ordering in Logistic Regression

Tags:

r

In logistic regression SAS has the option to model 1 rather than 0 using "descending" option. Is there any method in R, where we can do the same thing?

The code I'm using is the following:

glm(y~x1+x2+x3, family=binomial(link="logit"), na.action=na.pass)

Regards, Ari

like image 978
Beta Avatar asked Feb 23 '23 10:02

Beta


1 Answers

The option is exactly the same as modeling 1-y, and will return the same coefficients but with a different sign. So either you put 1-y in the model, or you just invert your coefficients :

Data <- data.frame(
    y = rbinom(100,1,0.5),
    x1 = rnorm(100),
    x2 = rnorm(100),
    x3 = rnorm(100)
)

mod1 <- glm(y~x1+x2+x3, family=binomial(link="logit"), 
           na.action=na.pass,data=Data)

mod2 <- glm((1-y)~x1+x2+x3, family=binomial(link="logit"),
           na.action=na.pass,data=Data)

> all.equal(coef(mod2),-coef(mod1))
[1] TRUE
like image 87
Joris Meys Avatar answered Feb 26 '23 22:02

Joris Meys