在逻辑回归交互变量上设置参考类别时遇到问题

Trouble with setting reference category on logistic regression interaction variable

提问人:Madhumitha S 提问时间:4/18/2023 更新时间:4/18/2023 访问量:54

问:

在我的数据集中的变量中,我想测试两个变量之间的相互作用——状态类别和目的。

  • state.ctgry 有两个序号类别(NDA 和非 NDA)
  • Purporse 有 5 个序号类别(社会、经济、文化、宗教和教育)

我想将 NDA 交互保留为参考类别,并获取非 NDA 交互结果显示在我的日志注册表中。在我的简单目的变量中,我将“经济”定义为参考类别。我对结果中与非 NDA 的宗教、社会和文化互动感兴趣

尽管定义了类别,但我仍然看到 NDA 交互与非 NDA 交互的结果被视为参考类别(附图 )

Regdcanceled$state.ctgry <- as.factor(Regdcanceled$state.ctgry)
Regdcanceled$Purpose <- as.factor(Regdcanceled$Purpose)

# set category 1 of variable A as reference
Regdcanceled$state.ctgry <- relevel(Regdcanceled$state.ctgry, ref = "NDA")

# set category X of variable B as reference
Regdcanceled$Purpose <- relevel(Regdcanceled$Purpose, ref = "Economic")

# create the interaction variable with NDA as the reference category
Regdcanceled$Int <- interaction(Regdcanceled$state.ctgry, Regdcanceled$Purpose, 
                                drop = TRUE)

# Fit logistic regression model with all levels of the interaction variable
log.fit4 <- glm(Cancelled ~ Purpose + state.ctgry + Total.amount + Int, 
                data = Regdcanceled, family = binomial)
summary(log.fit4)

r 逻辑回归 交互 作用分类

评论

2赞 George Savva 4/18/2023
查看公式 () 的帮助,了解如何使用 or 运算符向回归模型添加交互项。?formula*:
0赞 Community 4/18/2023
请提供足够的代码,以便其他人可以更好地理解或重现问题。

答:

0赞 Nick Glättli 4/18/2023 #1

您可以使用 添加交互。参考类别源于交互作用变量的参考类别。因此,您必须像这样更改代码:*

log.fit4 <- glm(Cancelled ~ Purpose*state.ctgry + Total.amount, 
                data = Regdcanceled, family = binomial)