Function to center and/or scale the coloumns of a matrix in various ways. The coloumns can be centered with their means or with supplied values, and they can be scaled with their standard deviations or with supplied values.
stdize(x, center = TRUE, scale = TRUE, avoid.zero.divisor = FALSE) stdize3(x, center = TRUE, scale = TRUE, avoid.zero.divisor = FALSE)
A logical, or a numeric vector. The values to subtract from
each column. If
A lgical, or a numeric vector. The values to divide each
column with. If
A logical. If
stdize standardizes the coloumns of a matrix by subtracting their
means (or the supplied values) and dividing by their standard deviations (or
the supplied values).
TRUE, division-by-zero is guarded
against by substituting any 0 in
center (either calculated or
supplied) with 1 prior to division.
The main difference between
scale is that
stdize divides by the standard deviations even when
stdize3 is a variant with a three-element list as output (
x, center, scale) and where
is also used to avoid centring (constant term in model matrix is unchanged).
Bjørn-Helge Mevik and Øyvind Langsrud
A <- matrix(rnorm(15, mean = 1), ncol = 3) stopifnot(all.equal(stdize(A), scale(A), check.attributes = FALSE)) ## These are different: stdize(A, center = FALSE) scale(A, center = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.