Change reference group using glm with binomial family

后端 未结 2 1712
旧巷少年郎
旧巷少年郎 2021-01-23 06:10

When I run a binomial regression in R with an independed factor variable consisting of three levels \"Higher\" , \"Middle\" and \"Lower\" of which I want to change the referen

相关标签:
2条回答
  • 2021-01-23 06:58

    cbsnivcat3 is an ordered factor, so relevel won't work. What you can do is change it to an ordinary factor:

    cbsnivcat3 <- factor(cbsnivcat3, levels=c("Lower","Middle","Higher"))
    
    0 讨论(0)
  • 2021-01-23 06:58

    Try this

    df <- data.frame(y=sample(c(0,1), size=100,replace=T),x1=rep(c('a','b','c'),100), x2=1:100)
    summary(glm(y~x1+x2,data=df))
    
    df$x1 <- relevel(df$x1, ref='b')
    summary(glm(y~x1+x2,data=df))
    
    df$x1 <- relevel(df$x1, ref='c')
    summary(glm(y~x1+x2,data=df))
    
    0 讨论(0)
提交回复
热议问题