I am confused with the answer from https://stackoverflow.com/questions/23282048/logistic-regression-defining-reference-level-in-r
It said if you want to predict the probability of "Yes", you set as relevel(auth$class, ref = "YES")
. However, in my experiment, if we have a binary response variable with "0" and "1". We only get the estimation for probability of "1" when we set relevel(factor(y),ref="0")
.
n <- 200
x <- rnorm(n)
sumx <- 5 + 3*x
exp1 <- exp(sumx)/(1+exp(sumx))
y <- rbinom(n,1,exp1) #probability here is for 1
model1 <- glm(y~x,family = "binomial")
summary(model1)$coefficients
Estimate Std. Error z value Pr(>|z|)
(Intercept) 5.324099 1.0610921 5.017565 5.233039e-07
x 2.767035 0.7206103 3.839849 1.231100e-04
model2 <- glm(relevel(factor(y),ref="0")~x,family = "binomial")
summary(model2)$coefficients
Estimate Std. Error z value Pr(>|z|)
(Intercept) 5.324099 1.0610921 5.017565 5.233039e-07
x 2.767035 0.7206103 3.839849 1.231100e-04
I think if we want to get probability of "Yes", we should set relevel(auth$class, ref = "No")
, am I correct? And what is reference level here means? Actually, what is glm() to predict in default if we use response other than "0" and "1"?