R:对 caret 包构建的逻辑模型执行 car::Anova 类型 II 和 III 测试
R: perform car::Anova type II and III test on logistic model built by caret package
我正在构建一个广义逻辑回归模型,如下所示:
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)
我收到以下错误:
Error in UseMethod("vcov") : no applicable method for 'vcov'
applied to an object of class "c('train', 'train.formula')
但是,如果我改用函数 glm
来构建模型,那就没问题了:
glm_fit <- glm(diabetes~., data=PimaIndiansDiabetes, family=binomial)
car::Anova(glm_fit, type=2)
那么,如何在我的 caret
模型上执行 Anova
类型 II 和 III 测试?
class "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
我正在构建一个广义逻辑回归模型,如下所示:
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)
我收到以下错误:
Error in UseMethod("vcov") : no applicable method for 'vcov' applied to an object of class "c('train', 'train.formula')
但是,如果我改用函数 glm
来构建模型,那就没问题了:
glm_fit <- glm(diabetes~., data=PimaIndiansDiabetes, family=binomial)
car::Anova(glm_fit, type=2)
那么,如何在我的 caret
模型上执行 Anova
类型 II 和 III 测试?
class "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