Logistic Regression in R models for 1 or 0?

According to this link, it says SAS models for 0,

To model 1s rather than 0s, we use the descending option. We do this because by default, proc logistic models 0s rather than 1s

What happens in case of R's glm function? Does it model for 1 or 0? Is there a way to change it? Does it matter?

Topic sas logistic-regression r

Category Data Science


I always learned to model for 1. See below for the impact of switching the encoding,

model <- glm(ans ~ x, data = simulated_data, family = binomial)
summary(model)

# 
# Call:
# glm(formula = ans ~ x, family = binomial, data = simulated_data)
# 
# Deviance Residuals: 
#       1        2        3        4        5  
#  1.6388  -0.6249  -1.2146  -0.8083   0.7389  
# 
# Coefficients:
#             Estimate Std. Error z value Pr(>|z|)
# (Intercept)  -2.4753     2.5006   -0.99    0.322
# x             0.5957     0.6543    0.91    0.363
# 
# (Dispersion parameter for binomial family taken to be 1)
# 
#     Null deviance: 6.7301  on 4  degrees of freedom
# Residual deviance: 5.7505  on 3  degrees of freedom
# AIC: 9.7505
# 
# Number of Fisher Scoring iterations: 4
# 

simulated_data$ans <- !simulated_data$ans
model_opp <- glm(ans ~ x, data = simulated_data, family = binomial)
summary(model_opp)

# 
# Call:
# glm(formula = ans ~ x, family = binomial, data = simulated_data)
# 
# Deviance Residuals: 
#       1        2        3        4        5  
# -1.6388   0.6249   1.2146   0.8083  -0.7389  
# 
# Coefficients:
#             Estimate Std. Error z value Pr(>|z|)
# (Intercept)   2.4753     2.5006    0.99    0.322
# x            -0.5957     0.6543   -0.91    0.363
# 
# (Dispersion parameter for binomial family taken to be 1)
# 
#     Null deviance: 6.7301  on 4  degrees of freedom
# Residual deviance: 5.7505  on 3  degrees of freedom
# AIC: 9.7505
# 
# Number of Fisher Scoring iterations: 4

Hope this helps.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.