如何在Box中使用Box-Tidwell函数进行逻辑回归

时间:2019-05-28 21:58:25

标签: r logistic-regression

我使用'car'包中的boxTidwell函数获取逻辑回归模型时出错。

我想建模

fatalCancer〜globy1,其中fatalCancer是具有两个水平的因子,而globy1是数字(均为正)。我正在对此进行测试,以检查globy1与结果对数的线性关系。

查看错误消息(如下)和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

分数统计最终不适用,我想成功进行测试。

1 个答案:

答案 0 :(得分:1)

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

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

或者,您可以通过散点图来评估:

plot(logodds ~ globy1)

我希望这会有所帮助!