如果df$Y
是一个因素,哪个级别被视为1
,默认情况下0
被视为glm(Y ~ X, data = df, family = binomial)
?
好像它不是ref
中的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