The function `tsmovav` calculates the moving averages of a time series.
tsmovav(
x,
order = 3,
type = c("backward", "center"),
n.ahead = 0,
x.name = NULL,
show.plot = TRUE
)# S3 method for tsmovav
print(x, digits = max(3L, getOption("digits") - 3L), ...)
# S3 method for tsmovav
plot(x, title = NULL, ...)
original series data
list of time in which the series values were observed.
time gap between the series and forecasted values.
name of the time series for which forecasts was requested.
predicted past values and forecasted future values.
list of time in which the predictions/forecasts were estimated.
name of the series containing the predicted/forecasted values.
standard errors of the forecasted values.
lower and upper limits of the prediction interval.
number of forecasting periods.
indication of the series part that should be predicted or forecasted.
logical. Indicates whether series values are log-transformed for model fitting or not.
significance level.
moving average order.
type of moving average.
a univariate time series object or a numeric vector or matrix, or a `tsmovav` object.
moving average order. Default is 3.
type of moving average to be calculated. Available options are "backward" and "center". While backward assigns the moving averages to the next period after the averaging window, which is more useful for forecasting purpose, center assigns the moving averages to the middle period of the averaging window, which is more suitable for time series smoothing. Default is `backward`.
number of forecasting periods. Only useful if "type = backward". Default is 0.
a new name for x. If the parameter is omitted, the current name of the time series will be returned to the user.
logical. If TRUE, the smoothing/forecasting plot will be displayed directly. Default is TRUE.
the number of significant digits.
other printing or plotting parameters.
title of the moving average plot. Default is NULL.
Ka Yui Karl Wu
Centred moving averages are better suited for smoothing a time series than for forecasting. By definition, each moving average is aligned with the midpoint of its averaging window. When the number of periods in the averaging window (i.e., the moving average order) is even, the averages calculated for the two central positions must be combined. Specifically, the mean of these two middle moving averages is assigned to the central period that lies closest to the true midpoint of the series, forming its final centred moving average.
Mathematically, for odd number order \(r\):
$$\tilde{y}_t = \dfrac{y_{t-\frac{r-1}{2}}+\ldots+y_{t+\frac{r+1}{2}}}{r}$$
For even number order \(r\):
$$\tilde{y}_t = \dfrac{0.5y_{t-\frac{r}{2}}+y_{t-\frac{r}{2}+1}+\ldots+y_{t+\frac{r}{2}-1}+0.5y_{t+\frac{r}{2}}}{2r}$$
Backward moving average is a forecasting method that assigns each computed average to the period immediately following the observation window. This approach works the same regardless of whether the moving average order is odd or even.
$$\tilde{y}_t = \dfrac{y_{t-1}+\ldots+x_{y-r}}{r}$$
Hyndman, R. J., & Athanasopoulos, G. (2021). Forecasting: Principles and practice (3rd ed.). OTexts.
https://otexts.com/fpp3/
## Backward Moving Average
tsmovav(airport$Travellers, order = 12, type = "backward", n.ahead = 6, show.plot = TRUE)
## Centered Moving Average
tsmovav(airport$Travellers, order = 12, type = "center")
Run the code above in your browser using DataLab