Created
March 28, 2012 19:18
-
-
Save andrewheiss/2229633 to your computer and use it in GitHub Desktop.
lm summary with beta coefficients
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
summary.with.betas <- function(model, logit=FALSE) { | |
model <- update(model, x=TRUE, y=TRUE) | |
sd.x <- apply(model$x, 2, sd) | |
sd.y <- sd(model$y) | |
std.coef <- coef(model) * (sd.x / sd.y) | |
coef.table <- as.data.frame(summary(model)$coefficients) | |
coef.table <- cbind(coef.table, beta=std.coef, sdX=sd.x) | |
if (logit == TRUE) { | |
e.beta <- exp(coefficients(model)) | |
e.bstdx <- exp(sd.x) | |
coef.table <- cbind(coef.table, e.beta=e.beta, e.bstdx=e.bstdx) | |
} | |
coef.table | |
} | |
# Use it like this: | |
x <- runif(100, -1, 1) | |
y <- runif(100, -1, 1) | |
fit <- lm(y ~ x) | |
summary(fit) | |
summary.with.betas(fit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment