basicSegmentCorrection: Performs a basic segment correction.

View source: R/Basic_Segment_Correction.R

basicSegmentCorrectionR Documentation

Performs a basic segment correction.

Description

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.

Usage

basicSegmentCorrection(series, changepoints = c(), bestFitsBySegment, segmentsToCorrect = c(), referenceSegment = NA, verbose=T, plotResults=T)

Arguments

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 based on the end of each segment.

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 getBestFitBySegment.

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 NA (the default), the largest segment in series is chosen. If set to 0, then the observations will be standardized to have mean 0 and standard deviation 1. This process is performed after any de-trending and de-seasonalizing. 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. This shifting and scaling is done only to segments in segmentsToCorrect. Other segments are left unaltered

verbose

If TRUE, prints out messages indicating progress.

plotResults

If TRUE, produces a plot of the time series after correction.

Details

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.

Value

Returns a vector containing the segment-corrected observations.

Author(s)

Matthew Quinn

Examples

##---- 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)
{
  }

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