Skip to content

Commit

Permalink
Review more standardizing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Hemken committed Mar 3, 2022
1 parent aad2cdc commit 084e11e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: stdBeta
Type: Package
Title: Standardized Coefficients for Linear Models
Description: Updates a model fit by substituting standarized variables.
Version: 0.2.3
Version: 1.0
Authors@R: person("Doug", "Hemken", email="[email protected]",
role=c("aut", "cre"), comment="SSCC, Univ. of Wisconsin-Madison")
Maintainer: Doug Hemken <[email protected]>
Expand Down
21 changes: 20 additions & 1 deletion vignettes/Why_stdBeta.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ fit <- lm(mpg ~ disp*wt, mtcars)
QuantPsyc::lm.beta(fit) # warning given, wrong results
lm.beta::lm.beta(fit)
lsr::standardCoefs(fit) # agrees with lm.beta::lm.beta, but no intercept
arm::standardize(fit, standardize.y=TRUE)
arm::standardize(fit, standardize.y=TRUE) # uses 2 sd
reghelper::beta(fit) # Correct!
effectsize::standardize(fit) # also correct!
```

The `QuantPsyc` function uses the classic formula, but
Expand Down Expand Up @@ -100,11 +102,28 @@ of the exponentiation operator.
coefficients(lm(zmpg ~ zwt + I(zwt^2))) # by "hand"
fitsq <- lm(mpg ~ wt + I(wt^2), mtcars)
stdBeta::stdBeta(fitsq)
reghelper::beta(fitsq) # Correct!
effectsize::standardize(fitsq) # also correct!
```

The second method would be to use the `poly` function.
```{r poly2}
coefficients(lm(zmpg ~ zwt + I(zwt^2))) # by "hand"
fitpoly <- lm(mpg ~ poly(wt,2,raw=TRUE), data=mtcars)
stdBeta::stdBeta(fitpoly)
reghelper::beta(fitpoly) # Error
effectsize::standardize(fitpoly) # also correct!
```

## Factors

```{r}
mtcars$am <- factor(mtcars$am)
coefficients(lm(zmpg ~ zwt*am, data=mtcars)) # by "hand"
fitfactor <- lm(mpg ~ wt*am, data=mtcars)
stdBeta::stdBeta(fitfactor)
reghelper::beta(fitfactor) # scales factors by default
reghelper::beta(fitfactor, skip="am") # Correct
effectsize::standardize(fitfactor) # also correct!
```

0 comments on commit 084e11e

Please sign in to comment.