我正在建立如下的广义逻辑回归模型:
library(mlbench)
data(PimaIndiansDiabetes)
library(caret)
trControl <- trainControl(method = "repeatedcv",
repeats = 3,
classProbs = TRUE,
number = 10,
savePredictions = TRUE,
summaryFunction = twoClassSummary)
caret_model <- train(diabetes~.,
data=PimaIndiansDiabetes,
method="glm",
trControl=trControl)
然后我要执行Anova
II型和III型测试:
library(car)
car::Anova(caret_model , type=2)
我收到以下错误:
UseMethod(“ vcov”)中的错误:'vcov'没有适用的方法应用于类“ c('train','train.formula')
的对象
但是,如果我改用函数glm
来构建模型,那就很好了:
glm_fit <- glm(diabetes~., data=PimaIndiansDiabetes, family=binomial)
car::Anova(glm_fit, type=2)
所以,如何在我的Anova
模型上执行caret
II型和III型测试?
对于类“ train”,没有方法方差分析,所以要做您需要做的事情:
car::Anova(caret_model$finalModel, type=2)
Analysis of Deviance Table (Type II tests)
Response: .outcome
LR Chisq Df Pr(>Chisq)
pregnant 15.233 1 9.505e-05 ***
glucose 114.927 1 < 2.2e-16 ***
pressure 6.548 1 0.010502 *
triceps 0.008 1 0.928500
insulin 1.742 1 0.186918
mass 40.779 1 1.704e-10 ***
pedigree 10.340 1 0.001302 **
age 2.522 1 0.112253
类似于:
car::Anova(glm_fit, type=2)
Analysis of Deviance Table (Type II tests)
Response: diabetes
LR Chisq Df Pr(>Chisq)
pregnant 15.233 1 9.505e-05 ***
glucose 114.927 1 < 2.2e-16 ***
pressure 6.548 1 0.010502 *
triceps 0.008 1 0.928500
insulin 1.742 1 0.186918
mass 40.779 1 1.704e-10 ***
pedigree 10.340 1 0.001302 **
age 2.522 1 0.112253