让r输出标准回归系数
标签:
杂谈 |
分类: R |
这是一个说明r特点的很好的例子。与其他软件相比,r在标准化方面做得不算好。
比如r的lm功能是不输出标准化回归系数的。
此时,只好对着公式去自己一个一个去算了。
Beta.x1=(b.x1*sd.x1)/sd.y1
如果你有很多回归系数,还是写个function比较方便。
r里的计量经济学的包QuantPsyc里的lm.beta可以很方便的输出这个结果。
一个例子:
#
install.packages("QuantPsyc")
library(QuantPsyc)
us <- USJudgeRatings
names(us)
lm1 <- lm ( CONT ~ INTG + DMNR + DILG,
us)
lm.beta(lm1)
其中的lm.beta其实是:
function (MOD)
{
b <- summary(MOD)$coef[-1, 1]
sx <- sd(MOD$model[-1])
sy <- sd(MOD$model[1])
beta <- b * sx/sy
return(beta)
}
- Advantages
-
Standard coefficients' advocates note that the coefficients ignore
the independent variable's
scale of units, which makes comparisons easy. - Disadvantages
- Critics voice concerns that such a standardization can be misleading; a change of one standard deviation in one variable has no reason to be equivalent to a similar change in another predictor.
Some variables are easy to affect externally, e.g., the amount of time spent on an action. Weight or cholesterol level are more difficult, and some, like height or age, are impossible to affect externally.

加载中…