WBS.univar {changepoints}R Documentation

Wild binary segmentation for univariate mean change points detection.

Description

Perform wild binary segmentation for univariate mean change points detection.

Usage

WBS.univar(y, s, e, Alpha, Beta, delta = 2, level = 0)

Arguments

y

A numeric vector of observations.

s

A integer scalar of starting index.

e

A integer scalar of ending index.

Alpha

A integer vector of starting indices of random intervals.

Beta

A integer vector of ending indices of random intervals.

delta

A positive integer scalar of minimum spacing.

level

Should be fixed as 0.

Value

An object of class "BS", which is a list with the following structure:

S

A vector of estimated change point locations (sorted in strictly increasing order).

Dval

A vector of values of CUSUM statistic.

Level

A vector representing the levels at which each change point is detected.

Parent

A matrix with the starting indices on the first row and the ending indices on the second row.

Author(s)

Haotian Xu

References

Wang, Yu and Rinaldo (2020) <doi:10.1214/20-EJS1710>.

See Also

thresholdBS for obtaining change points estimation, tuneBSunivar for a tuning version.

Examples

set.seed(0)
cpt_true = c(20, 50, 170)
y = rnorm(300) + c(rep(0,20),rep(2,30),rep(0,120),rep(2,130))
intervals = WBS.intervals(M = 300, lower = 1, upper = length(y))
temp = WBS.univar(y, 1, length(y), intervals$Alpha, intervals$Beta, delta = 5)
plot.ts(y)
points(x = tail(temp$S[order(temp$Dval)],4),
       y = y[tail(temp$S[order(temp$Dval)],4)], col = "red")
WBS_result = thresholdBS(temp, tau = 4)
print(WBS_result$BS_tree, "value")
plot(WBS_result$BS_tree)
print(WBS_result$BS_tree_trimmed, "value")
plot(WBS_result$BS_tree_trimmed)
cpt_hat = sort(WBS_result$cpt_hat[,1]) # the threshold tau is specified to be 4
Hausdorff.dist(cpt_hat, cpt_true)
cpt_LR = local.refine.univar(cpt_hat, y)
Hausdorff.dist(cpt_LR, cpt_true)

[Package changepoints version 1.1.0 Index]