Learn R Programming

spatialEco (version 2.0-3)

z_normalization: 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")
)

Value

vector of z normalized data

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

Author

Jeffrey S. Evans <jeffrey_evans@tnc.org>

References

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

Examples

Run this code
 # 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") ) 
 

Run the code above in your browser using DataLab