0

I am trying to add my forecasts together for each region and each quarter. I've tried to summarize on a specific variable, but that didn't work. I've also tried to groupby region too, but I believe for this to work, you need to aggregate somehow. I'm trying to add the two forecasts together while also being able to see the change in accuracy using the accuracy(). So far, I've not really found a good way to do this.

tourism %>% 
  filter(Quarter >= yearquarter("2008 Q1")) %>%
  filter(Purpose == "Holiday" & State == "New South Wales") %>%
  filter(Region %in% c("North Coast NSW", "South Coast", "Sydney")) %>%
  mutate(Demand = case_when(
    Region == "Sydney" ~ 0.03*Trips*5,
    Region == "South Coast"~0.04*Trips*2,
    Region == "North Coast NSW" ~ 0.04 *Trips*2
  )) -> D

DTR <- D %>% filter(Quarter <= yearquarter("2016 Q4"))
DTE <- D %>% filter(Quarter >= yearquarter("2017 Q1"))


m <- DTR %>% 
  model(m.auto = ETS(Demand),
        m.AAM = ETS(Demand ~ error("A") + trend("A") + season("M")),
        m.AAdM = ETS(Demand ~ error("A") + trend("Ad") + season("M")))


m  %>%
  glance()

m %>% 
  select(m.auto) %>%
  glance()
m.auto <- m %>%
  select(m.auto)
  

f <- m %>% 
  select(m.auto) %>%
  forecast(h = 4)

rbind(m.auto %>% accuracy(), 
      f %>% accuracy(data = D))

Here is the table of the forecast:

structure(list(Region = c("North Coast NSW", "North Coast NSW", 
"North Coast NSW", "North Coast NSW", "South Coast", "South Coast", 
"South Coast", "South Coast", "Sydney", "Sydney", "Sydney", "Sydney"
), State = c("New South Wales", "New South Wales", "New South Wales", 
"New South Wales", "New South Wales", "New South Wales", "New South Wales", 
"New South Wales", "New South Wales", "New South Wales", "New South Wales", 
"New South Wales"), Purpose = c("Holiday", "Holiday", "Holiday", 
"Holiday", "Holiday", "Holiday", "Holiday", "Holiday", "Holiday", 
"Holiday", "Holiday", "Holiday"), .model = c("m.auto", "m.auto", 
"m.auto", "m.auto", "m.auto", "m.auto", "m.auto", "m.auto", "m.auto", 
"m.auto", "m.auto", "m.auto"), Quarter = structure(c(17167, 17257, 
17348, 17440, 17167, 17257, 17348, 17440, 17167, 17257, 17348, 
17440), fiscal_start = 1, class = c("yearquarter", "vctrs_vctr"
)), Demand = structure(list(structure(list(mu = 64.5267676142378, 
    sigma = 7.45649497452699), class = c("dist_normal", "dist_default"
)), structure(list(mu = 45.7869538723355, sigma = 5.39507245782213), class = c("dist_normal", 
"dist_default")), structure(list(mu = 42.4573776516376, sigma = 5.09748859911909), class = c("dist_normal", 
"dist_default")), structure(list(mu = 53.9721361044215, sigma = 6.59826306707935), class = c("dist_normal", 
"dist_default")), structure(list(mu = 61.7503906560609, sigma = 6.75515872707897), class = c("dist_normal", 
"dist_default")), structure(list(mu = 35.6173573447291, sigma = 3.97232150452371), class = c("dist_normal", 
"dist_default")), structure(list(mu = 27.1314815258956, sigma = 3.08272534449931), class = c("dist_normal", 
"dist_default")), structure(list(mu = 38.1701802125742, sigma = 4.41547997477935), class = c("dist_normal", 
"dist_default")), structure(list(mu = 95.1714054395916, sigma = 8.18541561715263), class = c("dist_normal", 
"dist_default")), structure(list(mu = 85.2330580025708, sigma = 8.18541582507749), class = c("dist_normal", 
"dist_default")), structure(list(mu = 79.7805187916752, sigma = 8.18541603300235), class = c("dist_normal", 
"dist_default")), structure(list(mu = 77.9011650250759, sigma = 8.18541646640782), class = c("dist_normal", 
"dist_default"))), vars = "Demand", class = c("distribution", 
"vctrs_vctr", "list")), .mean = c(64.5267676142378, 45.7869538723355, 
42.4573776516376, 53.9721361044215, 61.7503906560609, 35.6173573447291, 
27.1314815258956, 38.1701802125742, 95.1714054395916, 85.2330580025708, 
79.7805187916752, 77.9011650250759)), row.names = c(NA, -12L), key = structure(list(
    Region = c("North Coast NSW", "South Coast", "Sydney"), State = c("New South Wales", 
    "New South Wales", "New South Wales"), Purpose = c("Holiday", 
    "Holiday", "Holiday"), .model = c("m.auto", "m.auto", "m.auto"
    ), .rows = structure(list(1:4, 5:8, 9:12), ptype = integer(0), class = c("vctrs_list_of", 
    "vctrs_vctr", "list"))), row.names = c(NA, 3L), class = c("tbl_df", 
"tbl", "data.frame"), .drop = TRUE), index = structure("Quarter", ordered = TRUE), index2 = "Quarter", interval = structure(list(
    year = 0, quarter = 1, month = 0, week = 0, day = 0, hour = 0, 
    minute = 0, second = 0, millisecond = 0, microsecond = 0, 
    nanosecond = 0, unit = 0), .regular = TRUE, class = c("interval", 
"vctrs_rcrd", "vctrs_vctr")), response = "Demand", dist = "Demand", model_cn = ".model", class = c("fbl_ts", 
"tbl_ts", "tbl_df", "tbl", "data.frame"))

Please let me know if you need anymore information.

QMan5
  • 713
  • 1
  • 4
  • 20

0 Answers0