3

I want to calculate variance inflation factor (VIF) for a caret glm model in R. This is my code and the dataset is from UCI:

library(caret)
library(tidyverse)

url <- paste0("https://archive.ics.uci.edu/ml/machine-learning-databases/",
              "00267/data_banknote_authentication.txt")

dataset <- read_csv(url, col_names = c("varWav","skeWav","curtWav","entropy","class"))
dataset$class <- as.factor(ifelse(dataset$class == 0,"Authentic","Forgery"))

idx <- createDataPartition(dataset$class, p = 0.8, list = FALSE)
train_set <- dataset[idx,]
test_set <- dataset[-idx,]

notes_model <- train(class ~.,
                   data = train_set,
                   method = "glm")

But when I try this code it returns me an error:

car::vif(notes_model)

Error in UseMethod("vcov") : no applicable method for 'vcov' applied to an object of class "c('train', 'train.formula')"

Perhaps my code is wrong? Please, any help will be greatly appreciated.

UseR10085
  • 7,120
  • 3
  • 24
  • 54
Alexis
  • 2,104
  • 2
  • 19
  • 40

1 Answers1

4

You can extract the final trained model and then calculate vif with that:

car::vif(notes_model$finalModel)
    varWav     skeWav    curtWav    entropy 
 63.978111 184.323806 356.526156   1.935005 
astrofunkswag
  • 2,608
  • 12
  • 25
  • 1
    Great!, now I see that some variables have high multi collinearity. Thank you @astrofunkswag – Alexis Aug 04 '20 at 23:23