Test on device-events using the tabular CUSUM (CUmulative SUM) method.
cusum(df, ...)# S3 method for mds_ts
cusum(df, ts_event = c(Count = "nA"), analysis_of = NA, ...)
# S3 method for default
cusum(
df,
analysis_of = NA,
eval_period = NULL,
delta = 1,
H = NULL,
zero_rate = 1/3,
mu = NULL,
sigma = NULL,
...
)
Required input data frame of class mds_ts
or, for generic
usage, any data frame with the following columns:
Unique times of class Date
Either the event count or rate of class numeric
Further arguments passed onto cusum
methods
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")
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"
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
.
Required number of sigmas at which to detect a mean shift.
Default: 1
detects a mean shift of one sigma.
Optional positive number representing the decision interval bound. Lower values will result in a more sensitive test.
Default: NULL
uses a value of 5 times the estimated sigma.
Required maximum proportion of event
s in df
(constrained by eval_period
) containing zeroes for this algorithm to
run. Because CUSUM 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 event
s in
df
in order to run.
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.
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.
A named list of class mdsstat_test
object, as follows:
Name of the test run
English description of what was analyzed
Named boolean of whether the test was run. The name contains the run status.
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
.
The test parameters
The data on which the test was run
mds_ts
: CUSUM on mds_ts data
default
: CUSUM on general data
Function cusum()
is an implementation of the tabular CUSUM
method originally proposed by E.S. Page. CUSUM is part of the family of
statistical process control tests.
Page, E. S. (June 1954). "Continuous Inspection Scheme". Biometrika. 41 (1/2): 100<U+2013>115. doi:10.1093/biomet/41.1-2.100. JSTOR 2333009.
# NOT RUN {
# Basic Example
data <- data.frame(time=c(1:25), event=as.integer(stats::rnorm(25, 100, 25)))
a1 <- cusum(data)
# Example using an mds_ts object
a2 <- cusum(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 <- cusum(data, c(Rate="rate"))
# }
Run the code above in your browser using DataLab