r2sd: Scale a vector (or vectors) by two standard deviations

View source: R/r2sd.R

r2sdR Documentation

Scale a vector (or vectors) by two standard deviations


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)

r2sd_at(data, x)



a vector, likely in your data frame


what to do with NAs in the vector. Defaults to TRUE (i.e. passes over the missing observations)


a data frame


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_at(mtcars, c("mpg", "hp", "disp"))

stevemisc documentation built on April 12, 2022, 5:06 p.m.