How can I run an anova test on the time-series models.
Example code (from https://otexts.com/fpp3/holt-winters.html)
library(tsibble)
library(tidyverse)
library(fable)
library(forecast)
aus_holidays <- tourism %>%
filter(Purpose == "Holiday") %>%
summarise(Trips = sum(Trips))
fit <- aus_holidays %>%
model(
additive = ETS(Trips ~ error("A") + trend("A") + season("A")),
multiplicative = ETS(Trips ~ error("M") + trend("A") + season("M"))
)
model_1 <- fit %>% select(additive)
model_2 <- fit %>% select(multiplicative)
In above example, I want to run anova
test on model_1
and model_2
. I tried anova(model_1, model_2)
, but it needs lm
objects.
I ran oneway anova
test on fitted values, as shown below.
total_rows <- nrow(augment(model_1))
temp_df <- tibble(
.fitted = c(augment(model_1)$.fitted,
augment(model_2)$.fitted),
model_name = c(rep("model_1", total_rows),
rep("model_2", total_rows))
)
oneway.test(.fitted ~ model_name, data = temp_df)
#OR
anova(lm(.fitted ~ model_name, data = temp_df))