movingAve | R Documentation |
Implements the Savitzky-Golay (Savitzky and Golay, 1964) filter on a regular series of data to compute a moving average.
movingAve(x, span = 3, order = 0, pos = "center")
x |
the data to be averaged or differenced. Missing values are permitted but result in missing values in the output. |
span |
the length of the data to be averaged. |
order |
the polynomial order for averaging. Must be less than
|
pos |
how to position the output data relative to the value returned;
"center" means that the value represents the average of the
most central value relative to the |
A vector of the same length as x
containing the averages.
For odd values of span
and pos
equal to "center,"
order
equal to 0 or 1 gives the same result.
In general, there is no
reason to use polynomial orders greater than 2, and pos
should always
be set to "center" for polynomial orders greater than 1 to avoid strange
behavior due to end effects.
The weights for the averages are computed based on linear model theory (Savitzky and Golay, 1964; Wood and Hockens, 1970). Wood and Hockens (1970) also discuss some artifacts resulting from smoothing.
Savitzky, A., and Golay, M.J.E., 1964, Smoothing and differentiation of data
by simplified least squares procedures: Analytical Chemistry, v. 36, no. 8, p.
1627–1639.
Wood, L.C., and Hockens, S.N., 1970, Least squares smoothing operators: Geophysics, v. 35, no. 6, p. 1005–1019.
filter
, diff
, movingDiff
## Construct a simple valley movingData <- abs(seq(-5, 5)) movingAve(movingData, span=5) movingAve(movingData, span=5, order=2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.