Learn R Programming

changepoint (version 0.3)

PELT.meanvar.gamma: Multiple Changes in Mean and Variance using PELT pruned method - Gamma Data (i.e. change in scale parameter)

Description

Calculates the optimal positioning and number of changepoints for Gamma data using PELT pruned method.

Usage

PELT.meanvar.gamma(data, shape=1, pen=0, nprune=FALSE)

Arguments

data
A vector containing the data within which you wish to find changepoints.
shape
Numerical value of the true shape parameter for the data. Either single value or vector of length nrow(data). If data is a matrix and shape is a single value, the same shape parameter is used for each row.
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 mean and variance for data that is assumed to be Gamma distributed. 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 Gamma shape parameter: 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.meanvar.norm,cpt.meanvar,binseg.meanvar.gamma,multiple.meanvar.gamma,single.meanvar.gamma,segneigh.meanvar.gamma

Examples

Run this code
# Example of multiple changes in scale parameter at 50,100,150 in simulated gamma data
set.seed(1)
x=c(rgamma(50,shape=1,rate=1),rgamma(50,shape=1,rate=3),rgamma(50,shape=1,rate=1),rgamma(50,shape=1,rate=10))
PELT.meanvar.gamma(x,pen=2*log(200)) # returns c(47,102,150,200)
PELT.meanvar.gamma(x,pen=2*log(200),nprune=TRUE) # returns vector showing how many points are kept during pruing at each iteration of the method

# Example no change in scale parameter
set.seed(1)
x=rgamma(200,shape=1,rate=1)
PELT.meanvar.gamma(x,pen=2*log(200)) # returns 200 to show no change in mean or variance has been found
PELT.meanvar.gamma(x,pen=2*log(200),nprune=TRUE) # notice how the number of points kept it steadily increasing compare to the previous example where it almost resets when a true change has been found

Run the code above in your browser using DataLab