Changing reference group for categorical predictor variable in logistic regression

后端 未结 4 1982
轻奢々
轻奢々 2020-12-30 07:31

I\'m running a logistic regression with a categorical predictor variable with levels 0-6. By default, R considers level 0 as the reference group.

How can I tell R to

相关标签:
4条回答
  • 2020-12-30 07:45

    The C function has already been suggested, also look at contrasts, relevel, and reorder, among others.

    0 讨论(0)
  • 2020-12-30 07:49

    You can use relevel function: dataframe$x1 <- relevel(datafrmae$x1, "type here the reference category")

    0 讨论(0)
  • 2020-12-30 08:05

    Use the C function to define your contrasts in the dataframe.

    If your dataframe is DF and the factor variable is fct, then

    DF$fct <- C(DF$fct, contr.treatment, base=3)
    

    (untested).

    0 讨论(0)
  • 2020-12-30 08:11

    This is very easy with Frank Harrell's packages (which allows for many additional functions).
    For example, for a dataframe named 'df'

    library(Hmisc) 
    library(rms)
    dd=datadist(df)
    options(datadist='dd')
    (m=lrm(y ~ catvar, data=df)) #uses the mode as the reference group
    summary(m, catvar=3) #using level=3 as the reference group
    summary(m, catvar=0) #using level=0 as the reference group
    

    (And, some sample data would have been nice - you can always use dput to output a small dataset)

    0 讨论(0)
提交回复
热议问题