各位,我的df就像:
或者你可以复制它:
reg_df <- structure(list(NEWDI = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L), age = c(79.93, 75.1,
59.52, 45.62, 63.25, 69.41, 70.37, 70.57, 72.54, 64.63, 67.41,
60.29, 71.52, 65.11, 73.52, 57.96, 75.88, 65.35, 73.23, 57.25
), smoke_dummy = c(1L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L,
1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L), drink_dummy = c(1L, 0L,
1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 1L,
1L, 1L), bmi = c(27.9595, 32.7313, 28.682, 26.8898, 30.556, 25.763,
26.9286, 45.3568, 33.1924, 29.391, 36.0282, 25.7202, 35.2501,
27.0999, 35.5935, 30.1911, 32.557, 28.0998, 25.2214, 23.4699),
edu_dummy = c(0L, 1L, NA, 0L, 0L, 1L, NA, 0L, NA, NA, 0L,
0L, NA, NA, 1L, NA, 0L, 0L, NA, NA), class_dummy = c(3, 1,
0, 0, 0, 0, 3, 0, 1, 0, 3, 0, 0, 1, 3, 2, 3, 0, 1, 0), sex_dummy = c(1,
0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1)), row.names = c(NA,
20L), class = "data. Frame")
我想这样做:
model <- glm(NEWDI ~ class_dummy + age + smoke_dummy + drink_dummy +
bmi + edu_dummy + sex_dummy,
data = reg_df, family = "binomial")
summary(model)
我有个问题:
我想将每个X变量值设置为0作为回归的参考组,并查看它们的OR(除了class_dummy值为0~3,其他variable_dummy值为0~1.),并且smoke_dummy,drink_dummybmi,edu_dummy和bmi具有NA值,我不确定是否可以将回归设置为忽略NA值。
谢谢你!
1条答案
按热度按时间6ss1mwsb1#
为了在回归中显示参考组,您需要将
_dummy
变量更改为因子。我用data.table
做了这个。接下来,拟合模型后,您可以使用
gtsummary
包中的tbl_regression
创建回归表。