Segment a time series using the PELT algorithm
segment_pelt.Rd
Segmenting functions for the PELT algorithm
Arguments
- x
A time series
- model_fn
A
character
orname
coercible into a fun_cpt function. See, for example,fit_meanshift_norm()
. The default isfit_meanvar()
.- ...
arguments passed to
changepoint::cpt.meanvar()
orchangepoint::cpt.mean()
Value
A cpt
object returned by changepoint::cpt.meanvar()
or
changepoint::cpt.mean()
Details
This function wraps either changepoint::cpt.meanvar()
or
changepoint::cpt.mean()
.
Examples
# Segment a time series using PELT
res <- segment_pelt(DataCPSim)
res
#> Class 'cpt' : Changepoint Object
#> ~~ : S4 class containing 12 slots with names
#> cpttype date version data.set method test.stat pen.type pen.value minseglen cpts ncpts.max param.est
#>
#> Created on : Wed Apr 24 21:56:29 2024
#>
#> summary(.) :
#> ----------
#> Created Using changepoint version 2.2.4
#> Changepoint type : Change in mean and variance
#> Method of analysis : PELT
#> Test Statistic : Normal
#> Type of penalty : MBIC with value, 27.99769
#> Minimum Segment Length : 2
#> Maximum no. of cpts : Inf
#> Changepoint Locations : 547 822 972
str(res)
#> Formal class 'cpt' [package "changepoint"] with 12 slots
#> ..@ data.set : Time-Series [1:1096] from 1 to 1096: 35.5 29 35.6 33 29.5 ...
#> ..@ cpttype : chr "mean and variance"
#> ..@ method : chr "PELT"
#> ..@ test.stat: chr "Normal"
#> ..@ pen.type : chr "MBIC"
#> ..@ pen.value: num 28
#> ..@ minseglen: num 2
#> ..@ cpts : int [1:4] 547 822 972 1096
#> ..@ ncpts.max: num Inf
#> ..@ param.est:List of 2
#> .. ..$ mean : num [1:4] 35.3 58.2 96.8 156.5
#> .. ..$ variance: num [1:4] 127 371 921 2406
#> ..@ date : chr "Wed Apr 24 21:56:29 2024"
#> ..@ version : chr "2.2.4"
# Segment as time series while specifying a penalty function
segment_pelt(DataCPSim, penalty = "BIC")
#> Class 'cpt' : Changepoint Object
#> ~~ : S4 class containing 12 slots with names
#> cpttype date version data.set method test.stat pen.type pen.value minseglen cpts ncpts.max param.est
#>
#> Created on : Wed Apr 24 21:56:29 2024
#>
#> summary(.) :
#> ----------
#> Created Using changepoint version 2.2.4
#> Changepoint type : Change in mean and variance
#> Method of analysis : PELT
#> Test Statistic : Normal
#> Type of penalty : BIC with value, 20.99827
#> Minimum Segment Length : 2
#> Maximum no. of cpts : Inf
#> Changepoint Locations : 547 822 972
# Segment a time series while specifying a meanshift normal model
segment_pelt(DataCPSim, model_fn = fit_meanshift_norm, penalty = "BIC")
#> Class 'cpt' : Changepoint Object
#> ~~ : S4 class containing 12 slots with names
#> cpttype date version data.set method test.stat pen.type pen.value minseglen cpts ncpts.max param.est
#>
#> Created on : Wed Apr 24 21:56:29 2024
#>
#> summary(.) :
#> ----------
#> Created Using changepoint version 2.2.4
#> Changepoint type : Change in mean
#> Method of analysis : PELT
#> Test Statistic : Normal
#> Type of penalty : BIC with value, 13.99884
#> Minimum Segment Length : 1
#> Maximum no. of cpts : Inf
#> Number of changepoints: 873