Skip to contents

Recursively splits the series at the position giving the largest reduction in total segment cost, stopping after K splits or as soon as no split improves the cost by more than penalty. This is the greedy approximation of Killick et al. (2012), Sec. 2.1; morie_pelt solves the same objective exactly and is the natural cross-check.

Usage

morie_binseg(x, K, cost = "mean", penalty = 0, min_seglen = 1L)

Arguments

x

Numeric series.

K

Maximum number of changepoints.

cost

Segment cost, "mean" (default) or "meanvar"; see morie_pelt.

penalty

Cost improvement a split must beat, default 0.

min_seglen

Minimum segment length.

Value

A list with changepoints (sorted, 0-based), order (in the order they were found), improvements, n_changepoints, segment_means, estimate, n, method.

References

Scott, A. J. and Knott, M. (1974). A cluster analysis method for grouping means in the analysis of variance. Biometrics, 30(3), 507-512.

Examples

morie_binseg(x = c(1, 2, 3, 4, 5, 6, 7, 8), K = 5L)
#> $changepoints
#> [1] 1 2 3 4 6
#> 
#> $order
#> [1] 4 2 6 1 3
#> 
#> $improvements
#> [1] 32.0  4.0  4.0  0.5  0.5
#> 
#> $n_changepoints
#> [1] 5
#> 
#> $segment_means
#> [1] 1.0 2.0 3.0 4.0 5.5 7.5
#> 
#> $estimate
#> [1] 1 2 3 4 6
#> 
#> $n
#> [1] 8
#> 
#> $method
#> [1] "Binary segmentation (Scott-Knott 1974; Killick et al. 2012 Sec. 2.1)"
#>