0
votes

I am trying to build a logistic regression model using glm function in R. My dependent variable is binomial with 0 and 1 only. Here 0 - Non Return , 1- Return.

I want to model for Non-Return (0's),but glm function of R by default build for 1's. Like in SAS which by default build for lower value and we can use descending attribute in proc logistic to change the order, do we have something similar in glm too ?

I have one option to achieve this by changing 0 to 1 and vice-versa in my raw data but don't want to change my raw data.

Please help me or guide how can I do the similar thing in R.

Thanks in advance.

2

2 Answers

2
votes

Just specify 1 - y as the DV:

set.seed(42)
y <- sample(c(0, 1), 10, TRUE)
#[1] 1 1 0 1 1 1 1 0 1 1

fit <- glm(y ~ 1, family = binomial)
coef(fit)
# (Intercept) 
# 1.386294 
log(mean(y) / (1 - mean(y)))
#[1] 1.386294

1 - y
#[1] 0 0 1 0 0 0 0 1 0 0

fit1 <- glm(1 - y ~ 1, family = binomial)
coef(fit1)
#(Intercept) 
#-1.386294 
log(mean(1 - y) / (1 - mean(1 - y)))
#[1] -1.386294
0
votes

Alternatively, you can temporarily transform your data by using...transform:

glm( data = transform( data.frame(y=0), y=y+1 ), ... )