Learn R Programming

tidychangepoint (version 1.0.0)

as.model: Convert, retrieve, or verify a model object

Description

Convert, retrieve, or verify a model object

Usage

as.model(object, ...)

# S3 method for default as.model(object, ...)

# S3 method for tidycpt as.model(object, ...)

is_model(x, ...)

Value

  • as.model() returns a mod_cpt model object

  • is_model() a logical vector of length 1

Arguments

object

A tidycpt object, typically returned by segment()

...

currently ignored

x

An object, typically returned by fit_*()

Details

tidycpt objects have a model component. The functions documented here are convenience utility functions for working with the model components. as.model() is especially useful in pipelines to avoid having to use the $ or [ notation for subsetting.

When applied to a tidycpt object, as.model() simply returns the model component of that object. However, when applied to a segmenter object, as.model() attempts to converts that object into a mod_cpt model object.

is_model() checks to see if a model object implements all of the S3 methods necessary to be considered a model.

See Also

Other tidycpt-generics: as.segmenter(), changepoints(), diagnose(), fitness(), model_name()

Examples

Run this code
# Segment a time series using PELT
x <- segment(CET, method = "pelt")

# Retrieve the model component
x |> 
  as.model()

# Explicitly convert the segmenter to a model
x |>
  as.segmenter() |>
  as.model()

# Is that model valid? 
x |>
  as.model() |>
  is_model()
  

# Fit a model directly, without using [segment()]
x <- fit_nhpp(CET, tau = 330)
is_model(x)

Run the code above in your browser using DataLab