Learn R Programming

changepoint (version 0.3)

PELT.reg.norm: Multiple Changes in Regression using PELT pruned method - Normal Errors

Description

Calculates the optimal positioning and number of changepoints for regression data with zero-mean Normal errors using PELT pruned method.

Usage

PELT.reg.norm(data, pen=0, nprune=FALSE)

Arguments

data
A matrix or 3-d array containing the data within which you wish to find a changepoint. If data is a 3-d array, each first dimension is considered a separate dataset. Within each dataset the first column is considered the response and the further columns
pen
Numeric value of the linear penalty function. This value is used in the decision for each individual changepoint so that in total the penalty is k*pen where k is the optimal number of changepoints detected.
nprune
Logical. If nprune=FALSE, the locations of the changepoints are returned. If nprune=TRUE then the number of points kept at each stage of pruning is returned instead.

Value

  • If nprune=FALSE then a vector of the changepoint locations is returned:
  • cptVector containing the changepoint locations for the penalty supplied. This always ends with n.
  • If nprune=TRUE then a vector of the number of points kept during pruning at each iteration is returned:
  • npruneVector containing the number of points kept at each stage of pruning.

Details

This function is used to find a multiple changes in regression for data that is assumed to have zero-mean normally distributed errors. The value returned is the result of testing H0:existing number of changepoints against H1: one extra changepoint using the log of the likelihood ratio statistic coupled with the penalty supplied. The PELT method keeps track of the optimal number and location of changepoints as it passes through the data.

References

Change in regression: Chen, J. and Gupta, A. K. (2000) Parametric statistical change point analysis, Birkhauser

PELT Algorithm: Killick, R. and Fearnhead, P. and Eckley, I.A. (2011) An exact linear time search algorithm for multiple changepoint detection, Submitted

See Also

PELT.mean.norm,PELT.var.norm,PELT.meanvar.norm,cpt.reg,binseg.reg.norm,multiple.reg.norm,single.reg.norm,segneigh.reg.norm

Examples

Run this code
# Example of multiple changes in regression at 100,250 in simulated data with zero-mean normal errors
set.seed(1)
x=1:400
y=c(0.01*x[1:100],3.5-0.02*x[101:250],-15+0.05*x[251:400])
ynoise=y+rnorm(400,0,0.2)
yx=cbind(ynoise,1,x)
PELT.reg.norm(yx,pen=4*log(400)) # returns optimal number as 2 and the locations as c(100,249)
PELT.reg.norm(yx,pen=4*log(400),nprune=TRUE) # returns vector showing how many points are kept during pruing at each iteration of the method

# Example no change in regression
set.seed(10)
x=1:400
y=0.01*x
ynoise=y+rnorm(400,0,0.2)
yx=cbind(ynoise,1,x)
PELT.reg.norm(yx,pen=4*log(400)) # returns 400 to show no changepoint were found
PELT.reg.norm(yx,pen=4*log(200),nprune=TRUE) # notice how the number of points kept it steadily increasing compared to the previous example where it almost resets when a true change has been found

Run the code above in your browser using DataLab