At 03:04 PM 3/4/2002 +0100, Fredrik Karlsson wrote:
>When doing regression, is there a way of automatically obtaining the
>standardized correlation coefficients?
Dear Fredrik,
I assume that you mean standardized *regression* coefficients. If so, a
simple approach is to use the scale function to standardize the variables
and then to perform a regression with lm; you can include -1 on the
right-hand side of the model formula to suppress the constant; it will be 0
within rounding error anyway.
For example, using the Duncan data frame in the car package:
> Duncan.s <- as.data.frame(scale(Duncan[, 2:4])) # omits a
factor
in col. 1
> lm(prestige ~ income + education - 1, data=Duncan.s)
Call:
lm(formula = prestige ~ income + education - 1, data = Duncan.s)
Coefficients:
income education
0.4643 0.5155
Of course, you could also compute the standardized coefficients from the
unstandardized coefficients and the standard deviations of the variables;
for example
> mod <- lm(prestige ~ income + education, data=Duncan)
> coef(mod)
(Intercept) income education
-6.0646629 0.5987328 0.5458339
> coef(mod)[2:3]*sd(Duncan[,c('income',
'education')])/sd(Duncan$prestige)
income education
0.4642947 0.5155284
Finally, it's not hard to encapsulate this in a function:
> std.coef <- function (mod){
+ sy <- sd(response(mod))
+ sx <- sd(model.matrix(mod)[,-1])
+ b <- coef(mod)[-1]
+ b*sx/sy
+ }
> std.coef(mod)
income education
0.4642947 0.5155284
Is that what you had in mind?
John
-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._