standardize: Standardize Data

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Standardize data by mean or standard deviation, with optional centering.

Usage

1
2
standardize(X, method=c("sd","mean"), mle=TRUE, center=FALSE)
standardise(X, method=c("sd","mean"), mle=TRUE, center=FALSE)

Arguments

X

A numeric vector, matrix, or data frame.

method

a string giving the standardization method to use, either "sd" (the default) or "mean". Partial matches are allowed.

mle

logical; if TRUE, then the maximum likelihood estimator of standard deviation rather than the unbiased estimator will be used. Has no effect if method is "mean".

center

logical; if TRUE, then after standardization, data will be centered to have mean (or column means) 0.

Details

standardize is an alternative to the base R function scale, offering more options. Data on a (-Inf, Inf) scale, such as normally distributed data, are generally standardized by dividing by the standard deviation. However, it is often more appropriate to standardize data on a [0, Inf) scale, such as Weibull or gamma distributed data, by dividing by the mean.

So far as the numerical values of the data are concerned, standardize(X, "sd", FALSE, TRUE) is equivalent to scale(X). See the note on attributes in Value, below.

standardise is an alias for standardize.

Value

A vector or matrix of the same dimension as X, with the attribute standardized, which is a list with elements scale and center. These have the same meanings as scaled:scale and scaled:center in the return value attributes of scale. If center is FALSE, then standardized@center will be NULL.

Author(s)

Daniel Dvorkin

See Also

scale in package base.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
set.seed(123)

X = rmvweisd(5, 1:3, 3:1)
standardize(X, "mean")
#           [,1]      [,2]      [,3]
# [1,] 0.4600131 0.8392135 1.3481948
# [2,] 1.0188317 1.0361609 1.3975700
# [3,] 1.5355348 0.3813876 0.6260400
# [4,] 0.5390977 1.7176610 0.9614062
# [5,] 1.4465227 1.0255769 0.6667891
# attr(,"standardized")
# attr(,"standardized")$scale
# [1] 0.2457062 0.6110324 1.0480777
# 
# attr(,"standardized")$center
# NULL

colMeans(standardize(X, "mean"))
# [1] 1 1 1


Search within the lcmix package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.