# Moving average with smoothing over three values
a <- 1 / 3
gain_ma <- create.gain(rep(a, 3))
lambda <- seq(0, 0.5, 0.001)
GF <- gain_ma(lambda)
plot(lambda, GF, type = "l")
# First differences filter
b <- c(1, -1)
gain_diff <- create.gain(b)
lambda <- seq(0, 0.5, 0.001)
GF2 <- gain_diff(lambda)
plot(lambda, GF2, type = "l")
# \donttest{
# For a fully data-driven local linear trend +
# trigonometric polynomial seasonality
# (Note: we get various filters for different observation time points)
xt <- EXPENDITURES
est <- deseats(log(xt), set_options(order_poly = 3))
ws <- est@weights[, , "Combined"]
l <- (length(ws[, 1]) - 1) / 2
lambda <- seq(0, 0.5, 0.001)
mat <- matrix(0, ncol = length(lambda), nrow = l + 1)
colF <- colorRampPalette(c("deepskyblue4", "deepskyblue"))
cols <- colF(l)
for (j in 1:(l + 1)) {
gainF <- create.gain(ws[j, ], zero.at = j)
mat[j, ] <- gainF(lambda)
}
matplot(lambda, t(mat), type = paste0(rep("l", l + 1), collapse = ""),
lty = rep(1, l + 1), col = cols)
title(
main = paste0(
"Gain functions for the applied data-driven locally weighted ",
"regression\napproach at boundary points and the first interior ",
"point"
)
)
# Same example as before but not for the trend but for the detrending filters
# (Note: we get various filters for different observation time points)
ll <- l * 2 + 1
mat2 <- mat
for (j in 1:(l + 1)) {
zero.vec <- rep(0, ll)
zero.vec[[j]] <- 1
gainF <- create.gain(zero.vec - ws[j, ], zero.at = j)
mat2[j, ] <- gainF(lambda)
}
matplot(lambda, t(mat2), type = paste0(rep("l", l + 1), collapse = ""),
lty = rep(1, l + 1), col = cols)
title(
main = paste0(
"Gain functions for the applied data-driven detrending filter\n",
"at boundary points and the first interior ",
"point"
)
)
# }
Run the code above in your browser using DataLab