\[ \hat{T_{t}} = \frac{y_{t-1} + y_{t} + y_{t+1}}{2} \] The above is a MA(2) model, or a 2-MA model.
global_economy
dataset:Exports
into each observation in ma_5
:for (i in (k + 1):(length(aus_economy$Exports) - k)) {
aus_economy$ma_5[i] <- mean(aus_economy$Exports[(i - k):(i + k)])
}
aus_economy |>
select(Exports, ma_5) |>
head()
# A tsibble: 6 x 3 [1Y]
Exports ma_5 Year
<dbl> <dbl> <dbl>
1 13.0 NA 1960
2 12.4 NA 1961
3 13.9 13.5 1962
4 13.0 13.5 1963
5 14.9 13.6 1964
6 13.2 13.4 1965
slide_dbl()
from the slider
package.
mean
) to “sliding” time windows.We can also do this automatically using slide_dbl()
from the slider
package.
mean
) to “sliding” time windows.us_retail_employment_ma <- us_retail_employment |>
mutate(
`12-MA` = slider::slide_dbl(Employed, mean,
.before = 5, .after = 6, .complete = TRUE),
`2x12-MA` = slider::slide_dbl(`12-MA`, mean,
.before = 1, .after = 0, .complete = TRUE)
)
us_retail_employment_ma |>
autoplot(Employed, colour = "gray") +
geom_line(aes(y = `2x12-MA`), colour = "#D55E00") +
labs(y = "Persons (thousands)",
title = "Total employment in US retail")
classical_decomposition()
:classical_decomposition()
:trend(window = x)
trend(window = x)
trend(window = x)
season(window = x)
trend(window = x)
season(window = x)
trend(window = x)
season(window = x)
season(window = 'periodic')
forces the component to be identical across years.trend(window = x)
season(window = x)
season(window = 'periodic')
forces the component to be identical across years.robust = TRUE