Description Usage Arguments Value See Also Examples
Locates the change-points of time series based on a piecewise linear
segmentation algorithm. Given a window size (n.fit
) and an angle tolerance
(angle.tolerance
), the segmentation algorithm starts by finding the
slope of the first n.fit
points of the series via least squares
regression. The window is slid over one point to the right, the points within
the new window are regressed, and the new slope is compared to the old slope.
If the change in slope exceeds the specified angle.tolerance
, a change-point
is recorded as the rightmost point of the previous iteration's window. The
routine then picks up again starting at the point just to the right of the
change-point. If the change in slope does not exceed the specified
angle.tolerance
, then the old slope is updated (in a running average sense),
and the algorithm continues as usual. The window is slid along the
until its rightmost point reaches the edge of the time series.
1 2 |
x |
the independent variable of the time series. |
y |
the dependent variable of the time series. |
... |
additional arguments sent unaltered to the |
add |
a logical value. If |
angle.tolerance |
the maximum angle in degrees that the running average of the slopes in the current set of points can change relative to the slope of the data calculated in the most current (rightmost) window before a change-point is recorded. Default: 5. |
aspect |
a logical value. If |
n.fit |
an integer denoting the window size, not to exceed the number of samples in the time series. Default: 5. |
plot |
a logical value. If |
a vector containing the result.
lm
.
1 2 3 4 5 6 7 8 9 10 11 12 13 | ## obtain some data with approximately
## piecewise-linear trends
x <- seq(0,2*pi,length=100)
y <- sin(x)
## perform linear segmentation with aspect ratio
## dilation using a 5 degree tolerance and 5
## point windows
z <- linearSegmentation(x, y, n.fit=5, angle.tolerance=5, aspect=TRUE)
## plot the data and the estimated change-points
plot(x, y)
abline(v=x[z], lty=2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.