zscore: z-score a vector or matrix

View source: R/utility_functions.R

zscoreR Documentation

z-score a vector or matrix

Description

Removes the mean and standardizes the variance to 1.

Usage

zscore(x, mean.only = FALSE)

Arguments

x

n x T matrix of numbers

mean.only

If TRUE, only remove the mean.

Details

n = number of observation (y) time series. T = number of time steps in the time series.

The z-scored values (z) of a matrix of y values are z_i = \Sigma^{-1}(y_i-\bar{y}) where \Sigma is a diagonal matrix with the standard deviations of each time series (row) along the diagonal, and \bar{y} is a vector of the means.

Value

n x T matrix of z-scored values.

Author(s)

Eli Holmes, NOAA, Seattle, USA.

Examples

zscore(1:10)
x <- zscore(matrix(c(NA, rnorm(28), NA), 3, 10))
# mean is 0 and variance is 1
apply(x, 1, mean, na.rm = TRUE)
apply(x, 1, var, na.rm = TRUE)

MARSS documentation built on May 31, 2023, 9:28 p.m.