z_normalization: z normalization

View source: R/z_normalization.R

z_normalizationR Documentation

z normalization

Description

Z-normalizes a time series by subtracting its mean and dividing by the standard deviation or meadian and MAD

Usage

z_normalization(
  x,
  method = c("original", "modified"),
  na = c("keep", "remove")
)

Arguments

x

Timeseries vector to normalize

method

("original", "modified") Use the standard z normalization or modified version

na

Behavior of NA values, keep or remove

Value

vector of z normalized data

Note

The original method is to subtract x rom the mean then divide by sd whereas, modified uses the median and mad. For NA's if the argument is keep, an NA index is built and the NA's are re-inserted in to the resulting vector. The behavior of remove will entirely remove them and result in a vector length different than the input.

Author(s)

Jeffrey S. Evans <sage_insights@outlook.com>

References

Iglewicz, B. & D.C. Hoaglin (1993) How to Detect and Handle Outliers, American Society for Quality Control, Milwaukee, WI.

Examples

 # add data
 data(EuStockMarkets)
 d <- as.vector(EuStockMarkets[,1])

# Calculate Z score
summary(d)
summary(Z_org <- z_normalization(d) ) 
summary(Z_mod <- z_normalization(d, method="modified") )
  par(mfrow=c(3,1))
    plot(density(d), main="original timeseries")
    plot(density(Z_org), main="original z norm")
    plot(density(Z_mod), main="modified z norm")

# Check NA behavior, insert some NA's
d[c(100, 500, 1000, 1400)] <- NA
length(d)
length( z_normalization(d, na="keep") ) 
length( z_normalization(d, na="remove") ) 
 

spatialEco documentation built on May 20, 2026, 9:09 a.m.