Learn R Programming

robcp (version 0.3.8)

cor_cusum: A CUSUM-type test to detect changes in the correlation.

Description

Performs a CUSUM-based test on changes in Spearman's rho or Kendall's tau.

Usage

cor_cusum(x, version = c("tau", "rho"), method = "kernel", control = list(), 
          fpc = TRUE, tol = 1e-08, plot = FALSE)

Value

A list of the class "htest" containing the following components:

statistic

return value of the function cor_stat.

p.value

p-value (numeric).

alternative

alternative hypothesis (character string).

method

name of the performed test (character string).

cp.location

index of the estimated change point location (integer).

data.name

name of the data (character string).

lrv

list containing the compontents method, param and value.

Arguments

x

time series (matrix or ts object with numeric/integer values).

version

version of the test. Either rho or tau.

method

method for estimating the long run variance.

control

a list of control parameters.

fpc

finite population correction (boolean).

tol

tolerance of the distribution function (numeric), which is used do compute p-values.

plot

should the test statistic be plotted (cf. plot.cpStat)? Boolean.

Author

Sheila Görz

Details

The function perform a CUSUM-type test on changes in the correlation of a time series \(x\). Formally, the hypothesis pair can be written as $$H_0: \xi_1 = ... = \xi_n$$ $$vs.$$ $$H_1: \exists k \in \{1, ..., n-1\}: \xi_k \neq \xi_{k+1}$$ where \(\xi_i\) is a fluctuation measure (either Spearman's rho or Kendall's tau) for the \(i\)-th observations and \(n\) is the length of the time series. \(k\) is called a 'change point'.

The test statistic is computed using cor_stat and asymptotically follows a Kolmogorov distribution. To derive the p-value, the funtion pKSdist is used.

References

Wied, D., Dehling, H., Van Kampen, M., and Vogel, D. (2014). A fluctuation test for constant Spearman’s rho with nuisance-free limit distribution. Computational Statistics & Data Analysis, 76, 723-736.

Dürre, A. (2022+). "Finite sample correction for cusum tests", unpublished manuscript

See Also

cor_stat, lrv, pKSdist

Examples

Run this code
### first: generate a time series with a burn-in period of m and a change point 
###        k = n/2
require(mvtnorm)
n <- 500
m <- 100
N <- n + m
k <- m + floor(n * 0.5)
n1 <- N - k

## Spearman's rho:
rho <- c(0.4, -0.9)
  
# serial dependence:
theta1 <- 0.3
theta2 <- 0.2
theta <- cbind(c(theta1, 0), c(0, theta2))
q <- rho * sqrt( (theta1^2 + 1) * (theta2^2 + 1) / (theta1 * theta2 + 1))
# shape matrices of the innovations:
S0 <- cbind(c(1, q[1]), c(q[1], 1))
S1 <- cbind(c(1, q[2]), c(q[2], 1))

e0 <- rmvt(k, S0, 5)
e1 <- rmvt(n1, S1, 5)
e <- rbind(e0, e1)
# generate the data:
x <- matrix(numeric(N * 2), ncol = 2)
x[1, ] <- e[1, ]
invisible(sapply(2:N, function(i) x[i, ] <<- e[i, ] + theta %*% e[i-1, ]))
x <- x[-(1:m), ]

cor_cusum(x, "rho")


## Kendall's tau
S0 <- cbind(c(1, rho[1]), c(rho[1], 1))
S1 <- cbind(c(1, rho[2]), c(rho[2], 1))
e0 <- rmvt(k, S0, 5)
e1 <- rmvt(n1, S1, 5)
e <- rbind(e0, e1)
x <- matrix(numeric(N * 2), ncol = 2)
x[1, ] <- e[1, ]
# AR(1):
invisible(sapply(2:N, function(i) x[i, ] <<- 0.8 * x[i-1, ] + e[i, ]))
x <- x[-(1:m), ]

cor_cusum(x, version = "tau")

Run the code above in your browser using DataLab