ewma: Exponentially Weighted Moving Average (EWMA)

Description Usage Arguments Details Value Methods (by class) References Examples

Description

Test on device-events using the EWMA method based on the normal distribution.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
ewma(df, ...)

## S3 method for class 'mds_ts'
ewma(df, ts_event = c(Count = "nA"), analysis_of = NA, ...)

## Default S3 method:
ewma(
  df,
  analysis_of = NA,
  eval_period = NULL,
  delta = 3,
  lambda = 0.85,
  zero_rate = 1/3,
  mu = NULL,
  sigma = NULL,
  ...
)

Arguments

df

Required input data frame of class mds_ts or, for generic usage, any data frame with the following columns:

time

Unique times of class Date

event

Either the event count or rate of class numeric

...

Further arguments passed onto ewma methods

ts_event

Required if df is of class mds_ts. Named string indicating the variable corresponding to the event count or rate. Rate must be calculated in a separate column in df as it is not calculated by default. The name of the string is an English description of what was analyzed.

Default: c("Count"="nA") corresponding to the event count column in mds_ts objects. Name is generated from mds_ts metadata.

Example: c("Rate of Bone Filler Events in Canada"="rate")

analysis_of

Optional string indicating the English description of what was analyzed. If specified, this will override the name of the ts_event string parameter.

Default: NA indicates no English description for plain df data frames, or ts_event English description for df data frames of class mds_ts.

Example: "Rate of bone cement leakage"

eval_period

Optional positive integer indicating the number of unique times counting in reverse chronological order to assess. This will be used to establish the process mean and moving range.

Default: NULL considers all times in df.

delta

Required number of sigmas at which to detect a mean shift. Sigma in this context refers to the estimated standard deviation of the EWMA statistic.

Default: 3 detects a EWMA shift of three sigmas.

lambda

Required "memory" parameter in the range (0, 1]. Lower values assign more weight to prior measurements. A value of 1 indicates no memory and only considers the current measurement.

Default: 0.85 assigns higher weight to the current measurement with "light memory" of prior measurements.

zero_rate

Required maximum proportion of events in df (constrained by eval_period) containing zeroes for this algorithm to run. Because EWMA does not perform well on time series with many 0 values, a value >0 is recommended.

Default: 1/3 requires no more than 1/3 zeros in events in df in order to run.

mu

Optional value of the in-control process mean, typically measured from historical data.

Default: NULL estimates the in-control process mean from timepoints prior to the most recent timepoint in the time series. The most recent measurement is then tested using this estimate.

sigma

Optional value of the in-control process standard deviation, typically measured from historical data.

Default: NULL estimates the in-control process standard deviation from timepoints prior to the most recent timepoint in the time series using a moving range calculation assuming an n=2 sampling approach. The most recent measurement is then tested using this estimate.

Details

Function ewma() is an implementation of the EWMA method originally proposed by S.W. Roberts based on the normal distribution. EWMA is part of the family of statistical process control tests.

Value

A named list of class mdsstat_test object, as follows:

test_name

Name of the test run

analysis_of

English description of what was analyzed

status

Named boolean of whether the test was run. The name contains the run status.

result

A standardized list of test run results: statistic for the test statistic, lcl and ucl for the 95 confidence bounds, p for the p-value, signal status, and signal_threshold.

params

The test parameters

data

The data on which the test was run

Methods (by class)

References

S. W. Roberts (1959) Control Chart Tests Based on Geometric Moving Averages, Technometrics, 1:3, 239-250, DOI: 10.1080/00401706.1959.10489860

Examples

1
2
3
4
5
6
7
8
9
# Basic Example
data <- data.frame(time=c(1:25), event=as.integer(stats::rnorm(25, 100, 25)))
a1 <- ewma(data)
# Example using an mds_ts object
a2 <- ewma(mds_ts[[3]])
# Example using a derived rate as the "event"
data <- mds_ts[[3]]
data$rate <- ifelse(is.na(data$nA), 0, data$nA) / data$exposure
a3 <- ewma(data, c(Rate="rate"))

mdsstat documentation built on March 13, 2020, 2:58 a.m.