Skip to contents

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

Eli Holmes, NOAA, Seattle, USA.

Examples

zscore(1:10)
#>  [1] -1.4863011 -1.1560120 -0.8257228 -0.4954337 -0.1651446  0.1651446
#>  [7]  0.4954337  0.8257228  1.1560120  1.4863011
x <- zscore(matrix(c(NA, rnorm(28), NA), 3, 10))
# mean is 0 and variance is 1
apply(x, 1, mean, na.rm = TRUE)
#> [1]  4.319943e-17 -4.025914e-17  2.932165e-17
apply(x, 1, var, na.rm = TRUE)
#> [1] 1 1 1