Teradata Package for R Function Reference | 17.00 - ChangePointDetection - Teradata Package for R - Look here for syntax, methods and examples for the functions included in the Teradata Package for R.

Teradata® Package for R Function Reference

Product
Teradata Package for R
Release Number
17.00
Published
July 2021
Language
English (United States)
Last Update
2023-08-08
dita:id
B700-4007
NMT
no
Product Category
Teradata Vantage
ChangePointDetection

Description

The ChangePointDetection function detects change points in a stochastic process or time series, using retrospective change-point detection, implemented with these algorithms:

  1. Search algorithm: binary search

  2. Segmentation algorithm: normal distribution and linear regression

The function takes sorted time series data as input and generates change points or data segments as output.

Usage

  td_changepoint_detection_mle (
      data = NULL,
      data.partition.column = NULL,
      data.order.column = NULL,
      value.column = NULL,
      accumulate = NULL,
      segmentation.method = "normal_distribution",
      search.method = "binary",
      max.change.num = 10,
      penalty = "BIC",
      output.option = "changepoint",
      data.sequence.column = NULL
  )

Arguments

data

Required Argument.
Specifies the tbl_teradata defining the input time series data.

data.partition.column

Required Argument.
Specifies Partition By columns for "data".
Values to this argument can be provided as a vector, if multiple columns are used for partition.
Types: character OR vector of Strings (character)

data.order.column

Required Argument.
Specifies Order By columns for "data".
Values to this argument can be provided as a vector, if multiple columns are used for ordering.
Types: character OR vector of Strings (character)

value.column

Required Argument.
Specifies the name of the input tbl_teradata column that contains the time series data.
Types: character

accumulate

Required Argument.
Specifies the names of the input tbl_teradata columns to copy to the output tbl_teradata.
Note: To identify change points in the output tbl_teradata, specify the columns that appear in "data.partition.column" and "data.order.column".
Types: character OR vector of Strings (character)

segmentation.method

Optional Argument.
Specifies one of these segmentation methods:

  1. normal_distribution: In each segment, the data is in a normal distribution.

  2. linear_regression: In each segment, the data is in linear regression.


Default Value: "normal_distribution"
Permitted Values: normal_distribution, linear_regression
Types: character

search.method

Optional Argument.
Specifies the search method, binary segmentation. This is the default and only possible value.
Default Value: "binary"
Permitted Values: binary
Types: character

max.change.num

Optional Argument.
Specifies the maximum number of change points to detect.
Default Value: 10
Types: integer

penalty

Optional Argument.
Possible values are:

  1. BIC - For change point existence, the condition is: ln(L1)-ln(L0) > (p1-p0)*ln(n)/2.
    For normal distribution and linear regression, the condition is: (p1-p0)*ln(n)/2 = ln(n).

  2. AIC - the condition for the existence of a change point is: ln(L1)-ln(L0) > p1-p0.
    For normal distribution and linear regression, the condition is: p1-p0 = 2.

  3. For threshold(numeric value), the specified value is compared to: ln(L1)-ln(L0). L1 and L2 are the maximum likelihood estimation of hypotheses H1 and H0. p is the number of additional parameters introduced by adding a change point. p is used in the information criterion BIC or AIC. p1 and p0 represent this parameter in hypotheses H1 and H0 separately.


Default Value: "BIC"
Types: character

output.option

Optional Argument.
Specifies the output tbl_teradata columns.
Default Value: "changepoint"
Permitted Values: changepoint, segment, verbose
Types: character

data.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "data". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.
Types: character OR vector of Strings (character)

Value

Function returns an object of class "td_changepoint_detection_mle" which is a named list containing object of class "tbl_teradata".
Named list member can be referenced directly with the "$" operator using the name: result.

Examples

  
    # Get the current context/connection
    con <- td_get_context()$connection
    
    # Load example data.
    loadExampleData("changepointdetection_example", "finance_data2" , "cpt")

    # Create object(s) of class "tbl_teradata".
    # The input signal is like a clock signal whose values can represent a
    # cyclic recurrence of an event (for example, electric power consumption at
    # certain periods or sequence, pulserate, and so on).
    cpt <- tbl(con,"cpt")

    # Input contains two time series of finance data.
    finance_data2 <- tbl(con,"finance_data2")

    # Example 1: Two Series, Default Options.
    td_changepoint_detection_out1 <- td_changepoint_detection_mle(data=finance_data2,
                                                           data.partition.column='sid',
                                                           data.order.column='id',
                                                           value.column='expenditure',
                                                           accumulate=c('sid','id','expenditure'))

    # Example 2 -  One Series, Default Options.
    td_changepoint_detection_out2 <- td_changepoint_detection_mle(data=cpt,
                                                                  data.partition.column="sid",
                                                                  data.order.column="id",
                                                                  value.column = "val",
                                                                  accumulate = c("sid", "id")
                                                                  )

    # Example 3 - One Series, VERBOSE Output.
    td_changepoint_detection_out3 <- td_changepoint_detection_mle(data=cpt,
                                                                  value.column = "val",
                                                                  data.partition.column="sid",
                                                                  data.order.column="id",
                                                                  accumulate = c("sid","id"),
                                                                  output.option = "verbose"
                                                                  )

    # Example 4 - One Series, Penalty 10.
    td_changepoint_detection_out4 <- td_changepoint_detection_mle(data=cpt,
                                                                  data.partition.column="sid",
                                                                  data.order.column="id",
                                                                  value.column = "val",
                                                                  accumulate = c("sid","id"),
                                                                  penalty = "10"
                                                                  )

    # Example 5 -  One Series, SEGMENT Output, Penalty 10.
    td_changepoint_detection_out5 <- td_changepoint_detection_mle(data=cpt,
                                                                  data.partition.column="sid",
                                                                  data.order.column="id",
                                                                  value.column = "val",
                                                                  accumulate = c("sid","id"),
                                                                  penalty = "10",
                                                                  output.option = "segment"
                                                                  )

    # Example 6 - One Series, Penalty 20, Linear Regression.
    td_changepoint_detection_out6 <- td_changepoint_detection_mle(data=cpt,
                                                        data.partition.column="sid",
                                                        data.order.column="id",
                                                        value.column = "val",
                                                        accumulate = c("sid","id"),
                                                        segmentation.method = "linear_regression",
                                                        penalty = "20"
                                                        )