This function computes the CUSUM statistic (and can compute weighted/trimmed
variants, depending on the values of kn
and tau
).
stat_Vn(dat, kn = function(n) { 1 }, tau = 0, estimate = FALSE,
use_kernel_var = FALSE, custom_var = NULL, kernel = "ba",
bandwidth = "and", get_all_vals = FALSE)
The data vector
A function corresponding to the trimming parameter \(t_T\) in the trimmed CUSUM variant; by default, is a function returning 1 (for no trimming)
The weighting parameter \(\tau\) for the weighted CUSUM statistic; by default, is 0 (for no weighting)
Set to TRUE
to return the estimated location of the
change point
Set to TRUE
to use kernel methods for long-run
variance estimation (typically used when the data is
believed to be correlated); if FALSE
, then the
long-run variance is estimated using
\(\hat{\sigma}^2_{T,t} = T^{-1}\left(
\sum_{s = 1}^t \left(X_s - \bar{X}_t\right)^2 +
\sum_{s = t + 1}^{T}\left(X_s -
\tilde{X}_{T - t}\right)^2\right)\), where
\(\bar{X}_t = t^{-1}\sum_{s = 1}^t X_s\) and
\(\tilde{X}_{T - t} = (T - t)^{-1}
\sum_{s = t + 1}^{T} X_s\)
Can be a vector the same length as dat
consisting of
variance-like numbers at each potential change point (so
each entry of the vector would be the "best estimate" of
the long-run variance if that location were where the
change point occured) or a function taking two parameters
x
and k
that can be used to generate this
vector, with x
representing the data vector and
k
the position of a potential change point; if
NULL
, this argument is ignored
If character, the identifier of the kernel function as used in
cointReg (see getLongRunVar
); if
function, the kernel function to be used for long-run variance
estimation (default is the Bartlett kernel in cointReg)
If character, the identifier for how to compute the
bandwidth as defined in cointReg (see
getBandwidth
); if function, a function
to use for computing the bandwidth; if numeric, the bandwidth
value to use (the default is to use Andrews' method, as used in
cointReg)
If TRUE
, return all values for the statistic at
every tested point in the data set
If both estimate
and get_all_vals
are FALSE
, the
value of the test statistic; otherwise, a list that contains the test
statistic and the other values requested (if both are TRUE
,
the test statistic is in the first position and the estimated change
point in the second)
The definition of the statistic is
$$T^{-1/2} \max_{1 \leq t \leq T} \hat{\sigma}_{t,T}^{-1} \left| \sum_{s = 1}^t X_s - \frac{t}{T}\sum_{s = 1}^T \right|$$
A more general version is
$$T^{-1/2} \max_{t_T \leq t \leq T - t_T} \hat{\sigma}_{t,T}^{-1} \left(\frac{t}{T} \left(\frac{T - t}{T}\right)\right)^{\tau} \left| \sum_{s = 1}^t X_s - \frac{t}{T}\sum_{s = 1}^T \right|$$
The parameter kn
corresponds to the trimming parameter \(t_T\) and
the parameter tau
corresponds to \(\tau\).
See horvathricemiller19CPAT for more details.
# NOT RUN {
CPAT:::stat_Vn(rnorm(1000))
CPAT:::stat_Vn(rnorm(1000), kn = function(n) {0.1 * n}, tau = 1/2)
CPAT:::stat_Vn(rnorm(1000), use_kernel_var = TRUE, bandwidth = "nw", kernel = "bo")
# }
Run the code above in your browser using DataLab