Posts Tagged ‘Regression’

How to Get Standard Regression Coefficient Using R

Published by admin on March 18th, 2012

Last week, Lexing showed us a picture of how different programming languages look like. Very Interesting. However, let’s dive to the question raised in the title of this post: How to Get Standard Regression Coefficient Using R?( In addition to that, I want to practice using SyntaxHighliter here.)

# e.g. I set up one regression
reg<-lm(view/top$DAYS~feo+fev+ffvv+frf+frfsm+frfgs
        +frfgvs+frflv+frfy+frfys+fvfa+fvfmd+fvocp+ov)
summary(reg)
# model diagnosis
layout(matrix(1:4,2,2))
plot(reg)

# according to the formula between standard regression coefficient
                beta.x=b.x*sd.x/sd.y
# calcuate the standard regression coefficient one by one
# for the beta of feo
b.x<-coef(reg)[2]
sd.y<-sd(view/top$DAYS)
sd.x<-sd(feo)
beta.x<-b.x*sd.x/sd.y
# it's dull to do it in this way!

# output standard coefficient using QuantPsyc library
library(QuantPsyc)# install.packages("QuantPsyc")
as.data.frame(lm.beta(reg))

Apparently, R is not well designed in this aspect, although we could get what we want, but it’s not so efficient and convenient compared with other commercial software. Hope this will be improved in the future.