r - 如何在 R 中将 Box-Tidwell 函数与逻辑回归一起使用
问题描述
使用逻辑回归模型的“汽车”包中的 boxTidwell 函数时出现错误。
我要建模
fatalCancer ~ globy1,其中 fatalCancer 是具有两个级别的因子, globy1 是数字(全为正)。我正在对此进行测试,以检查 globy1 的线性假设与结果的 logit。
查看错误消息(如下)和 boxTidwell 函数代码,似乎可能有问题,因为 fatalCancer 是一个因素。boxTidwell 文档中没有任何关于指定它是逻辑模型的内容。在 Fox 的 _An R Companion to Applied Regression (p.312) 第 6.4 节的示例中,示例逻辑回归不需要任何规范。
有没有办法修复下面 boxTidwell 函数的语法?
> library(car)
Loading required package: carData
>
> load("m2dat.RData")
> m2dat <- na.omit(m2dat)
> dim(m2dat)
[1] 116 3
> head(m2dat)
dog globy1 fatalCancer
1 101A 3.1 No
2 102A 2.9 No
3 103A 4.9 No
4 104A 3.1 Yes
5 105A 2.8 Yes
6 106A 3.5 No
> boxTidwell(fatalCancer ~ globy1, data=m2dat)
MLE of lambda Score Statistic (z) Pr(>|z|)
6.5694 NA NA
iterations = 21
There were 48 warnings (use warnings() to see them)
> warnings()
Warning messages:
1: In model.response(mf, "numeric") :
using type = "numeric" with a factor response will be ignored
2: In model.response(mf, "numeric") :
using type = "numeric" with a factor response will be ignored
3: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors
4: In model.response(mf, "numeric") :
using type = "numeric" with a factor response will be ignored
5: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors
6: In Ops.factor(r, 2) : ‘^’ not meaningful for factors
7: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors
8: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors
9: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors
10: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors
...
46: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors
47: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors
48: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors
分数统计结果为 NA,我想成功运行测试。
解决方案
逻辑回归的线性假设在对数赔率和预测变量之间,而不是在结果变量和预测变量之间(因为您已将它们输入到函数中)。
lreg <- glm(fatalCancer ~ globy1, data=m2dat, family = binomial(link="logit"))
logodds <- lreg$linear.predictors
boxTidwell(logodds ~ globy1)
或者,您可以使用散点图进行评估:
plot(logodds ~ globy1)
我希望这有帮助!
推荐阅读
- php - 如何通过ajax在php中插入多个同名输入
- docker - 为 docker 容器分配本地 IP
- google-chrome-extension - 在扩展弹出窗口中单击按钮时如何获得麦克风权限
- python-3.x - 无法在 Jupyter Notebook 中显示 graphviz 树
- php - FileMaker API for PHP 登录页面错误 - 无法修改标头信息
- django - django 如何生成唯一的用户令牌
- jakarta-ee - ZK 框架:使用 foreach 刷新动态布局
- ios - 领域对象的过滤属性
- xslt - XSLT:复制
没有 m: 命名空间,无需为每个元素创建模板 - google-maps - 集群图像未出现(仅出现数字) - agm-cluster-marker - Angular 5