if (FALSE) {
## Example of montoring for the period m+1, ..., n
m <- 100 # size of the learning sample
n <- 150 # monitoring horizon
## The learning sample
set.seed(123)
x.learn <- matrix(rnorm(m))
## New observations with a large change in mean
## to simulate monitoring for the period m+1, ..., n
k <- 125 ## the true change-point
x <- matrix(c(rnorm(k-m), rnorm(n-k, mean = 2)))
## Step 1: Simulation of B trajectories of the detector functions under the null
B <- 1e4
## Under the assumption of serial independence
## (no need to specify the learning sample)
traj.sim <- simClosedEndCpDist(m = m, n = n, B = B, method = "sim")
## Without the assumption of serial independence
## (the learning sample is compulsory; the larger it is, the better;
## the monitoring horizon n should not be too large)
traj.mult <- simClosedEndCpDist(x.learn = x.learn, n = n, B = B, method = "mult")
## Step 2: Compute threshold functions with p steps
p <- 2
tf.sim <- threshClosedEndCpDist(traj.sim, p = p)
# p can be taken large if B is very large
tf.mult <- threshClosedEndCpDist(traj.mult, p = p) # p should not be taken too
# large unless both m and B
# are very large
## Step 3: Compute the detectors for the monitoring period m+1, ... , n
det <- detClosedEndCpDist(x.learn = x.learn, x = x)
## Step 4: Monitoring
## Simulate the monitoring with the first threshold function
monClosedEndCpDist(det, tf.sim)
## Simulate the monitoring with the second threshold function
monClosedEndCpDist(det, tf.mult)
## Simulate the monitoring with the first threshold function
## and another detector function
monClosedEndCpDist(det, tf.sim, statistic = "mmk")
## Alternative steps 3 and 4:
## Compute the detectors for the monitoring period m+1, ... , m+20 only
det <- detClosedEndCpDist(x.learn = x.learn, x = x[1:20,,drop = FALSE])
## Simulate the monitoring with the first threshold function
monClosedEndCpDist(det, tf.sim)
## Simulate the monitoring with the second threshold function
monClosedEndCpDist(det, tf.mult)
}
Run the code above in your browser using DataLab