trimSeasonality: Trim proposed changepoints arising from seasonality

View source: R/Trimming.R

trimSeasonalityR Documentation

Trim proposed changepoints arising from seasonality

Description

Removes proposed changepoints that appear to be false positives due to seasonality or cyclical patterns.

Usage

trimSeasonality(series, changepoints, threshold=1.15, numHarmonics=2)

Arguments

series

A vector of observations on which to run changepoint analysis.

changepoints

A vector indicating the indices at which there are proposed changepoints. A changepoint is located immediately prior to a shift in the series.

threshold

Parameter for determining when to trim changepoints. If the ratio of the harmonic regression RMSE to the optimal piecewise RMSE is below this threshold, then the changepoint is subject to removal. That is, a larger threshold makes it easier to remove proposed changepoints. Reasonable values may be between 1 and 1.5, but will depend on the context. It is worthwhile for the investigator to try multiple values for the threshold.

numHarmonics

Indicates the number of harmonics to be modeled (currently restricted to being 1 or 2).

Details

Iterates over proposed changepoints. For a given changepoint, the two neighboring segments on either side of the changepoint are considered. If the ratio of the harmonic regression RMSE (across both segments together) to the optimal piecewise harmonic regression RMSE (each segment separately) is below this threshold, then the changepoint is subject to removal. That is, a larger threshold makes it easier to remove proposed changepoints.

After iterating over all changepoints, the changepoint with the smallest ratio (i.e. closest to 1) is removed and the process repeats until no changepoints are subject to removal.

Value

Returns a vector of changepoints that are retained. This will be the subset of the input changepoints vector, but excluding those that were trimmed.

Author(s)

Matthew Quinn

Examples

#Obtain changepoints for the simulated data. 10000 simulation trials may take some time.
simChangepoints <- getChangepoints(series=simSeries, alpha=0.01, numTrials=10000, serial=F, numCores = 2)

#Trim changepoints for seasonality
simChangepointsTrimmed <- trimSeasonality(series=simSeries, changepoints=simChangepoints, threshold=1.2)

#Plot
plot(y=simSeries, x=1:length(simSeries), type="l", ylab="Simulated Value", xlab="Index", main="Simulated Data with Trimmed Changepoints")
abline(v=simChangepointsTrimmed, col="red")

matthewquinn1/changepointSelect documentation built on July 25, 2022, 7:12 p.m.