1

如何对时间序列模型进行方差分析。

示例代码(来自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)

在上面的示例中,我想在and上运行anova测试。我试过了,但它需要对象。model_1model_2anova(model_1, model_2)lm

oneway anova对拟合值进行了测试,如下所示。

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))
4

0 回答 0