Scale {Keng}R Documentation

Scale a vector

Description

Scale a vector

Usage

Scale(x, expected_M = NULL, expected_SD = NULL, oadvances = NULL)

Arguments

x

The original vector.

expected_M

The expected Mean of the scaled vector.

expected_SD

The expected Standard Deviation (unit) of the scaled vector.

oadvances

The distance the Origin of x advances by.

Details

To scale x, its origin, or unit (expected_SD), or both, could be changed.

If expected_M = 0 or NULL, and expected_SD = NULL, x would be mean-centered.

If expected_M is a non-zero number, and expected_SD = NULL, the mean of x would be transformed to expected_M.

If expected_M = 0 or NULL, and expected_SD = 1, x would be standardized to be its z-score with M = 0 and SD = 1.

The standardized score is not necessarily the z-score. If neither expected_M nor expected_SD is NULL, x would be standardized to be a vector whose mean and standard deviation would be expected_M and expected_SD, respectively. To standardize x, the mean and standard deviation of x are needed and computed, for which the missing values of x are removed if any.

If oadvances is not NULL, the origin of x will advance with the standard deviation being unchanged. In this case, Scale() could be used to pick points in simple slope analysis for moderation models. Note that when oadvances is not NULL, expected_M and expected_SD must be NULL.

Value

The scaled vector.

Examples

(x <- rnorm(10, 5, 2))
# Mean-center x.
Scale(x)
# Transform the mean of x to 3.
Scale(x, expected_M = 3)
# Transform x to its z-score.
Scale(x, expected_SD = 1)
# Standardize x with *M* = 100 and *SD* = 15.
Scale(x, expected_M = 100, expected_SD = 15)
# The origin of x advances by 3.
Scale(x, oadvances = 3)

[Package Keng version 2024.11.17 Index]