qwer
qwer

Reputation: 1

selecting small vif variables in r

I am trying to write an r function to select covariates with small VIF. Here is my code:

ea=read.csv("ea.csv")
library(car)
fullm<-lm(appEuse~.,data=ea)
cov<-names(ea)
ncov<-length(cov)
vifs<-rep(NA,ncov)
include<-rep(NA,ncov)

for (i in 1:ncov){
    vifs[i]<-vif(fullm)[i]
    if (vifs[i]<10){
        include[i]<-cov[i+1]
   }
}

Error in if (vifs[i] < 10) { : missing value where TRUE/FALSE needed

I was trying to set for loop from 1 to ncov-1, then got argument is of length zero. Is there a way to go around it?

Upvotes: 0

Views: 66

Answers (1)

Jack Calzaretta
Jack Calzaretta

Reputation: 18

Could be wrong, but looks like you're trying to loop an if statement over a list of NAs:

vifs<-rep(NA,ncov)

is later referenced at

if (vifs[i]<10){

Could this be your issue?

Upvotes: 0

Related Questions