[R] does package "QuantPsych" function lm.beta can handle resultsof a regression with weights?
Dimitri Liakhovitski
dimitri.liakhovitski at gmail.com
Thu Jul 29 15:06:03 CEST 2010
Thanks a lot, Tom!
On Mon, Jul 26, 2010 at 9:24 AM, Tom Fletcher
<tom.fletcher.mp7e at statefarm.com> wrote:
> The original function was created for a simple example. It never was
> written to address weighted regression. A quick fix will work for you
> situation.
>
> ### The original is:
>
>
> 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)
> }
>
> #### A newer modification:
>
> lm.betaW <-
> function (MOD)
> {
> b <- summary(MOD)$coef[-1, 1]
> sx <- sd(MOD$model[-1][1])
> sy <- sd(MOD$model[1])
> beta <- b * sx/sy
> return(beta)
> }
>
> The above should do the trick.
>
> TF
>
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Dimitri Liakhovitski
> Sent: Thursday, July 22, 2010 12:35 PM
> To: r-help at r-project.org
> Subject: [R] does package "QuantPsych" function lm.beta can handle
> resultsof a regression with weights?
>
> Hello, and sorry for not providing an example.
> I run a regular linear regression (using lm) and use weights with it
> (weights = ...).
> I use "QuantPsych" package, its function lm.beta to extract standardized
> regression weights from my lm regression object.
>
> When I don't use weights, everything is fine.
> But when I do use weights, I get an error that refers to lm.beta code:
> "In b * sx : longer object length is not a multiple of shorter object
> length"
>
> This happens because there is an extra column in the object:
> regr$model that lm.beta is using to get at the betas.
> Is there some other package that just gives me the standardized
> regression weights - even if I used weights for regression?
>
> Thank you!
>
> --
> Dimitri Liakhovitski
> Ninah Consulting
> www.ninah.com
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Dimitri Liakhovitski
Ninah Consulting
www.ninah.com
More information about the R-help
mailing list