默认情况下,R函数`glm(...,family = binomial)中的响应使用哪个级别作为“1”?

时间:2017-04-01 21:27:46

标签: r

如果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

0 个答案:

没有答案