Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rescale

Function for Standardizing by Centering and Dividing by 2 sd's


Description

This function standardizes a variable by centering and dividing by 2 sd's with exceptions for binary variables.

Usage

rescale(x, binary.inputs="center")

Arguments

x

a vector

binary.inputs

options for standardizing binary variables, default is center; 0/1 keeps original scale; -0.5,0.5 rescales 0 as -0.5 and 1 as 0.5; center substracts the mean; and full substracts the mean and divids by 2 sd.

Value

the standardized vector

Author(s)

References

Andrew Gelman. (2008). “Scaling regression inputs by dividing by two standard deviations”. Statistics in Medicine 27: 2865–2873. http://www.stat.columbia.edu/~gelman/research/published/standardizing7.pdf

See Also

Examples

# Set up the fake data
  n <- 100
  x <- rnorm (n, 2, 1)
  x1 <- rnorm (n)
  x1 <- (x1-mean(x1))/(2*sd(x1))   # standardization
  x2 <- rbinom (n, 1, .5)
  b0 <- 1
  b1 <- 1.5
  b2 <- 2
  y <- rbinom (n, 1, invlogit(b0+b1*x1+b2*x2))
  rescale(x, "full")
  rescale(y, "center")

arm

Data Analysis Using Regression and Multilevel/Hierarchical Models

v1.11-2
GPL (> 2)
Authors
Andrew Gelman [aut], Yu-Sung Su [aut, cre], Masanao Yajima [ctb], Jennifer Hill [ctb], Maria Grazia Pittau [ctb], Jouni Kerman [ctb], Tian Zheng [ctb], Vincent Dorie [ctb]
Initial release
2020-7-27

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.