Replies: 1 comment 1 reply
-
|
The simplest approach is to use the library(forecast)
library(fpp3)
google_stock <- gafa_stock |>
filter(Symbol == "GOOG", year(Date) >= 2015) |>
mutate(day = row_number()) |>
update_tsibble(index = day, regular = TRUE)
google_2015 <- google_stock |> filter(year(Date) == 2015)
google_tscv_m1 <- tsCV(google_2015$Close, h = 8, function(x, h) {
auto.arima(x) |>
forecast(h = h)
})
google_tscv_m2 <- tsCV(google_2015$Close, h = 8, function(x, h) {
Arima(x, order = c(1, 1, 0), lambda = 0, biasadj = TRUE) |>
forecast(h = h)
})
google_tscv_comb <- tsCV(google_2015$Close, h = 8, function(x, h) {
fc1 <- Arima(x, order = c(1, 1, 0), lambda = 0, biasadj = TRUE) |>
forecast(h = h)
fc2 <- auto.arima(x) |> forecast(h = h)
fc2$mean <- 0.5 * (fc1$mean + fc2$mean)
return(fc2)
})
common_times <- apply(
!is.na(google_tscv_m1) &
!is.na(google_tscv_m2) &
!is.na(google_tscv_comb),
1,
all
)
mse <- rbind(
m1 = colMeans(google_tscv_m1[common_times, ]^2),
m2 = colMeans(google_tscv_m2[common_times, ]^2),
comb = colMeans(google_tscv_comb[common_times, ]^2)
)
mse
#> h=1 h=2 h=3 h=4 h=5 h=6 h=7 h=8
#> m1 138.8834 300.1304 444.5767 575.8839 691.6277 800.2433 918.4026 1022.969
#> m2 133.9775 297.6269 448.3832 581.2425 698.6947 796.2140 909.7168 1005.752
#> comb 135.7658 297.3055 443.5407 573.8943 688.6614 790.0591 904.4725 1003.522Created on 2026-06-02 with reprex v2.1.1 This is not the most efficient approach, because the forecasts from each model are computed twice, but it is probably the simplest approach. To do it more efficiently, you would need to implement your own variation of |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Using the fable package we ca easily apply the cross validation on the forecast combination. For example
I am trying to translate the above code with the forecast package, using also the theory in these links
accuracy
combinations
So my attempt is this
But then I am not sure how to proceed.
Beta Was this translation helpful? Give feedback.
All reactions