trimChangepoints | R Documentation |
Wrapper function that will call trimLinearTrends
, trimSeasonality
, or trimLinearTrendsAndSeasonality
to remove proposed changepoints that appear to be false positives due to linear trends and/or seasonality.
trimChangepoints(series, changepoints, thresholdLinear=1.15, thresholdSeasonal=1.15, numHarmonics=2, verbose=T)
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. |
thresholdLinear |
Parameter for determining when to trim changepoints based on linear trends. If the ratio of the linear 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. If this parameter is less than or equal to 1, then trimming for linear trends is not performed. |
thresholdSeasonal |
Parameter for determining when to trim changepoints based on seasonality. 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. If this parameter is less than or equal to 1, then trimming for seasonality is not performed. |
numHarmonics |
Indicates the number of harmonics to be modeled when assessing seasonality (currently restricted to being 1 or 2). |
verbose |
If TRUE, prints out message indicating status. |
In order to trim changepoints for both linear trends and seasonality, thresholdLinear
and thresholdSeaonal
must both be larger than 1. If thresholdLinear > 1
and thresholdSeasonal <= 1
, then the changepoints will only be trimmed for linear trends. If thresholdLinear <= 1
and thresholdSeasonal > 1
, then the changepoints will only be trimmed for seasonality. However, it is generally recommended to trim for both linear trends and seasonality.
Returns a vector of changepoints that are retained. This will be the subset of the input changepoints vector, but excluding those that were trimmed.
Matthew Quinn
getChangepoints
#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 linear trends and seasonality simChangepointsTrimmed <- trimChangepoints(series=simSeries, changepoints=simChangepoints, thresholdLinear=1.2, thresholdSeasonal=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") #Trim changepoints for linear trends only simChangepointsTrimmed <- trimChangepoints(series=simSeries, changepoints=simChangepoints, thresholdLinear=1.2, thresholdSeasonal=1) #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") #Trim changepoints for seasonality only simChangepointsTrimmed <- trimChangepoints(series=simSeries, changepoints=simChangepoints, thresholdLinear=1, thresholdSeasonal=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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.