Skip to contents

Make rolling zscore attribute from timeseries.

Usage

ts_zscore(data, grp = NULL, width = 7, align = "right", threshold = 3)

Arguments

data

a dataframe containing the timeseries attribute

grp

character list of attributes to group by

width

integer value indicating widtch of window

align

character indicating which side of value window will be aligned. Default is `right`, which only uses past values. Other options are `center` and `left`.

threshold

integer indicating zscore away from center function will flag value as an outlier

Value

a dataframe with zcore and zscore_flag attributes

Examples

if (FALSE) { # \dontrun{
data.frame(index = 1:60, value = c(rnorm(50, 10, 3), rnorm(10, 25, 0))) %>%
 na.omit() %>%
 ts_zscore(width = 30)

c(10, 30) %>%
 map(~data.frame(index = 1:60
                 ,value = c(rnorm(50, 10, 3), rnorm(10, 25, 0))) %>%
       na.omit() %>%
       ts_zscore(width = .x)) %>%
 reduce(bind_rows)
} # }