2

Consider the following:

library(tidyverse)
library(car)

a <- c( 2, 3, 4, 5, 6, 7, 8, 9, 100, 11)
b <- c(5, 6, 7, 80, 9, 10, 11, 12, 13, 14)
c <- c(15, 16, 175, 18, 19, 20, 21, 22, 23, 24)

x <- c(17,18,50,15,64,15,3,5,6,9)
y <- c(55,66,99,83,64,51,23,64,89,101)
z <- c(98,78,56,21,45,34,61,98,45,64)

abc <- data.frame(cbind(a,b,c))

Firstly, I run a regression and values abc with xyz as follows (This went according to plan):

dep_vars <- as.matrix(abc)
lm <- lm(dep_vars ~ x + y + z, data = abc)

From here, I want to get the variance inflation factor using the vif() function:

vif(lm)

But then I get an error that says Error in if (names(coefficients(mod)[1]) == "(Intercept)") { : argument is of length zero. Can anybody help me understand where I went wrong? Or is there an alternative?

Kgosi
  • 33
  • 5
  • `library(car) a <- c( 2, 3, 4, 5, 6, 7, 8, 9, 100, 11) b <- c(5, 6, 7, 80, 9, 10, 11, 12, 13, 14) c <- c(15, 16, 175, 18, 19, 20, 21, 22, 23, 24) d <- c(90, 92, 94, 96, 98, 100, 102, 103, 100, 90) e <- c(27, 28, 50, 15, 64, 25, 3, 5, 6, 9) abcde <- data.frame(cbind(a, b, c, d, e)) lm <- lm(as.matrix(d, e) ~ a + b + c, data = abcde) vif(lm)` – Isaiah Oct 21 '22 at 11:05
  • Kgosi, is this what you were after? – Isaiah Oct 21 '22 at 11:06
  • Yes, I guess the problem was my variables weren't all in one data frame? – Kgosi Oct 21 '22 at 11:13
  • @Isaiah I've still got the same problem though? – Kgosi Oct 21 '22 at 11:20
  • 1
    Just tried a couple of times and worked for me. Perhaps you need to clear your environment. I'd also restart R. – Isaiah Oct 21 '22 at 11:46
  • Voting to close as not-reproducible. – IRTFM Nov 10 '22 at 23:17

0 Answers0