Search code examples
rglm

Change the levels of the categorical predictor in glm in R


I have a predictor variable called "Group", this group has 3 categories (ALTO, MEDIO, BAJO). In my glm for binomial family, the summary shows the intercept + BAJO and MEDIO, but I need to see in my tab_model only ALTO and MEDIO and let BAJO as intercept. Is there any way to change this setting?

mSUI1d <- glm(Suicidio ~ Grupo, data = PAIS_PBI, family = binomial)
> mSUI1d

Call:  glm(formula = Suicidio ~ Grupo, family = binomial, data = PAIS_PBI)

Coefficients:
(Intercept)    GrupoBAJO   GrupoMEDIO  
   -1.35703      0.12204      0.07421  

Degrees of Freedom: 42454 Total (i.e. Null);  42452 Residual
  (1027 observations deleted due to missingness)
Null Deviance:      44250 
Residual Deviance: 44230    AIC: 44240

And this is my tab_model:

           Odds Ratios  IC (95%)
GrupoBAJO   1.13 ***    1.07 – 1.20
GrupoMEDIO  1.08 *      1.02 – 1.14
Observations    42455

Solution

  • You can use the relevel() function to specify which level of the factor is the reference level. Assuming the variable Grupo is already a factor, this should work:

    PAIS_PBI$Grupo <- relevel(PAIS_PBI$Grupo, ref = "BAJO")