【发布时间】:2018-08-22 04:25:35
【问题描述】:
我正在尝试评估我构建的逻辑回归模型的拟合优度。最初,建议我使用 Hosmer-Lemeshow 测试,但经过进一步研究,我了解到它不如 Hosmer et al 所指出的综合拟合优度测试可靠。据我了解,R rms 包中的 residual.lrm 是运行 le Cessie - van Houwelingen - Copas - Hosmer 未加权平方和检验的方法。
我已经构建了以下模型:
> NEDOCModel <- glm(complication ~ ultrasound + fNEDOC, family = "binomial", data = modelmain);
> summary(NEDOCModel);
Call:
glm(formula = complication ~ ultrasound + fNEDOC, family = "binomial",
data = modelmain, x = TRUE, y = TRUE)
Deviance Residuals:
Min 1Q Median 3Q Max
-0.5841 -0.5812 -0.4899 -0.4899 2.0878
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.69293 0.10126 -16.719 <2e-16 ***
ultrasound1 -0.36661 0.12514 -2.929 0.0034 **
fNEDOCOvercrowded (140 - 200) 0.01087 0.13524 0.080 0.9359
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 1765.6 on 2284 degrees of freedom
Residual deviance: 1757.1 on 2282 degrees of freedom
AIC: 1763.1
Number of Fisher Scoring iterations: 4
其中并发症是二元结果(0 或 1),超声和 fNEDOC 是二元预测因子(0 或 1)。
按照residual.lrm 函数的描述(和示例),我收到以下错误:
> resid(NEDOCModel, "gof");
Error in match.arg(type) :
'arg' should be one of “deviance”, “pearson”, “working”, “response”, “partial”
作为一个业余爱好者并且对这个领域比较陌生,如果能帮助我解决这个错误并提供指导以确保我正确评估我的模型,我将不胜感激。
提前致谢!
编辑:这是数据的一小部分:
simExample <- structure(list(complication = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("0",
"1"), class = "factor"), ultrasound = structure(c(1L, 2L, 2L,
1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L,
1L), .Label = c("0", "1"), class = "factor"), fNEDOC = structure(c(1L,
2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L,
1L, 1L, 2L), .Label = c("Not Overcrowded (00 - 140)", "Overcrowded (140 -
200)"), class = "factor")), .Names = c("complication", "ultrasound",
"fNEDOC"), row.names = c(NA, 20L), class = "data.frame")
View(simExample)
complication ultrasound fNEDOC
1 0 0 Not Overcrowded (00 - 140)
2 0 1 Overcrowded (140 - 200)
3 0 1 Not Overcrowded (00 - 140)
4 0 0 Not Overcrowded (00 - 140)
5 0 1 Not Overcrowded (00 - 140)
6 0 0 Not Overcrowded (00 - 140)
7 0 0 Not Overcrowded (00 - 140)
8 0 1 Overcrowded (140 - 200)
9 0 1 Not Overcrowded (00 - 140)
10 1 0 Overcrowded (140 - 200)
11 0 0 Not Overcrowded (00 - 140)
12 0 1 Not Overcrowded (00 - 140)
13 0 1 Not Overcrowded (00 - 140)
14 0 1 Overcrowded (140 - 200)
15 0 1 Overcrowded (140 - 200)
16 0 1 Not Overcrowded (00 - 140)
17 0 1 Not Overcrowded (00 - 140)
18 0 0 Not Overcrowded (00 - 140)
19 0 1 Not Overcrowded (00 - 140)
20 0 0 Overcrowded (140 - 200)
【问题讨论】:
-
你命名的函数是
residuals(),而不是resid()。你试过residuals(NEDOCModel, "gof")吗?寻求帮助时,您应该包含一个简单的reproducible example,其中包含可用于测试和验证可能解决方案的示例输入和所需输出。 -
@MrFlick 是的。我都试过了;
resid()是residuals()的缩写。我会在几分钟内添加一小部分数据。 -
您应该按照提供的链接中所述的可重现格式共享数据。您所展示的内容很难复制/粘贴到 R 中进行测试。
-
residuals.rlm函数适用于使用lrm()函数创建的模型。您使用了glm()函数,因此您需要查看?residuals.glm帮助页面。 glm 模型没有“gof”选项。我什至不确定从帮助页面应该做什么。 -
@MrFlick 使用
lrm()构建模型确实允许resid()函数正常工作。我只是想在离开并学习更多东西之前确认一下:lrm()在这种情况下是glm()的合适替代品,因为结果是二进制的?感谢您的帮助!
标签: r logistic-regression