If df$Y
is a factor, which level is treated as 1
and which is treated as 0
by default in glm(Y ~ X, data = df, family = binomial)
?
It seems like it's not the ref
argument in relevel
?
fun <- function(){
test <- data.frame(y = factor(c(rep('a',100),rep('b',100))), x = 1:200)
t1 <- sample(c('a','b'), 1)
test[,'y'] <- relevel(test[,'y'], ref = t1)
co <- glm(y ~ x, data = test, family = binomial)$coefficients[2]
test[,'y'] <- ifelse(test[,'y'] == t1, 1, 0)
c1 <- glm(y ~ x, data = test, family = binomial)$coefficients[2]
return((co > 0) == (c1 > 0))
}
fun()
## F