trimLinearTrendsAndSeasonality | R Documentation |
Removes proposed changepoints that appear to be false positives due to linear trends and/or seasonality.
trimLinearTrendsAndSeasonality(series, changepoints, thresholdLinear=1.15, thresholdSeasonal=1.15, numHarmonics=2)
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. It is recommended to use the same threshold as for thresholdSeasonal. |
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. It is recommended to use the same value as used for thresholdLinear. |
numHarmonics |
Indicates the number of harmonics to be modeled when assessing seasonality (currently restricted to being 1 or 2). |
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 linear regression RMSE (across both segments together) to the optimal piecewise regression RMSE (each segment separately) is below thresholdLinear, then the changepoint is subject to removal. If the ratio of the harmonic regression RMSE (across both segments together) to the optimal piecewise regression RMSE (each segment separately) is below thresholdSeasonal, 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.
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
#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 <- trimLinearTrendsAndSeasonality(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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.