[R] How to extract the coefficients from the model

From: Georgi Dragolov <g.dragolov_at_jacobs-university.de>
Date: Fri, 28 Mar 2008 13:24:11 +0100


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_at_jacobs-university.de  

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 28 Mar 2008 - 12:26:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 28 Mar 2008 - 12:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive