BinSegModel: Compute Changepoint Model

Description Usage Arguments Value Details See Also Examples

View source: R/UserInterface.R

Description

This is the main function of the BinSeg package. It performs changepoint analysis on the provided data using the selected algorithm and distribution. Computes the optimal changepoints and estimates the parameters in each segment. Note that it is possible to view segmentation models from 1 up to the selected number of changepoints, by using the methods provided by the BinSeg Class.

Usage

1
BinSegModel(data, algorithm, distribution, numCpts = 1, minSegLen = 1)

Arguments

data

A numeric vector containing the input data. Must have at least length 1.

algorithm

A string with the algorithm to be used. Currently only "BS" (Binary Segmentation) is implemented.

distribution

A string with the distribution to be used. Use BinSegInfo to check the available distributions and their description.

numCpts

Integer determining the number of changepoints to be computed. Must be at least one. For the norm_mean distribution, as the variance is assumed to be constant, there can be up to N number of changepoints. However, for every other distribution, there are at most N/2.

minSegLen

Integer determining the minimum segment length. For the norm_mean distribution, the minimum segment length is 1. However, for all the other ones it is 2, since each segment must have two data points to calculate variance.

Value

A BinSeg object containing the models_summary data table, as well as extra information such as the distribution, algorithm, number of changepoints, and parameters.

Details

This is the only function that must be called to perform a new changepoint analysis with the BinSeg package. Internally, it first makes several validations to the input parameters. After this, it calls the binseg function, which connects with C++ code using Rcpp. Later on it makes some modifications to the returned matrix (which will be used as models_summary data table) and creates a new BinSeg object which is returned. Note that in order to use any of the methods from the BinSeg class you must use this function instead of directly calling the binseg function.

See Also

BinSegInfo to know the available algorithms and distributions, binseg to check out the Rcpp function. BinSeg to check the return class sructure and available methods.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# First, get some data to analyse. In this case, it follows a normal distribution with change in mean.
data  <-  c(rnorm(10, 0, 10), rnorm(10, 100, 10), rnorm(10, 50, 10))

# Call BinSegInfo in order to know the available distributions and algorithms
BinSegInfo()

# Given the type of change, choose norm_mean, with the BS algorithm and 2 changepoints). Get a BinSeg object in return
models <- BinSegModel(data=data, algorithm="BS", distribution="mean_norm", numCpts=2)

# In order o get parameter estimations only for the model with 2 changepoints, call the coef function
coef(models, 2L)

# To plot the whole model, use plot
plot(models)

#To get a diagnostic plot, use plotDiagnostic
plotDiagnostic(models)

diego-urgell/BinSeg documentation built on Dec. 19, 2021, 11:11 p.m.