knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

backCUSUM

The goal of backCUSUM is to provide functionality to apply the methods developed in the paper "Backward CUSUM for Testing and Monitoring Structural Change" by Sven Otto and Jörg Breitung. The repository also provides code to replicate all simulation results in this paper.

Installation

You can install the package using the following command:

library('devtools')
install_github("ottosven/backCUSUM")

Example

This is a basic example to reproduce Figure 2 of the paper:

library(backCUSUM)
RNGkind("L'Ecuyer-CMRG")
set.seed(42)
T <- 100
breakpoint <- floor(3*T/4)
beta1 = 0
beta2 = 1
u <- rnorm(T,0,1)
y <- c(rep(beta1,breakpoint), rep(beta2,T-breakpoint)) + u
Qt <- Q.detector(y~1)
BQt <- BQ.detector(y~1)
wt <- get.recresid(y~1)

This is the plot:

par(mfrow=c(1,2))
plot(Qt, lwd = 2, type='l', col='blue', xlab = "", ylab = expression(), ylim=c(-2, 3.2), main='Forward CUSUM')
mtext(text = "time",side = 1, line = 2)
lines((0.948*(1+2*(1:T)/T)), lty=2, col='red', lwd=1)     # critical boundaries for alpha = 0.0001
lines(wt, col='grey', lwd = 1)
lines( x=c(1,100), y=c(0, 0), col='black', lwd=1, lty = 2)
plot(BQt, lwd = 2, type='l', col='blue', xlab = "", ylab = expression(), ylim=c(-2, 3.2), main='Backward CUSUM')
mtext(text = "time",side = 1, line = 2)
lines((0.948*(1+2*(T:1)/T)), lty=2, col='red', lwd=1)
lines(wt, col='grey', lwd = 1)
lines( x=c(1,100), y=c(0, 0), col='black', lwd=1, lty = 2)
par(fig = c(0, 1, 0, 1), oma = c(0, 0, 0, 0), mar = c(0, 0, 0, 0), new = TRUE)
plot(0, 0, type = "n", bty = "n", xaxt = "n", yaxt = "n")
legend("bottom", c("detector statistic", "linear boundary (5%)", "recursive residuals"), horiz = TRUE, bty = "n", cex=1 , col = c('blue', 'red', 'grey'), lty=c(1, 2, 1), lwd = c(2, 1, 1) )


ottosven/backCUSUM documentation built on April 12, 2022, 10:59 p.m.