single_CUSUM {HDCD} | R Documentation |
CUSUM transformation of matrix at a specific position
Description
R wrapper for C function computing the CUSUM transformation of matrix over an interval (s,e]
evaluated at a specific position. For compatibility with C indexing, the user should subtract 1
from s
, e
and v
when supplying the arguments to the function. If start and stop are not supplied, the CUSUM is computed over the full data, so (s,e] = (0,n]
.
Usage
single_CUSUM(X, start = NULL, stop = NULL, pos)
Arguments
X |
Matrix of observations, where each row contains a time series |
start |
Starting point of interval over which the CUSUM should be computed, subtracted by one |
stop |
Ending point of interval over which the CUSUM should be computed, subtracted by one |
pos |
Position at which the CUSUM should be evaluated, subtracted by one |
Value
A vector of CUSUM values, each corresponding to a row of the input matrix. The i
-th element corresponds to the CUSUM transformation of the i
-th row of X
, computed over the interval (\code{start}+1,\code{end}+1]
and evaluated at position \code{pos}
, i.e.
\sqrt{\frac{e-v}{(e-s)(v-s)}}\sum_{t=s+1}^v X_{i,t} - \sqrt{\frac{v-s}{(e-s)(e-v)}}\sum_{t=v+1}^e X_{i,t}
,
where s = (\code{start}+1)
, e = (\code{stop}+1)
and v = \code{pos}+1
.
Examples
n = 10
p = 10
set.seed(101)
X = matrix(rnorm(n*p), ncol = n, nrow=p)
# CUSUM over the full data (s,e] = (0,n] evaluated at position v=4
position = 4
X_cusum_single = single_CUSUM(X,pos = position-1)
X_cusum_single
# verifying that this corresponds to the 4-th row of output of CUSUM():
X_cusum = CUSUM(X)
X_cusum[,4]