Title: | Change Point Analysis Tests |
---|---|
Description: | Implements several statistical tests for structural change, specifically the tests featured in Horváth, Rice and Miller (in press): CUSUM (with weighted/trimmed variants), Darling-Erdös, Hidalgo-Seo, Andrews, and the new Rényi-type test. |
Authors: | Curtis Miller [aut, cre] |
Maintainer: | Curtis Miller <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-03-05 04:03:29 UTC |
Source: | https://github.com/ntguardian/cpat |
Hook triggered when package attached
.onAttach(lib, pkg)
.onAttach(lib, pkg)
lib |
a character string giving the library directory where the package defining the namespace was found |
pkg |
a character string giving the name of the package |
CPAT:::.onAttach(.libPaths()[1], "CPAT")
CPAT:::.onAttach(.libPaths()[1], "CPAT")
Concatenate and form strings (with space separation)
x %s% y
x %s% y
x |
One object |
y |
Another object |
A string combining x
and y
with a space separating them
`%s%` <- CPAT:::`%s%` "Hello" %s% "world"
`%s%` <- CPAT:::`%s%` "Hello" %s% "world"
Concatenate and form strings (no space separation)
x %s0% y
x %s0% y
x |
One object |
y |
Another object |
A string combining x
and y
`%s0%` <- CPAT:::`%s0%` "Hello" %s0% "world"
`%s0%` <- CPAT:::`%s0%` "Hello" %s0% "world"
This implements Andrews' test for end-of-sample change, as described by Andrews (2003). This test was derived for detecting a change in univariate data. See (Andrews 2003) for a description of the test.
andrews_test(x, M, pval = TRUE, stat = TRUE)
andrews_test(x, M, pval = TRUE, stat = TRUE)
x |
Vector of the data to test |
M |
Numeric index of the location of the first potential change point |
pval |
If |
stat |
If |
If both pval
and stat
are TRUE
, a list
containing both; otherwise, a number for one or the other, depending
on which is TRUE
Andrews DWK (2003). “End-of-Sample Instability Tests.” Econometrica, 71(6), 1661–1694. ISSN 00129682, 14680262, https://www.jstor.org/stable/1555535.
CPAT:::andrews_test(rnorm(1000), M = 900)
CPAT:::andrews_test(rnorm(1000), M = 900)
This implements Andrews' test for end-of-sample change, as described by Andrews (2003). This test was derived for detecting a change in multivarate data, aso originally described. See (Andrews 2003) for a description of the test.
andrews_test_reg(formula, data, M, pval = TRUE, stat = TRUE)
andrews_test_reg(formula, data, M, pval = TRUE, stat = TRUE)
formula |
The regression formula, which will be passed to
|
data |
|
M |
Numeric index of the location of the first potential change point |
pval |
If |
stat |
If |
If both pval
and stat
are TRUE
, a list
containing both; otherwise, a number for one or the other, depending
on which is TRUE
Andrews DWK (2003). “End-of-Sample Instability Tests.” Econometrica, 71(6), 1661–1694. ISSN 00129682, 14680262, https://www.jstor.org/stable/1555535.
x <- rnorm(1000) y <- 1 + 2 * x + rnorm(1000) df <- data.frame(x, y) CPAT:::andrews_test_reg(y ~ x, data = df, M = 900)
x <- rnorm(1000) y <- 1 + 2 * x + rnorm(1000) df <- data.frame(x, y) CPAT:::andrews_test_reg(y ~ x, data = df, M = 900)
Performs Andrews' test for end-of-sample structural change, as described in
(Andrews 2003). This function works for both univariate and
multivariate data depending on the nature of x
and whether
formula
is specified. This function is thus an interface to
andrews_test
and andrews_test_reg
; see the
documentation of those functions for more details.
Andrews.test(x, M, formula = NULL)
Andrews.test(x, M, formula = NULL)
x |
Data to test for change in mean (either a vector or
|
M |
Numeric index of the location of the first potential change point |
formula |
The regression formula, which will be passed to
|
A htest
-class object containing the results of the test
Andrews DWK (2003). “End-of-Sample Instability Tests.” Econometrica, 71(6), 1661–1694. ISSN 00129682, 14680262, https://www.jstor.org/stable/1555535.
Andrews.test(rnorm(1000), M = 900) x <- rnorm(1000) y <- 1 + 2 * x + rnorm(1000) df <- data.frame(x, y) Andrews.test(df, y ~ x, M = 900)
Andrews.test(rnorm(1000), M = 900) x <- rnorm(1000) y <- 1 + 2 * x + rnorm(1000) df <- data.frame(x, y) Andrews.test(df, y ~ x, M = 900)
Data set representing the returns of an industry portfolio representing the banking industry based on company four-digit SIC codes, obtained from the data library maintained by Kenneth French. Data ranges from July 1, 1926 to October 31, 2017.
banks
banks
A data frame with 24099 rows and 1 variable:
The return of a portfolio representing the banking industry
Row names are dates in YYYY-MM-DD format.
http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html
Makes package startup message.
CPAT_startup_message()
CPAT_startup_message()
CPAT:::CPAT_startup_message()
CPAT:::CPAT_startup_message()
Estimate the variance (using the sum of squared errors) with an estimator that is consistent when the mean changes at a known point.
cpt_consistent_var(x, k)
cpt_consistent_var(x, k)
x |
A numeric vector for the data set |
k |
The potential change point at which the data set is split |
This is the estimator
where and
. In this implementation,
is
computed automatically as
length(x)
and k
corresponds to
, a potential change point.
The estimated change-consistent variance
CPAT:::cpt_consistent_var(c(rnorm(500, mean = 0), rnorm(500, mean = 1)), k = 500)
CPAT:::cpt_consistent_var(c(rnorm(500, mean = 0), rnorm(500, mean = 1)), k = 500)
Performs the (univariate) CUSUM test for change in mean, as described in
(Rice et al. ). This is effectively an interface to
stat_Vn
; see its documentation for more details. p-values are
computed using pkolmogorov
, which represents the limiting
distribution of the statistic under the null hypothesis.
CUSUM.test(x, use_kernel_var = FALSE, stat_plot = FALSE, kernel = "ba", bandwidth = "and")
CUSUM.test(x, use_kernel_var = FALSE, stat_plot = FALSE, kernel = "ba", bandwidth = "and")
x |
Data to test for change in mean |
use_kernel_var |
Set to |
stat_plot |
Whether to create a plot of the values of the statistic at all potential change points |
kernel |
If character, the identifier of the kernel function as used in
cointReg (see |
bandwidth |
If character, the identifier for how to compute the
bandwidth as defined in cointReg (see
|
A htest
-class object containing the results of the test
Rice G, Miller C, Horváth L (????). “A new class of change point test of Rényi type.” in-press.
CUSUM.test(rnorm(1000)) CUSUM.test(rnorm(1000), use_kernel_var = TRUE, kernel = "bo", bandwidth = "nw")
CUSUM.test(rnorm(1000)) CUSUM.test(rnorm(1000), use_kernel_var = TRUE, kernel = "bo", bandwidth = "nw")
Performs the (univariate) Darling-Erdös test for change in mean, as described
in (Rice et al. ). This is effectively an interface
to stat_de
; see its documentation for more details. p-values
are computed using pdarling_erdos
, which represents the
limiting distribution of the test statistic under the null hypothesis when
a
and b
are chosen appropriately. (Change those parameters at
your own risk!)
DE.test(x, a = log, b = log, use_kernel_var = FALSE, stat_plot = FALSE, kernel = "ba", bandwidth = "and")
DE.test(x, a = log, b = log, use_kernel_var = FALSE, stat_plot = FALSE, kernel = "ba", bandwidth = "and")
x |
Data to test for change in mean |
a |
The function that will be composed with
|
b |
The function that will be composed with
|
use_kernel_var |
Set to |
stat_plot |
Whether to create a plot of the values of the statistic at all potential change points |
kernel |
If character, the identifier of the kernel function as used in
cointReg (see |
bandwidth |
If character, the identifier for how to compute the
bandwidth as defined in cointReg (see
|
A htest
-class object containing the results of the test
Rice G, Miller C, Horváth L (????). “A new class of change point test of Rényi type.” in-press.
DE.test(rnorm(1000)) DE.test(rnorm(1000), use_kernel_var = TRUE, kernel = "bo", bandwidth = "nw")
DE.test(rnorm(1000)) DE.test(rnorm(1000), use_kernel_var = TRUE, kernel = "bo", bandwidth = "nw")
Function for computing the value of the density function of the limiting distribution of the Rényi-type statistic.
dZn(x, summands = NULL)
dZn(x, summands = NULL)
x |
Point at which to evaluate the density function (note that this parameter is not vectorized) |
summands |
Number of summands to use in summation (the default should be machine accurate) |
Value of the density function at
CPAT:::dZn(1)
CPAT:::dZn(1)
Data set containing the five factors described by Fama and French (2015), from the data library maintained by Kenneth French. Data ranges from July 1, 1963 to October 31, 2017.
ff
ff
A data frame with 13679 rows and 6 variables:
Market excess returns
The risk-free rate of return
The return on a diversified portfolio of small stocks minus return on a diversified portfolio of big stocks
The return of a portfolio of stocks with a high book-to-market (B/M) ratio minus the return of a portfolio of stocks with a low B/M ratio
The return of a portfolio of stocks with robust profitability minus a portfolio of stocks with weak profitability
The return of a portfolio of stocks with conservative investment minus the return of a portfolio of stocks with aggressive investment
Row names are dates in YYYYMMDD format.
http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html
Computes the estimates of the long-run variance in a change point context, as
described in (Rice et al. ). By default it uses
kernel and bandwidth selection as used in the package cointReg, though
changing the parameters kernel
and bandwidth
can change this
behavior. If cointReg is not installed, the Bartlett internal (defined
internally) will be used and the bandwidth will be the square root of the
sample size.
get_lrv_vec(dat, kernel = "ba", bandwidth = "and")
get_lrv_vec(dat, kernel = "ba", bandwidth = "and")
dat |
The data vector |
kernel |
If character, the identifier of the kernel function as used in
cointReg (see |
bandwidth |
If character, the identifier for how to compute the
bandwidth as defined in cointReg (see
|
A vector of estimates of the long-run variance
Rice G, Miller C, Horváth L (????). “A new class of change point test of Rényi type.” in-press.
x <- rnorm(1000) CPAT:::get_lrv_vec(x) CPAT:::get_lrv_vec(x, kernel = "pa", bandwidth = "nw")
x <- rnorm(1000) CPAT:::get_lrv_vec(x) CPAT:::get_lrv_vec(x, kernel = "pa", bandwidth = "nw")
Compute some weights for long-run variance. This code comes directly from the
source code of cointReg; see getLongRunWeights
.
getLongRunWeights(n, bandwidth, kernel = "ba")
getLongRunWeights(n, bandwidth, kernel = "ba")
n |
Length of weights' vector |
bandwidth |
A number for the bandwidth |
kernel |
The kernel function; see |
List with components w
containing the vector of weights and
upper
, the index of the largest non-zero entry in w
CPAT:::getLongRunWeights(10, 1)
CPAT:::getLongRunWeights(10, 1)
Performs the (univariate) Rényi-type test for change in mean, as described in
(Rice et al. ). This is effectively an interface to
stat_Zn
; see its documentation for more details. p-values are
computed using pZn
, which represents the limiting distribution
of the test statistic under the null hypothesis, which represents the
limiting distribution of the test statistic under the null hypothesis when
kn
represents a sequence satisfying
and
as
. (
log
and
sqrt
should be good choices.)
HR.test(x, kn = log, use_kernel_var = FALSE, stat_plot = FALSE, kernel = "ba", bandwidth = "and")
HR.test(x, kn = log, use_kernel_var = FALSE, stat_plot = FALSE, kernel = "ba", bandwidth = "and")
x |
Data to test for change in mean |
kn |
A function corresponding to the trimming parameter |
use_kernel_var |
Set to |
stat_plot |
Whether to create a plot of the values of the statistic at all potential change points |
kernel |
If character, the identifier of the kernel function as used in
cointReg (see |
bandwidth |
If character, the identifier for how to compute the
bandwidth as defined in cointReg (see
|
A htest
-class object containing the results of the test
Rice G, Miller C, Horváth L (????). “A new class of change point test of Rényi type.” in-press.
HR.test(rnorm(1000)) HR.test(rnorm(1000), use_kernel_var = TRUE, kernel = "bo", bandwidth = "nw")
HR.test(rnorm(1000)) HR.test(rnorm(1000), use_kernel_var = TRUE, kernel = "bo", bandwidth = "nw")
Performs the (univariate) Hidalgo-Seo test for change in mean, as described
in (Rice et al. ). This is effectively an interface
to stat_hs
; see its documentation for more details. p-values
are computed using phidalgo_seo
, which represents the limiting
distribution of the test statistic when the null hypothesis is true.
HS.test(x, corr = TRUE, stat_plot = FALSE)
HS.test(x, corr = TRUE, stat_plot = FALSE)
x |
Data to test for change in mean |
corr |
If |
stat_plot |
Whether to create a plot of the values of the statistic at all potential change points |
A htest
-class object containing the results of the test
Rice G, Miller C, Horváth L (????). “A new class of change point test of Rényi type.” in-press.
HS.test(rnorm(1000)) HS.test(rnorm(1000), corr = FALSE)
HS.test(rnorm(1000)) HS.test(rnorm(1000), corr = FALSE)
CDF for the limiting distribution of the Darling-Erdös statistic.
pdarling_erdos(q)
pdarling_erdos(q)
q |
Quantile input to CDF |
If is the random variable with this distribution, the
quantity
CPAT:::pdarling_erdos(0.1)
CPAT:::pdarling_erdos(0.1)
CDF of the limiting distribution of the Hidalgo-Seo statistic
phidalgo_seo(q)
phidalgo_seo(q)
q |
Quantile input to CDF |
If is the random variable following the limiting
distribution, the quantity
CPAT:::phidalgo_seo(0.1)
CPAT:::phidalgo_seo(0.1)
CDF of the Kolmogorov distribution.
pkolmogorov(q, summands = ceiling(q * sqrt(72) + 3/2))
pkolmogorov(q, summands = ceiling(q * sqrt(72) + 3/2))
q |
Quantile input to CDF |
summands |
Number of summands for infinite sum (the default should have machine accuracy) |
If is the random variable following the Kolmogorov
distribution, the quantity
CPAT:::pkolmogorov(0.1)
CPAT:::pkolmogorov(0.1)
CDF for the limiting distribution of the Rènyi-type statistic.
pZn(q, summands = NULL)
pZn(q, summands = NULL)
q |
Quantile input to CDF |
summands |
Number of summands for infinite sum; if |
If is the random variable following the limiting
distribution, the quantity
CPAT:::pZn(0.1)
CPAT:::pZn(0.1)
Quantile function for the limiting distribution of the Darling-Erdös statistic.
qdarling_erdos(p)
qdarling_erdos(p)
p |
The probability associated with the desired quantile |
The quantile associated with p
CPAT:::qdarling_erdos(0.5)
CPAT:::qdarling_erdos(0.5)
Quantile function for the limiting distribution of the Hidalgo-Seo statistic
qhidalgo_seo(p)
qhidalgo_seo(p)
p |
The probability associated with the desired quantile |
A The quantile associated with p
CPAT:::qhidalgo_seo(0.5)
CPAT:::qhidalgo_seo(0.5)
Quantile function for the Kolmogorov distribution.
qkolmogorov(p, summands = 500, interval = c(0, 100), tol = .Machine$double.eps, ...)
qkolmogorov(p, summands = 500, interval = c(0, 100), tol = .Machine$double.eps, ...)
p |
Value of the CDF at the quantile |
summands |
Number of summands for infinite sum |
interval , tol , ...
|
Arguments to be passed to
|
This function uses uniroot
for finding this quantity,
and many of the the accepted parameters are arguments for that function; see
its documentation for more details.
The quantile associated with p
CPAT:::qkolmogorov(0.5)
CPAT:::qkolmogorov(0.5)
Quantile function for the limiting distribution of the Rènyi-type statistic.
qZn(p, summands = 500, interval = c(0, 100), tol = .Machine$double.eps, ...)
qZn(p, summands = 500, interval = c(0, 100), tol = .Machine$double.eps, ...)
p |
Value of the CDF at the quantile |
summands |
Number of summands for infinite sum |
interval , tol , ...
|
Arguments to be passed to
|
This function uses uniroot
for finding this quantity,
and many of the the accepted parameters are arguments for that function; see
its documentation for more details.
The quantile associated with p
CPAT:::qZn(0.5)
CPAT:::qZn(0.5)
This function simulates univariate data with a structural change.
rchangepoint(n, changepoint = NULL, mean1 = 0, mean2 = 0, dist = rnorm, meanparam = "mean", ...)
rchangepoint(n, changepoint = NULL, mean1 = 0, mean2 = 0, dist = rnorm, meanparam = "mean", ...)
n |
An integer for the data set's sample size |
changepoint |
An integer for where the change point occurs |
mean1 |
The mean prior to the change point |
mean2 |
The mean after the change point |
dist |
The function with which random data will be generated |
meanparam |
A string for the parameter in |
... |
Other arguments to be passed to dist |
This function generates artificial change point data, where up to the
specified change point the data has one mean, and after the point it has a
different mean. By default, the function simulates standard Normal data with
no change. If changepoint
is NULL
, then by default the change
point will be at about the middle of the data.
A vector of the simulated data
CPAT:::rchangepoint(500) CPAT:::rchangepoint(500, changepoint = 10, mean2 = 2, sd = 2) CPAT:::rchangepoint(500, changepoint = 250, dist = rexp, meanparam = "rate", mean1 = 1, mean2 = 2)
CPAT:::rchangepoint(500) CPAT:::rchangepoint(500, changepoint = 10, mean2 = 2, sd = 2) CPAT:::rchangepoint(500, changepoint = 250, dist = rexp, meanparam = "rate", mean1 = 1, mean2 = 2)
Simulates multiple realizations of the Darling-Erdös statistic.
sim_de_stat(size, a = log, b = log, use_kernel_var = FALSE, kernel = "ba", bandwidth = "and", n = 500, gen_func = rnorm, args = NULL, parallel = FALSE)
sim_de_stat(size, a = log, b = log, use_kernel_var = FALSE, kernel = "ba", bandwidth = "and", n = 500, gen_func = rnorm, args = NULL, parallel = FALSE)
size |
Number of realizations to simulate |
a |
The function that will be composed wit
|
b |
The function that will be composed with
|
use_kernel_var |
Set to |
kernel |
If character, the identifier of the kernel function as used in
the cointReg (see documentation for
|
bandwidth |
If character, the identifier of how to compute the bandwidth
as defined in the cointReg package (see
documentation for |
n |
The sample size for each realization |
gen_func |
The function generating the random sample from which the statistic is computed |
args |
A list of arguments to be passed to |
parallel |
Whether to use the foreach and doParallel packages to parallelize simulation (which needs to be initialized in the global namespace before use) |
If use_kernel_var
is set to TRUE
, long-run variance estimation
using kernel-based techniques will be employed; otherwise, a technique
resembling standard variance estimation will be employed. Any technique
employed, though, will account for the potential break points, as described
in Rice et al. (). See the documentation for
stat_de
for more details.
The parameters kernel
and bandwidth
control parameters for
long-run variance estimation using kernel methods. These parameters will be
passed directly to stat_de
.
A vector of simulated realizations of the Darling-Erdös statistic
Andrews DWK (1991).
“Heteroskedasticity and Autocorrelation Consistent Covariance Matrix Estimation.”
Econometrica, 59(3), 817-858.
Rice G, Miller C, Horváth L (????).
“A new class of change point test of Rényi type.”
in-press.
CPAT:::sim_de_stat(100) CPAT:::sim_de_stat(100, use_kernel_var = TRUE, gen_func = CPAT:::rchangepoint, args = list(changepoint = 250, mean2 = 1))
CPAT:::sim_de_stat(100) CPAT:::sim_de_stat(100, use_kernel_var = TRUE, gen_func = CPAT:::rchangepoint, args = list(changepoint = 250, mean2 = 1))
Simulates multiple realizations of the Hidalgo-Seo statistic.
sim_hs_stat(size, corr = TRUE, gen_func = rnorm, args = NULL, n = 500, parallel = FALSE, use_kernel_var = FALSE, kernel = "ba", bandwidth = "and")
sim_hs_stat(size, corr = TRUE, gen_func = rnorm, args = NULL, n = 500, parallel = FALSE, use_kernel_var = FALSE, kernel = "ba", bandwidth = "and")
size |
Number of realizations to simulate |
corr |
Whether long-run variance should be computed under the assumption of correlated residuals |
gen_func |
The function generating the random sample from which the statistic is computed |
args |
A list of arguments to be passed to |
n |
The sample size for each realization |
parallel |
Whether to use the foreach and doParallel packages to parallelize simulation (which needs to be initialized in the global namespace before use) |
use_kernel_var |
Set to |
kernel |
If character, the identifier of the kernel function as used in
the cointReg (see documentation for
|
bandwidth |
If character, the identifier of how to compute the bandwidth
as defined in the cointReg package (see
documentation for |
If corr
is TRUE
, then the residuals of the data-generating
process are assumed to be correlated and the test accounts for this in
long-run variance estimation; see the documentation for stat_hs
for more details. Otherwise, the sample variance is the estimate for the
long-run variance, as described in Hidalgo and Seo (2013).
A vector of simulated realizations of the Hidalgo-Seo statistic
Andrews DWK (1991).
“Heteroskedasticity and Autocorrelation Consistent Covariance Matrix Estimation.”
Econometrica, 59(3), 817-858.
Hidalgo J, Seo MH (2013).
“Testing for structural stability in the whole sample.”
Journal of Econometrics, 175(2), 84 - 93.
ISSN 0304-4076, doi:10.1016/j.jeconom.2013.02.008, http://www.sciencedirect.com/science/article/pii/S0304407613000626.
CPAT:::sim_hs_stat(100) CPAT:::sim_hs_stat(100, gen_func = CPAT:::rchangepoint, args = list(changepoint = 250, mean2 = 1))
CPAT:::sim_hs_stat(100) CPAT:::sim_hs_stat(100, gen_func = CPAT:::rchangepoint, args = list(changepoint = 250, mean2 = 1))
Simulates multiple realizations of the CUSUM statistic when the long-run variance of the data is known.
sim_Vn(size, n = 500, gen_func = rnorm, sd = 1, args = NULL)
sim_Vn(size, n = 500, gen_func = rnorm, sd = 1, args = NULL)
size |
Number of realizations to simulate |
n |
The sample size for each realization |
gen_func |
The function generating the random sample from which the statistic is computed |
sd |
The square root of the second moment of the data |
args |
A list of arguments to be passed to |
A vector of simulated realizations of the CUSUM statistic
CPAT:::sim_Vn(100) CPAT:::sim_Vn(100, gen_func = CPAT:::rchangepoint, args = list(changepoint = 250, mean2 = 1))
CPAT:::sim_Vn(100) CPAT:::sim_Vn(100, gen_func = CPAT:::rchangepoint, args = list(changepoint = 250, mean2 = 1))
Simulates multiple realizations of the CUSUM statistic.
sim_Vn_stat(size, kn = function(n) { 1 }, tau = 0, use_kernel_var = FALSE, kernel = "ba", bandwidth = "and", n = 500, gen_func = rnorm, args = NULL, parallel = FALSE)
sim_Vn_stat(size, kn = function(n) { 1 }, tau = 0, use_kernel_var = FALSE, kernel = "ba", bandwidth = "and", n = 500, gen_func = rnorm, args = NULL, parallel = FALSE)
size |
Number of realizations to simulate |
kn |
A function returning a positive integer that is used in the definition of the trimmed CUSUSM statistic effectively setting the bounds over which the maximum is taken |
tau |
The weighting parameter for the weighted CUSUM statistic (defaults to zero for no weighting) |
use_kernel_var |
Set to |
kernel |
If character, the identifier of the kernel function as used in
the cointReg (see documentation for
|
bandwidth |
If character, the identifier of how to compute the bandwidth
as defined in the cointReg package (see
documentation for |
n |
The sample size for each realization |
gen_func |
The function generating the random sample from which the statistic is computed |
args |
A list of arguments to be passed to |
parallel |
Whether to use the foreach and doParallel packages to parallelize simulation (which needs to be initialized in the global namespace before use) |
This differs from sim_Vn()
in that the long-run variance is estimated
with this function, while sim_Vn()
assumes the long-run variance is
known. Estimation can be done in a variety of ways. If use_kernel_var
is set to TRUE
, long-run variance estimation using kernel-based
techniques will be employed; otherwise, a technique resembling standard
variance estimation will be employed. Any technique employed, though, will
account for the potential break points, as described in
Rice et al. (). See the documentation for
stat_Vn
for more details.
The parameters kernel
and bandwidth
control parameters for
long-run variance estimation using kernel methods. These parameters will be
passed directly to stat_Vn
.
Versions of the CUSUM statistic, such as the weighted or trimmed statistics,
can be simulated with the function by passing values to kn
and
tau
; again, see the documentation for stat_Vn
.
A vector of simulated realizations of the CUSUM statistic
Andrews DWK (1991).
“Heteroskedasticity and Autocorrelation Consistent Covariance Matrix Estimation.”
Econometrica, 59(3), 817-858.
Rice G, Miller C, Horváth L (????).
“A new class of change point test of Rényi type.”
in-press.
CPAT:::sim_Vn_stat(100) CPAT:::sim_Vn_stat(100, kn = function(n) {floor(0.1 * n)}, tau = 1/3, use_kernel_var = TRUE, gen_func = CPAT:::rchangepoint, args = list(changepoint = 250, mean2 = 1))
CPAT:::sim_Vn_stat(100) CPAT:::sim_Vn_stat(100, kn = function(n) {floor(0.1 * n)}, tau = 1/3, use_kernel_var = TRUE, gen_func = CPAT:::rchangepoint, args = list(changepoint = 250, mean2 = 1))
Simulates multiple realizations of the Rènyi-type statistic when the long-run variance of the data is known.
sim_Zn(size, kn, n = 500, gen_func = rnorm, args = NULL, sd = 1)
sim_Zn(size, kn, n = 500, gen_func = rnorm, args = NULL, sd = 1)
size |
Number of realizations to simulate |
kn |
A function returning a positive integer that is used in the definition of the Rènyi-type statistic effectively setting the bounds over which the maximum is taken |
n |
The sample size for each realization |
gen_func |
The function generating the random sample from which the statistic is computed |
args |
A list of arguments to be passed to |
sd |
The square root of the second moment of the data |
A vector of simulated realizations of the Rènyi-type statistic
CPAT:::sim_Zn(100, kn = function(n) {floor(log(n))}) CPAT:::sim_Zn(100, kn = function(n) {floor(log(n))}, gen_func = CPAT:::rchangepoint, args = list(changepoint = 250, mean2 = 1))
CPAT:::sim_Zn(100, kn = function(n) {floor(log(n))}) CPAT:::sim_Zn(100, kn = function(n) {floor(log(n))}, gen_func = CPAT:::rchangepoint, args = list(changepoint = 250, mean2 = 1))
Simulates multiple realizations of the Rènyi-type statistic.
sim_Zn_stat(size, kn = function(n) { floor(sqrt(n)) }, use_kernel_var = FALSE, kernel = "ba", bandwidth = "and", n = 500, gen_func = rnorm, args = NULL, parallel = FALSE)
sim_Zn_stat(size, kn = function(n) { floor(sqrt(n)) }, use_kernel_var = FALSE, kernel = "ba", bandwidth = "and", n = 500, gen_func = rnorm, args = NULL, parallel = FALSE)
size |
Number of realizations to simulate |
kn |
A function returning a positive integer that is used in the definition of the Rènyi-type statistic effectively setting the bounds over which the maximum is taken |
use_kernel_var |
Set to |
kernel |
If character, the identifier of the kernel function as used in
the cointReg (see documentation for
|
bandwidth |
If character, the identifier of how to compute the bandwidth
as defined in the cointReg package (see
documentation for |
n |
The sample size for each realization |
gen_func |
The function generating the random sample from which the statistic is computed |
args |
A list of arguments to be passed to |
parallel |
Whether to use the foreach and doParallel packages to parallelize simulation (which needs to be initialized in the global namespace before use) |
This differs from sim_Zn()
in that the long-run variance is estimated
with this function, while sim_Zn()
assumes the long-run variance is
known. Estimation can be done in a variety of ways. If use_kernel_var
is set to TRUE
, long-run variance estimation using kernel-based
techniques will be employed; otherwise, a technique resembling standard
variance estimation will be employed. Any technique employed, though, will
account for the potential break points, as described in
Rice et al. (). See the documentation for
stat_Zn
for more details.
The parameters kernel
and bandwidth
control parameters for
long-run variance estimation using kernel methods. These parameters will be
passed directly to stat_Zn
.
A vector of simulated realizations of the Rènyi-type statistic
Andrews DWK (1991).
“Heteroskedasticity and Autocorrelation Consistent Covariance Matrix Estimation.”
Econometrica, 59(3), 817-858.
Rice G, Miller C, Horváth L (????).
“A new class of change point test of Rényi type.”
in-press.
CPAT:::sim_Zn_stat(100) CPAT:::sim_Zn_stat(100, kn = function(n) {floor(log(n))}, use_kernel_var = TRUE, gen_func = CPAT:::rchangepoint, args = list(changepoint = 250, mean2 = 1))
CPAT:::sim_Zn_stat(100) CPAT:::sim_Zn_stat(100, kn = function(n) {floor(log(n))}, use_kernel_var = TRUE, gen_func = CPAT:::rchangepoint, args = list(changepoint = 250, mean2 = 1))
This function computes the Darling-Erdös statistic.
stat_de(dat, a = log, b = log, estimate = FALSE, use_kernel_var = FALSE, custom_var = NULL, kernel = "ba", bandwidth = "and", get_all_vals = FALSE)
stat_de(dat, a = log, b = log, estimate = FALSE, use_kernel_var = FALSE, custom_var = NULL, kernel = "ba", bandwidth = "and", get_all_vals = FALSE)
dat |
The data vector |
a |
The function that will be composed with
|
b |
The function that will be composed with
|
estimate |
Set to |
use_kernel_var |
Set to |
custom_var |
Can be a vector the same length as |
kernel |
If character, the identifier of the kernel function as used in
cointReg (see |
bandwidth |
If character, the identifier for how to compute the
bandwidth as defined in cointReg (see
|
get_all_vals |
If |
If is the weighted and trimmed CUSUM statistic
with weighting parameter
and trimming parameter
(see
stat_Vn
), then the Darling-Erdös statistic is
with and
(
is the natural logarithm of
). The parameter
a
corresponds to and
b
to
; these are both
log
by default.
See (Rice et al. ) to learn more.
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 changg
point in the second)
Rice G, Miller C, Horváth L (????). “A new class of change point test of Rényi type.” in-press.
CPAT:::stat_de(rnorm(1000)) CPAT:::stat_de(rnorm(1000), use_kernel_var = TRUE, bandwidth = "nw", kernel = "bo")
CPAT:::stat_de(rnorm(1000)) CPAT:::stat_de(rnorm(1000), use_kernel_var = TRUE, bandwidth = "nw", kernel = "bo")
This function computes the Hidalgo-Seo statistic for a change in mean model.
stat_hs(dat, estimate = FALSE, corr = TRUE, get_all_vals = FALSE, custom_var = NULL, use_kernel_var = FALSE, kernel = "ba", bandwidth = "and")
stat_hs(dat, estimate = FALSE, corr = TRUE, get_all_vals = FALSE, custom_var = NULL, use_kernel_var = FALSE, kernel = "ba", bandwidth = "and")
dat |
The data vector |
estimate |
Set to |
corr |
If |
get_all_vals |
If |
custom_var |
Can be a vector the same length as |
use_kernel_var |
Set to |
kernel |
If character, the identifier of the kernel function as used in
cointReg (see |
bandwidth |
If character, the identifier for how to compute the
bandwidth as defined in cointReg (see
|
For a data set with
observations, the test statistic is
where (
is the sample mean),
,
,
,
,
, and
.
If corr
is FALSE
, then the residuals are assumed to be
uncorrelated. Otherwise, the residuals are assumed to be correlated and
with
.
This statistic was presented in (Hidalgo and Seo 2013).
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)
Hidalgo J, Seo MH (2013). “Testing for structural stability in the whole sample.” Journal of Econometrics, 175(2), 84 - 93. ISSN 0304-4076, doi:10.1016/j.jeconom.2013.02.008, http://www.sciencedirect.com/science/article/pii/S0304407613000626.
CPAT:::stat_hs(rnorm(1000)) CPAT:::stat_hs(rnorm(1000), corr = FALSE)
CPAT:::stat_hs(rnorm(1000)) CPAT:::stat_hs(rnorm(1000), corr = FALSE)
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)
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)
dat |
The data vector |
kn |
A function corresponding to the trimming parameter |
tau |
The weighting parameter |
estimate |
Set to |
use_kernel_var |
Set to |
custom_var |
Can be a vector the same length as |
kernel |
If character, the identifier of the kernel function as used in
cointReg (see |
bandwidth |
If character, the identifier for how to compute the
bandwidth as defined in cointReg (see
|
get_all_vals |
If |
The definition of the statistic is
A more general version is
The parameter kn
corresponds to the trimming parameter and
the parameter
tau
corresponds to .
See (Rice et al. ) for more details.
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)
Rice G, Miller C, Horváth L (????). “A new class of change point test of Rényi type.” in-press.
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")
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")
This function computes the Rényi-type statistic.
stat_Zn(dat, kn = function(n) { floor(sqrt(n)) }, estimate = FALSE, use_kernel_var = FALSE, custom_var = NULL, kernel = "ba", bandwidth = "and", get_all_vals = FALSE)
stat_Zn(dat, kn = function(n) { floor(sqrt(n)) }, estimate = FALSE, use_kernel_var = FALSE, custom_var = NULL, kernel = "ba", bandwidth = "and", get_all_vals = FALSE)
dat |
The data vector |
kn |
A function corresponding to the trimming parameter |
estimate |
Set to |
use_kernel_var |
Set to |
custom_var |
Can be a vector the same length as |
kernel |
If character, the identifier of the kernel function as used in
cointReg (see |
bandwidth |
If character, the identifier for how to compute the
bandwidth as defined in cointReg (see
|
get_all_vals |
If |
The definition of the statistic is
The parameter kn
corresponds to the trimming parameter .
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)
CPAT:::stat_Zn(rnorm(1000)) CPAT:::stat_Zn(rnorm(1000), kn = function(n) {floor(log(n))}) CPAT:::stat_Zn(rnorm(1000), use_kernel_var = TRUE, bandwidth = "nw", kernel = "bo")
CPAT:::stat_Zn(rnorm(1000)) CPAT:::stat_Zn(rnorm(1000), kn = function(n) {floor(log(n))}) CPAT:::stat_Zn(rnorm(1000), use_kernel_var = TRUE, bandwidth = "nw", kernel = "bo")