Convert, retrieve, or verify a segmenter object
as.segmenter.Rd
Convert, retrieve, or verify a segmenter object
Usage
as.segmenter(object, ...)
as.seg_cpt(object, ...)
# S3 method for class 'seg_basket'
as.seg_cpt(object, ...)
# S3 method for class 'seg_cpt'
as.seg_cpt(object, ...)
# S3 method for class 'tidycpt'
as.segmenter(object, ...)
# S3 method for class 'ga'
as.seg_cpt(object, ...)
# S3 method for class 'cpt'
as.seg_cpt(object, ...)
# S3 method for class 'wbs'
as.seg_cpt(object, ...)
is_segmenter(object, ...)
Arguments
- object
A tidycpt or
segmenter
object- ...
Arguments passed to methods
Value
as.segmenter()
returns thesegmenter
object of atidycpt
object. Note that this could be of any class, depending on the class returned by the segmenting function.
as.seg_cpt()
returns a seg_cpt object
is_segmenter()
alogical
vector of length 1
Details
tidycpt objects have a segmenter
component (that is typically
created by a class to segment()
).
The functions documented here are convenience utility functions
for working with the segmenter
components.
as.segmenter()
is especially useful in pipelines to avoid having to use
the $
or [
notation for subsetting.
as.segmenter()
simply returns the segmenter of a tidycpt
object.
as.seg_cpt()
takes a wild-caught segmenter
object of arbitrary class
and converts it into a seg_cpt object.
is_segmenter()
checks to see if a segmenter object implements all of the
S3 methods necessary to be considered a segmenter.
See also
Other tidycpt-generics:
as.model()
,
changepoints()
,
diagnose()
,
fitness()
,
model_name()
Other segmenter-functions:
fitness()
,
model_args()
,
seg_params()
Examples
# Segment a time series using PELT
x <- segment(CET, method = "pelt")
# Return the segmenter component
x |>
as.segmenter()
#> 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, 23.56658
#> Minimum Segment Length : 2
#> Maximum no. of cpts : Inf
#> Changepoint Locations : 55 57 309 311 330
# Note the class of this object could be anything
x |>
as.segmenter() |>
class()
#> [1] "cpt"
#> attr(,"package")
#> [1] "changepoint"
# Convert the segmenter into the standardized seg_cpt class
x |>
as.segmenter() |>
as.seg_cpt()
#> List of 8
#> $ data : Time-Series [1:362] from 1 to 362: 8.87 9.1 9.78 9.52 8.63 9.34 8.29 9.86 8.52 9.51 ...
#> $ pkg : chr "changepoint"
#> $ algorithm : chr "PELT"
#> $ changepoints: int [1:5] 55 57 309 311 330
#> $ fitness : Named num -Inf
#> ..- attr(*, "names")= chr "MBIC"
#> $ seg_params :List of 1
#> ..$ :List of 3
#> .. ..$ test_stat : chr "Normal"
#> .. ..$ num_cpts_max : num Inf
#> .. ..$ min_seg_length: num 2
#> $ model_name : chr "meanvar"
#> $ penalty : chr "MBIC"
#> - attr(*, "class")= chr "seg_cpt"
# Is the segmenter valid?
x |>
as.segmenter() |>
is_segmenter()
#> [1] TRUE