View source: R/Basic_Segment_Correction.R
basicSegmentCorrection | R Documentation |
Taking in a vector of observations and at least a list of best fitting models, this function will iterate over segments and perform de-trending or de-seasonlizing, followed by shifting and scaling to a reference. This is simply a tool for preliminary analysis after identifying changepoints and should not replace subject-matter knowledge, formal model building, and correction for changepoints.
basicSegmentCorrection(series, changepoints = c(), bestFitsBySegment, segmentsToCorrect = c(), referenceSegment = NA, verbose=T, plotResults=T)
series |
A vector of observations on which changepoint analysis has been run. This vector must not contain any missing values. |
changepoints |
A vector indicating the indices at which there are proposed changepoints. A changepoint is located immediately prior to a shift in the series. If left as an empty vector (the default), the changepoints will be detected from |
bestFitsBySegment |
A list of lists with each sublist corresponding to a segment. The structure of this sublist should match the formatting of the results from |
segmentsToCorrect |
A vector denoting which segments to perform de-trending, de-seasonlizing, shifting, and scaling on. If left an empty vector (default), all segments will be corrected. |
referenceSegment |
The results in each corrected segment will separately be shifted and scaled to match the mean and standard deviation of this segment. If left |
verbose |
If |
plotResults |
If |
This function should only be run after getBestFitBySegment
. It iterates over segments. If the segment's best fitting model is a linear trend, the segment is de-trended (i.e. the segment is replaced by the residuals from the linear model). If the best fitting model is a harmonic regression, the segment is de-seasonalized (i.e. the segment is replaced by the residuals from the harmonic regression). All segments are then shifted and scaled to match the mean and standard deviation of the referenceSegment
. The reference mean will be taken as the mean of referenceSegment
before de-trending or de-seasonlizing while the reference standard deviation will be estimated based on the residual standard error of the best fitting model for referenceSegment
, even if referenceSegment
is not in segmentsToCorrect
. The standard deviation is estimated using residual standard error rather than the sample standard deviation of the original segment to avoid having trends and seasonality influence this estimate.
In practice, one should not use this function to replace subject-matter knowledge, formal model building, and correction for changepoints. This is simply an additional tool that provides a preliminary analysis of segments resulting from identified changepoints.
Returns a vector containing the segment-corrected observations.
Matthew Quinn
##---- Should be DIRECTLY executable !! ---- ##-- ==> Define data, use random, ##-- or do help(data=index) for the standard data sets. ## The function is currently defined as function (x) { }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.