Dear R-Users,

 

I will be really grateful if you help me here. This is my script. I want to
extract the vif values for x1 and x2 respectively as well as the regression
coefficients for x1 and x2. Because I then want to plug them in a next step
of the analysis. Thank you in advance! I am using the MASS package.

 

co<-0.25*sqrt(16)*sqrt(10)

sigma <- matrix(c(16,co,co,10),2,2)

data025<-mvrnorm(n=100,rep(0,2),sigma,empirical = TRUE)

x1<-data025[,1]

x2<-data025[,2]

eta<-rnorm(n=100,mean=0,sd=1)

y<-10-1.5*x1-0.25*x2+eta

f<-lm(y~x1+x2)

vif<-function(f)

UseMethod("vif")

vif.lm<-function(f){

V<-summary(f)$cov.unscaled

 Vi<-crossprod(model.matrix(f))

nam<-names(coef(f))

if(k<-match("(Intercept)",nam,nomatch=F)){

v1<-diag(V)[-k]

v2<-(diag(Vi)[-k]-Vi[k,-k]^2/Vi[k,-k])

nam<-nam[-k]

}else{

v1<-diag(V)

v2<-diag(Vi)

}

structure(v1*v2,names=nam)

}

vif(f)

coef(f)

 

 

Georgi Dragolov

 

Jacobs University Bremen

Integrated Social Sciences, Class of 2008

College Ring 6, Mailbox 236

D-28759 Bremen, Germany

Phone: ++49-(0)421-200-5367

Email: G.Dragolov@jacobs-university.de

 


	[[alternative HTML version deleted]]

