【问题标题】:How to use the Box-Tidwell function with a logistic regression in R如何在 R 中将 Box-Tidwell 函数与逻辑回归一起使用
【发布时间】:2019-10-14 11:23:12
【问题描述】:

我在逻辑回归模型中使用 'car' 包中的 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,我想成功运行测试。

【问题讨论】:

  • ?boxTidwell 的文档中没有任何内容表明它适用于常规 lm 以外的任何内容。

标签: r logistic-regression


【解决方案1】:

逻辑回归的线性假设在对数赔率和预测变量之间,而不是在结果变量和预测变量之间(因为您已将它们输入到函数中)。

lreg <- glm(fatalCancer ~ globy1, data=m2dat, family = binomial(link="logit"))
logodds <- lreg$linear.predictors
boxTidwell(logodds ~ globy1)

或者,您可以使用散点图进行评估:

plot(logodds ~ globy1)

我希望这会有所帮助!

【讨论】:

  • 如果您使用 boxtidwell,则响应应该是对数优势比。但是我不太确定将拟合的对数优势预测传递给 boxTidwell 以找到合适的转换,因为这已经是线性拟合的预测。也许通过残差,但同样,不是很清楚 OP 想要什么..
  • 只是评论,不是批评..我自己也不太确定
  • 我不同意你的观点......在我发布答案后,我开始猜测它。我的回答应该可以解决警告,但我不确定它在统计上是否有效。另一种方法是使用预测变量的交互项及其 log 运行逻辑回归,即 fatalCancer ~ globy1 * log(globy1)。摘要功能将向您显示任何违规行为。这根据 Hosmer 和 Lemeshow (1989) 测试了线性假设。
猜你喜欢
  • 1970-01-01
  • 2019-06-25
  • 2018-01-26
  • 1970-01-01
  • 1970-01-01
  • 2019-08-20
  • 1970-01-01
  • 2017-01-25
  • 1970-01-01
相关资源
最近更新 更多