+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 16 to 28 of 28

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

  1. #16
    FormerlyKnownAsRaptor
    Points: 24,442, Level: 95
    Level completed: 10%, Points required for next Level: 908
    Awards:
    Activity Award
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    3,174
    Thanks
    883
    Thanked 552 Times in 500 Posts

    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.
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  2. #17
    TS Contributor
    Points: 6,570, Level: 53
    Level completed: 10%, Points required for next Level: 180
    Lazar's Avatar
    Location
    Sydney
    Posts
    664
    Thanks
    110
    Thanked 164 Times in 149 Posts

    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. #18
    Banned
    Points: 3,530, Level: 37
    Level completed: 20%, Points required for next Level: 120
    GretaGarbo's Avatar
    Posts
    419
    Thanks
    130
    Thanked 139 Times in 122 Posts

    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. #19
    TS Contributor
    Points: 6,570, Level: 53
    Level completed: 10%, Points required for next Level: 180
    Lazar's Avatar
    Location
    Sydney
    Posts
    664
    Thanks
    110
    Thanked 164 Times in 149 Posts

    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. #20
    Cookie Scientist
    Points: 5,945, Level: 49
    Level completed: 98%, Points required for next Level: 5
    Jake's Avatar
    Location
    Boulder, CO
    Posts
    797
    Thanks
    18
    Thanked 315 Times in 241 Posts

    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
    “In God we trust. All others must bring data.”
    ~W. Edwards Deming

  6. #21
    FormerlyKnownAsRaptor
    Points: 24,442, Level: 95
    Level completed: 10%, Points required for next Level: 908
    Awards:
    Activity Award
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    3,174
    Thanks
    883
    Thanked 552 Times in 500 Posts

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

    Quote 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
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  7. #22
    Banned
    Points: 3,530, Level: 37
    Level completed: 20%, Points required for next Level: 120
    GretaGarbo's Avatar
    Posts
    419
    Thanks
    130
    Thanked 139 Times in 122 Posts

    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. #23
    FormerlyKnownAsRaptor
    Points: 24,442, Level: 95
    Level completed: 10%, Points required for next Level: 908
    Awards:
    Activity Award
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    3,174
    Thanks
    883
    Thanked 552 Times in 500 Posts

    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)
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  9. #24
    TS Contributor
    Points: 6,570, Level: 53
    Level completed: 10%, Points required for next Level: 180
    Lazar's Avatar
    Location
    Sydney
    Posts
    664
    Thanks
    110
    Thanked 164 Times in 149 Posts

    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. #25
    Banned
    Points: 3,530, Level: 37
    Level completed: 20%, Points required for next Level: 120
    GretaGarbo's Avatar
    Posts
    419
    Thanks
    130
    Thanked 139 Times in 122 Posts

    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. #26
    FormerlyKnownAsRaptor
    Points: 24,442, Level: 95
    Level completed: 10%, Points required for next Level: 908
    Awards:
    Activity Award
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    3,174
    Thanks
    883
    Thanked 552 Times in 500 Posts

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

    Quote 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.
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  12. #27
    Banned
    Points: 3,530, Level: 37
    Level completed: 20%, Points required for next Level: 120
    GretaGarbo's Avatar
    Posts
    419
    Thanks
    130
    Thanked 139 Times in 122 Posts

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

    "ade4 package"
    No.

    I need to fix this.

    Anyway, thanks for the illustrations and the discussion.

  13. #28
    Points: 3,901, Level: 39
    Level completed: 68%, Points required for next Level: 49
    SiBorg's Avatar
    Posts
    255
    Thanks
    71
    Thanked 24 Times in 22 Posts

    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!
    Last edited by SiBorg; 07-20-2012 at 04:53 PM.

+ Reply to Thread
Page 2 of 2 FirstFirst 1 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats