[R] How to calculate vif of each term of model in R?

Methekar, Pushpa (GE Transportation, Non-GE) pushpa.methekar at ge.com
Wed Apr 8 10:23:51 CEST 2015




I am beginner in R doing modelling in R, I loaded excel sheet in R, i have chosen x elements and y elements then fitted model for linear and second order regression. Now I have both models. I am bit confused how to calculate vif for each term in model like

e.g model1<-lm(y1~x1+x2+.....x9) when I am using rms package then it's giving me like

    vif(model1)

       x1         x2         x3         x4         x5         x6         x7

 6.679692   1.520271   1.667125   3.618439   4.931810   2.073879  13.870630

        x8         x9

   220.969628 214.034135

now i want to compare each term with std vif as vif>=10 and which will satisfy this condition i want to delete that term and update model1. i have done something like this

fun = function(model1) {

 for(i in 1:length(model1))    {

      v=vif(model1)

         ss=any(v[i]>=10)

                if(ss==1){update(model1,.~.,-v[i])}

                else{print("no update")}

                 i<-i+1

    }



        return(model1)

      }

fun(model1)

but giving error as

Error in if (ss == 1) { : missing value where TRUE/FALSE needed.

please tell me how do i solve this problem.



	[[alternative HTML version deleted]]



More information about the R-help mailing list