Learn R Programming

cglasso (version 1.1.2)

scale.datacggm: Scaling and Centering of “datacggm” Objects

Description

The method function scale.datacggm centers and/or scales the columns of a numeric matrix storaged in a ‘datacggm’ object.

Usage

# S3 method for datacggm
scale(x, center = TRUE, scale = TRUE)

Arguments

x

an object of class ‘datacggm’.

center

either a logical value or numeric-alike vector of length equal to the number of columns of x, where ‘numeric-alike’ means that as.numeric(.) will be applied successfully if is.numeric(.) is not true.

scale

either a logical value or a numeric-alike vector of length equal to the number of columns of x.

Value

The method function ‘scale.datacggm’ returns an object of class datacggm. The numeric centering and scalings used (if any) are returned as attributes "scaled:center" and "scaled:scale".

Details

The value of center determines how column centering is performed. If center is a numeric-alike vector with length equal to the number of columns of x, then each column of x has the corresponding value from center subtracted from it. If center is TRUE then centering is done by subtracting the column means (omitting censoring values) of x$X from their corresponding columns, and if center is FALSE, no centering is done. The same is done for x$lo and x$up.

The value of scale determines how column scaling is performed (after centering). If scale is a numeric-alike vector with length equal to the number of columns of x, then each column of x$X is divided by the corresponding value from scale. If scale is TRUE then scaling is done by dividing the (centered) columns of x$X by their standard deviations if center is TRUE, and the root mean square otherwise. If scale is FALSE, no scaling is done. The same is done for x$lo and x$up.

The root-mean-square for a (possibly centered) column is defined as \(\sqrt{\sum(x^2)/(n-1)}\), where \(x\) is a vector of observed values and \(n\) is the number of observed values. In the case center = TRUE, this is the same as the standard deviation, but in general it is not. (To scale by the standard deviations without centering, use scale(x, center = FALSE, scale = apply(x, 2, sd, na.rm = TRUE)).)

See Also

datacggm.

Examples

Run this code
# NOT RUN {
set.seed(123)

n <- 100L
p <- 3L
mu <- rep(1L, p)
X <- rdatacggm(n = n, mu = mu, probr = 0.05, probl = 0.05)
centered.X <- scale(X)
centered.X
attr(centered.X, "scaled:center")
attr(centered.X, "scaled:scale")
# }

Run the code above in your browser using DataLab