【问题标题】:R: perform car::Anova type II and III test on logistic model built by caret packageR:对由 caret 包构建的逻辑模型执行 car::Anova 类型 II 和 III 测试
【发布时间】:2020-04-11 17:26:41
【问题描述】:

我正在建立一个广义逻辑回归模型,如下所示:

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)

那么,如何在我的caret 模型上执行Anova 类型 II 和 III 测试?

【问题讨论】:

    标签: r logistic-regression r-caret anova


    【解决方案1】:

    “train”类没有方法 anova,所以做你需要的:

    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    
    

    【讨论】:

      猜你喜欢
      • 2021-07-07
      • 2014-07-29
      • 1970-01-01
      • 1970-01-01
      • 2017-07-10
      • 2016-03-09
      • 1970-01-01
      • 2015-05-22
      • 1970-01-01
      相关资源
      最近更新 更多