# Thread: Extract beta and 95% CI of beta from lm in R

1. ## Re: Extract beta and 95% CI of beta from lm in R

Greta I think the argument is that in some cases (ie when the variables are in unfamiliar scaling) the standardized betas are more interpretable than the raw coefficients. So it allows you to say a 1 standard deviation increase in x yields an n standard deviation change in y. This is the crude design I used in my linear regression course (it now throws up a warning) for simple additive models:

Code:
stan.beta <- function(model) coefTab(model)[-1,5]
coefTab <- function(model){
frame <- as.data.frame(model.frame(model))
len <- length(coefficients(model))
colSds <- function(df) apply(df, 1, function(x) sd(x))
stan.co <- coefficients(model)[2:len]*(sd(frame[,2:len])/sd(frame[,1]))
DF <- data.frame(coefficients(summary(model)),
"stan.beta"=c(NA, stan.co),confint(model))
names(DF) <- c("beta", "se.beta", "t", "p", "stan.beta", "LowerCI", "UpperCI")
return(DF)
}

mod <- with(mtcars, lm(mpg~disp+hp+wt))
stan.beta(mod)
PS no guarantees if this is correct it was over a year and a half ago and I made it to match what my classmates who used SPSS would get. I think standardizing the coefficients first makes more sense but haven't really given this much thought since my linear regression class.

2. ## Re: Extract beta and 95% CI of beta from lm in R

^This is true. It is also a measure of effect size and some journal require effect size estimates. In addition many scales in social science are arbitary and/or have range restriction as such it seems that standadized estimates are often easier to understand.

3. ## Re: Extract beta and 95% CI of beta from lm in R

It seems to me that if one is using a standardized estimate then it seems like one is doing some implicit assumption that the x-variables are randomly sampled. But of course there is no such assumption in regression. We are just conditioning on the observed x-values. And that the standard deviation is some kind of “natural spread” of the x-variables. I think that this can lead the investigator wrong. (I wish I could dig up that critique!)

No I would definitely report the original estimates. But if they want the rescaled values, ok I would give them that to.

4. ## Re: Extract beta and 95% CI of beta from lm in R

My preference is always to give results on the original scale. For the most part, however, journals in my field require both.

5. ## Re: Extract beta and 95% CI of beta from lm in R

I like to report unstandardized coefficients + partial R-squareds for an indication of effect size

6. ## Re: Extract beta and 95% CI of beta from lm in R

Originally Posted by siborg77
thanks trinker I will try this tomorrow. My categorical data is coded as numbers, does this make any difference?
shouldn't as long as they're coded as factors in the dataframe

7. ## Re: Extract beta and 95% CI of beta from lm in R

trinker sayed:
"shouldn't as long as they're coded as factors in the dataframe"
But then the software takes the factors of the categorical variables and codes dummy variables (in most programs). To have a dummy variable seems to me to have a very simple thing.

Then, why on earth should one rescale that another time? (to the standardized beta model). Doesn’t that make it extra complicated?

8. ## Re: Extract beta and 95% CI of beta from lm in R

Just playing and testing:

Code:
mtcars\$cyl2 <- as.factor(mtcars\$cyl)
mod <- with(mtcars, lm(mpg~disp+hp+wt+cyl2))
mtcars.sc <- data.frame(scale(dummy(mtcars)))
mod2 <- with(mtcars.sc, lm(mpg~disp+hp+wt+cyl2.6+cyl2.8))

mod2
lm.beta(mod)
They're equal. I'd heard this but never tried it.

EDIT:
Hmmm... Not for the categorical variables

EDIT 2: put a missing period in the code between 2 and 9 (cyl2.8)

9. ## Re: Extract beta and 95% CI of beta from lm in R

I agree. One of the most frustrating things is when people report standadized estimates for things like gender and then say "the difference between males and females was...". There may be some value, however, in standadizing the outcome variable such that the estimate gives the difference between groups coded 0 and groups coded 1 in standard deviation units of the outcome variable. Many programs will give estimates for unstd, std x and y, std x, and std y.

10. ## Re: Extract beta and 95% CI of beta from lm in R

trinker sayed:
“They're equal. I'd heard this but never tried it.”
Aha, but is this also true for the classical sum-to-zero parameterization or the strange parameterization that is used in Splus or any other parameterization that the software happens to use?

(Nice code but the dummy function didn’t work for me.)

Anyway, there seems to be a place for extra confusion here because of standardization.

11. ## Re: Extract beta and 95% CI of beta from lm in R

Originally Posted by GretGarbo
(Nice code but the dummy function didn’t work for me.)
Hmmm... I ran it in a clean session and it works. Do you have R 2.15.1 and did you download the ade4 package?

EDIT: Greta I put a missing period in the code see if it runs now.

12. ## Re: Extract beta and 95% CI of beta from lm in R

No.

I need to fix this.

Anyway, thanks for the illustrations and the discussion.

13. ## Re: Extract beta and 95% CI of beta from lm in R

Only a few of them are categorical, most are continuous. Is reporting the SD preferable to the SE with the b coefficient

EDIT: I hadn't realised that there were at least 5 extra posts when I wrote this and am trying to digest it all. Thanks for all the comments!