r2sd | R Documentation |
r2sd
allows you to rescale a numeric vector such that the
ensuing output has a mean of 0 and a standard deviation of .5. r2sd_at
is a wrapper for
mutate_at
and rename_at
from dplyr. It both rescales the supplied vectors to
new vectors and renames the vectors to each have a prefix of z_
.
r2sd(x, na = TRUE)
x |
a vector, likely in your data frame |
na |
what to do with NAs in the vector. Defaults to TRUE (i.e. passes over the missing observations) |
By default, na.rm
is set to TRUE. If you have missing data, the function will just pass
over them.
Gelman (2008) argues that rescaling by two standard deviations puts regression inputs
on roughly the same scale no matter their original scale. This allows for some honest, if preliminary,
assessment of relative effect sizes from the regression output. This does that, but
without requiring the rescale
function from arm.
I'm trying to reduce the packages on which my workflow relies.
Importantly, I tend to rescale only the ordinal and interval inputs and leave the binary inputs as 0/1.
So, my r2sd
function doesn't have any of the fancier if-else statements that Gelman's rescale
function has.
The function returns a numeric vector rescaled with a mean of 0 and a standard deviation of .5.
Gelman, Andrew. 2008. "Scaling Regression Inputs by Dividing by Two Standard Deviations." Statistics in Medicine 27: 2865–2873.
x <- rnorm(100)
r2sd(x)
r2sd_at(mtcars, c("mpg", "hp", "disp"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.