更改 R 中 glm 中分类预测变量的级别

Change the levels of the categorical predictor in glm in R

我有一个名为“组”的预测变量,这个组有 3 个类别(ALTO、MEDIO、BAJO)。在我的二项式族的 glm 中,摘要显示截距 + BAJO 和 MEDIO,但我需要在我的 tab_model 中只看到 ALTO 和 MEDIO,并让 BAJO 作为截距。有什么办法可以改变这个设置吗?

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

这是我的 tab_model:

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

您可以使用relevel()函数来指定因子的哪个水平是参考水平。假设变量 Grupo 已经是一个因素,这应该有效:

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