Change reference group using glm with binomial family

后端 未结 2 1714
旧巷少年郎
旧巷少年郎 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

    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))
    

提交回复
热议问题