I am testing for multicollinearity in a dataset. I am able to run VIF()
just fine in order to test that there is multicollinearity. However, when I run vif()
to test each variable to see if one may be worth removing, I continue to get the same error each time, even though a classmate of mine has almost the exact same code and his works.
From my understanding, in VIF()
you want to run a model, like lm()
of the data, so I did that and that works. But vif()
I believe you should just be able to plug in a data frame, so I've tried making my data a data.frame before putting it through vif()
, but that does not seem to work. Just to see what happens, I also tried running the lm()
of the data through vif()
, but that definitely doesn't work.
d <- read.table('9.10data.txt', col.names = c('y',
'x1','x2','x3','x4'))
reg <- lm(data = d, y~x1+x2+x3+x4)
VIF(reg)
# VIF = 26.94823 > 10 so multicollinearity is present.
d <- data.frame(d)
vif(d)
I would expect to get a sort of matrix that shows the vif
values for each variable x1, x2, x3, x4, but I keep getting the error message:
Error in y[, i] : incorrect number of dimensions
If the data would help, go to http://users.stat.ufl.edu/~rrandles/sta4210/Rclassnotes/data/textdatasets/KutnerData/Chapter%20%209%20Data%20Sets/CH09PR10.txt and I just copy and pasted the data into a text editor and saved as a txt file.