classify_changepoint: Changepoint analysis

View source: R/classify_changepoint.R

classify_changepointR Documentation

Changepoint analysis

Description

This function implements a changepoint analysis to find changes in variance, mean or both. By default it is set to look for changes in the pressure data to identify migration periods, however it can be altered to any form of changepoint analysis in the package changepoint.

Usage

classify_changepoint(
  dta,
  cpt.method = "meanvar",
  method = "PELT",
  penalty = "Manual",
  pen.value = "100*log(n)",
  ...
)

Arguments

dta

data to be classified (vector)

cpt.method

method for classifying data, currently support "mean","variance", "meanvar", use ?changepoint::cpt.mean ?changepoint::cpt.var or ?changepoint::cpt.meanvar for additional parameters

method

changepoint method used in package changepoint. see changepoint::cpt.mean, changepoint::cpt.var and changepoint::cpt.meanvar for details

penalty

See changepoint package for details. Choice of "None", "SIC", "BIC", "MBIC", AIC", "Hannan-Quinn", "Asymptotic", "Manual" and "CROPS" penalties. If Manual is specified, the manual penalty is contained in the pen.value parameter. If Asymptotic is specified, the theoretical type I error is contained in the pen.value parameter. If CROPS is specified, the penalty range is contained in the pen.value parameter; note this is a vector of length 2 which contains the minimum and maximum penalty value. Note CROPS can only be used if the method is "PELT". The predefined penalties listed DO count the changepoint as a parameter, postfix a 0 e.g."SIC0" to NOT count the changepoint as a parameter.

pen.value

See changepoint package for details. Tthe theoretical type I error e.g.0.05 when using the Asymptotic penalty. A vector of length 2 (min,max) if using the CROPS penalty. The value of the penalty when using the Manual penalty option - this can be a numeric value or text giving the formula to use. Available variables are, n=length of original data, null=null likelihood, alt=alternative likelihood, tau=proposed changepoint, diffparam=difference in number of alternatve and null parameters

...

any additional inputs for changepoint::cpt.mean, changepoint::cpt.var or changepoint::cpt.meanvar

Value

Changepoints in the data.

References

Killick, R. and Eckley, I., 2014. changepoint: An R package for changepoint analysis. Journal of statistical software, 58(3), pp.1-19.

Examples

## Not run: 
# Import and crop PAM data
data("swift")
start = as.POSIXct("2016-09-01","%Y-%m-%d", tz="UTC")
end = as.POSIXct("2017-04-15","%Y-%m-%d", tz="UTC")
PAM_data =  create_crop(swift, start, end)

# data(bee_eater)
# start = as.POSIXct("2015-08-01","%Y-%m-%d", tz="UTC")
# end = as.POSIXct("2016-06-01","%Y-%m-%d", tz="UTC")
# PAM_data = create_crop(bee_eater, start, end)

changepoints  = classify_changepoint(PAM_data$pressure$obs)

# plot the timeseries with the changepoint
par(mfrow=c(2,1))
plot(PAM_data$pressure$obs, type="l")
abline(v=changepoints$changepoints, col="red",lwd=2)

# plot using changepoint package output
changepoint::plot(changepoints$output, cpt.width=3)

## End(Not run)

KiranLDA/PAMLr documentation built on March 6, 2023, 1:40 p.m.