cusum
Detecting small changes in mathematical expectation using a cumulative sum.
| Library |
|
Syntax
Function call
-
iupper,ilower = cusum(x)— returns the first index of the upper and lower cumulative sumsx, which deviated by more than five standard deviations up and down from the target mathematical expectation, respectively. The minimum detectable expectation offset is one standard deviation. The function evaluates the target mathematical expectation and standard deviations for the first25selectionsx.
-
iupper,ilower = cusum(x,climit,mshift,tmean,tdev)— determines the number of standard deviationsclimitby which the upper and lower cumulative sums may deviate from the mathematical expectation. This call also determines the minimum detectable expectation value offset, the target expectation value, and the target standard deviation.
-
iupper,ilower = cusum(___,"all")— returns all indexes where the upper and lower cumulative amounts exceed the control limit.
-
iupper,ilower,uppersum,lowersum = cusum(___)— also returns the upper and lower cumulative amounts.
-
cusum(___)— without output arguments, builds the upper and lower cumulative sums normalized to one standard deviation above and below the target mathematical expectation.
Arguments
Input arguments
# climit — control limit
+
5 (by default) | the real scalar
Details
The reference limit, set as a real scalar, expressed in standard deviations.
# mshift — minimum expectation offset for detection
+
1 (by default) | the real scalar
Details
The minimum expectation value offset for detection, given as a real scalar expressed in standard deviations.
Name-value input arguments
# out — type of output data
+
:plot (by default) | :data
Details
Type of output data:
-
:plot— the function returns a graph; -
:data— the function returns data.
Output arguments
# iupper, ilower — indexes of points beyond the control
+
integer scalars | integer vectors
Details
Indexes of points beyond the control, returned as integer scalars or vectors. If all samples of the signal are within the specified tolerance, the function cusum returns empty arguments iupper and ilower.
# uppersum, lowersum — upper and lower cumulative sums
+
vectors
Details
The upper and lower cumulative amounts returned as vectors.
Examples
Default values for the function cusum
Details
Let’s generate and build a graph 100-a selective random signal with a linear trend. To get reproducible results, reset the settings of the random number generator.
rnds = rand(1, 100)
trnd = range(0, 1, length=100)
fnc = rnds .+ trnd'
plot(vec(fnc))
Apply cusum to the function using the default values of the input arguments.
import EngeeDSP.Functions: cusum
cusum(fnc)
Let’s calculate the mathematical expectation and standard deviation for the former 25 samples. Apply cusum using these values as the target expectation and the target standard deviation. Let’s highlight the point at which the cumulative sum deviates by more than five standard deviations from the target mathematical expectation. Let’s set the minimum detectable expectation offset to one standard deviation.
import EngeeDSP.Functions: mean, std
mfnc = mean(fnc[1:25])
sfnc = std(fnc[1:25]).S
cusum(fnc, 5.0, 1.0, mfnc, sfnc)
Let’s repeat the calculation using a negative linear trend.
nnc = rnds .- trnd'
cusum(nnc)
Additional Info
CUSUM Control Chart
Details
The CUSUM control chart is designed to detect small increments in the mathematical expectation of a process.
The sequence is given with an estimated average and the estimated standard deviation . Determine the upper and lower cumulative amounts of the process using:
-
the upper cumulative amount
-
the lower amount
Variable , presented in cusum an argument mshift, is the number of standard deviations from the target mathematical expectation tmean which make the shift detectable.
The process violates the CUSUM test in the sample if it satisfies the condition or . The control limit presented in cusum an argument climit.
By default, the function returns the first detected violation. If the flag is specified "all", the function will return all violations.