
Last chance! 50% off unlimited learning
Sale ends in
Generic function to segment data into separate change points according to specified algorithm
segment(data, likelihood, max_segments = ncol(data),
allow_parallel = TRUE, algorithm = "exact", ...)
matrix for which to find the change points
a function receives the segment matrix as argument and returns a likelihood estimation. This function is used to calculate the change points that maximize the total likelihood. Depending on the algorithm being used, this function is likely to be executed many times, in which case it's also likely to be the bottleneck of the function execution, so it's advised that this function should have fast implementation.
an integer that defines the maximum amount of segments to split the data into.
allows parallel execution to take place using the
registered cluster. Assumes a cluster is registered with the foreach
package. Defaults to TRUE.
can be of type exact
, hierarchical
or hybrid
, Default: exact
other parameters to be passed to the underlying function
a list of type segmentr
, which has the two attributes:
changepoints
: a vector with the first index of each identified change point
segments
: a list of vectors, in which each vector corresponds to the indices
that identifies a segment.
This function can be used as a generic function to call any of the algorithms implemented by the package. Depending on the type of data the user wants to segment, one algorithm might be more adequate than the others.
exactalg()
for the exact algorithm, hieralg()
for the
hierarchical algorithm implementation, hybridalg()
for the hybrid
algorithm implementation.
# NOT RUN {
make_segment <- function(n, p) matrix(rbinom(100 * n, 1, p), nrow = 100)
data <- cbind(make_segment(5, 0.1), make_segment(10, 0.9), make_segment(2, 0.1))
mean_lik <- function(X) abs(mean(X) - 0.5) * ncol(X)^2
segment(data, likelihood = mean_lik, algorithm = "hieralg")
# }
Run the code above in your browser using DataLab