1. Produce forecasts for the following series using whichever of NAIVE(y), SNAIVE(y) or RW(y ~ drift()) is more appropriate in each case:

Australian Population (global_economy)

aus_population = global_economy %>% filter(Country=="Australia")
autoplot(aus_population, Population)+
  labs(title = "Australian Population")

fit = aus_population %>% model(Drift = NAIVE(Population~drift()))

#generate forecast
aus_pop_forcast = fit %>%  
  forecast(h=10)

#plot forecast
aus_pop_forcast %>% 
  autoplot(aus_population)

### Bricks (aus_production)

aus_bricks = aus_production %>% filter(!is.na(Bricks))
autoplot(aus_bricks , Bricks)

brick_model = aus_bricks  %>% model(snaive = SNAIVE(Bricks ~ lag("year")))

brick_forcast = brick_model %>% forecast(h=10)

#plot
brick_forcast %>% autoplot(aus_bricks )

### NSW Lambs (aus_livestock)

NSW_Lambs = aus_livestock %>% filter(Animal == "Lambs", State=="New South Wales")
autoplot(NSW_Lambs)
## Plot variable not specified, automatically selected `.vars = Count`

NSW_Lambs_model = NSW_Lambs %>% model(snaive = SNAIVE(Count ~ lag("year")))

nsw_forcast = NSW_Lambs_model %>% forecast(h=10)
nsw_forcast %>% autoplot(NSW_Lambs)

### Household wealth (hh_budget).

hh_wealth = hh_budget %>% select(Wealth) %>% filter(Country=='Australia')  %>% filter(!is.na(Wealth))

hh_wealth_fit = hh_wealth %>%
  model(`naive` = NAIVE(Wealth))

hh_wealth_fit %>% forecast(h = 10) %>% autoplot(hh_wealth)

Australian takeaway food turnover (aus_retail).

aus_takeaway = aus_retail %>% filter(Industry=='Takeaway food services',State=='Australian Capital Territory') 

aus_takeaway_fit = aus_takeaway %>%
  model(`snaive` = SNAIVE(Turnover))
aus_takeaway_fit %>% forecast(h = 36) %>% autoplot(aus_takeaway)

2. Use the Facebook stock price (data set gafa_stock) to do the following:

Produce a time plot of the series.

Stock = gafa_stock %>% filter(Symbol == "FB") %>%
  select(Close) %>% mutate(day=row_number())
autoplot(Stock)  
## Plot variable not specified, automatically selected `.vars = Close`

### Produce forecasts using the drift method and plot them.

fb_ts <- gafa_stock |> filter(Symbol=='FB') |>
    mutate(trading_day = row_number()) |>
    update_tsibble(index = trading_day, regular = TRUE)

fb_jan_2018 <- fb_ts |>
  filter(yearmonth(Date) >= yearmonth("2017 Dec"))

fb_pre_2018 <- fb_ts |> filter(Symbol=='FB' & year(Date)<= 2017) 
    
fb_pre_2018 |>
    model(RW(Close ~ drift())) |> 
    forecast(h=30) |> 
    autoplot(fb_pre_2018)

### Show that the forecasts are identical to extending the line drawn between the first and last observations.

fb_pre_2018 |>
    model(RW(Close ~ drift())) |> 
    forecast(h=30) |> 
    autoplot(fb_pre_2018) +
    #autolayer()
    geom_segment(aes(x = 0, y = pull(fb_pre_2018 |> filter(trading_day==1),Close), xend = 1007, yend = pull(fb_pre_2018 |> filter(trading_day==1007),Close),linetype=2 ),,colour='blue',linetype=2)

Try using some of the other benchmark functions to forecast the same data set. Which do you think is best? Why?

3.Apply a seasonal naïve method to the quarterly Australian beer production data from 1992. Check if the residuals look like white noise, and plot the forecasts. The following code will help.

recent_production <- aus_production |>
  filter(year(Quarter) >= 1992)
fit <- recent_production |> model(SNAIVE(Beer))
fit |> gg_tsresiduals()

What do you conclude?

4 Repeat the previous exercise using the Australian Exports series from global_economy and the Bricks series from aus_production. Use whichever of NAIVE() or SNAIVE() is more appropriate in each case.

7.

For your retail time series (from Exercise 7 in Section 2.10):

Create a training dataset consisting of observations before 2011 using

myseries_train <- myseries |> filter(year(Month) < 2011) Check that your data have been split appropriately by producing the following plot.

autoplot(myseries, Turnover) + autolayer(myseries_train, Turnover, colour = “red”) Fit a seasonal naïve model using SNAIVE() applied to your training data (myseries_train).

fit <- myseries_train |> model(SNAIVE()) Check the residuals.

fit |> gg_tsresiduals() Do the residuals appear to be uncorrelated and normally distributed?

Produce forecasts for the test data

fc <- fit |> forecast(new_data = anti_join(myseries, myseries_train)) fc |> autoplot(myseries) Compare the accuracy of your forecasts against the actual values.

fit |> accuracy() fc |> accuracy(myseries) How sensitive are the accuracy measures to the amount of training data used?