Workshop Activities: Week 5
Week 5 Mini-Studio
This page follows the same sequence as week5-code.R. It is designed as a stable seminar companion: read the code, run the matching block in R or RStudio, then answer the short prompts here in words. That keeps the focus on the class code, which is the style you are most likely to meet in the exam.
- Open week5-code.R beside this page.
- Work through the sections in order.
- Run the matching block in RStudio.
- Use the prompts here to practise explanation and model choice, not just syntax.
A. Build the holidays series
This opening block creates the tourism series used in the first activity.
holidays <- tourism |>
filter(State %in% c("Victoria", "Queensland")) |>
filter(Purpose == "Holiday") |>
as_tibble() |>
summarise(Trips = sum(Trips), .by = c("State", "Quarter")) |>
as_tsibble(index = Quarter, key = State)
holidays |> autoplot()- Filters the
tourismdata to holiday trips in Victoria and Queensland. - Aggregates trips by state and quarter.
- Converts to a tsibble for time series analysis.
- Plots the series to visualize the data.
- Compare the overall level and seasonal patterns between Victoria and Queensland.
- Look for any trends or changes in variability over time.
B. Fit ETS models to the holidays series
This block fits ETS models to both series and explores the results.
fit <- holidays |>
model(ets = ETS(Trips))
fit
fit |> glance()
fit |> tidy()fit |>
filter(State == "Queensland") |>
report()
fit |>
filter(State == "Victoria") |>
report()- Fits automatic ETS models to each state’s series.
- Uses
glance()for model summaries,tidy()for parameters, andreport()for detailed model info.
- Note the different models selected for each state.
- Compare the parameter estimates and model fits.
- Pay attention to any warnings or automatic selections.
C. Plot components and generate forecasts
This section visualizes model components and produces forecasts.
fit |> components() |> autoplot()
fit |> forecast(h = 8) |> autoplot(holidays)- Plots the estimated components (trend, seasonal, error) of the fitted models.
- Generates 8-step-ahead forecasts and plots them with the original data.
- Examine how the components differ between states.
- Assess the forecast patterns and uncertainty intervals.
D. Analyze Algeria exports data
This activity shifts to exports data for Algeria.
algeria_exports <- global_economy |>
filter(Country == "Algeria") |>
select(Year, Exports)
algeria_exports |> autoplot()- Extracts exports data for Algeria from
global_economy. - Plots the series to assess its characteristics.
- Determine if the series resembles white noise or has structure.
- Consider what ETS model might be appropriate.
E. Fit ETS models to Algeria exports
Fit both additive and multiplicative error models.
fit_algeria <- algeria_exports |>
model(
additive = ETS(Exports ~ error("A")),
multiplicative = ETS(Exports ~ error("M"))
)
fit_algeria |> glance()
fit_algeria |> report()- Fits ETS models with additive and multiplicative errors.
- Compares model summaries and reports.
- See which model is selected automatically.
- Compare the fitted parameters and performance.
F. Check components and residuals for Algeria
Analyze the model internals and residuals.
fit_algeria |> components() |> autoplot()
fit_algeria |> gg_tsresiduals()- Plots components and residual diagnostics for both models.
- Look for patterns in residuals that indicate model adequacy.
- Compare component plots between additive and multiplicative models.
G. Forecast Algeria exports
Generate and plot forecasts.
fit_algeria |> forecast(h = 5) |> autoplot(algeria_exports)- Produces 5-year-ahead forecasts and visualizes them.
- Assess the forecast behavior and differences between models.
H. Analyze Australia population data
This final activity uses population data.
aus_pop <- global_economy |>
filter(Country == "Australia") |>
mutate(Population = Population / 1e6) |>
select(Year, Population)
aus_pop |> autoplot()- Extracts and scales Australia’s population data to millions.
- Plots the series.
- Identify the trend pattern in the population growth.
I. Fit trend models to Australia population
Fit linear and damped trend models.
fit_aus <- aus_pop |>
model(
linear = ETS(Population ~ trend("A")),
damped = ETS(Population ~ trend("Ad"))
)
fit_aus |> report()- Fits ETS models with linear and damped trends.
- Reports the estimated parameters.
- Compare the trend parameters and model fits.
J. Generate long-term forecasts
Forecast 30 years ahead.
fit_aus |> forecast(h = 30) |> autoplot(aus_pop)- Generates 30-year forecasts and plots them.
- Observe the differences in long-term projections between linear and damped trends.
K. Evaluate forecast accuracy
Fit models up to 2010 and forecast the rest.
train <- aus_pop |> filter(Year <= 2010)
fit_train <- train |>
model(
linear = ETS(Population ~ trend("A")),
damped = ETS(Population ~ trend("Ad"))
)
fit_train |> forecast(h = 11) |> autoplot(aus_pop) +
labs(title = "Forecasts from models fitted to 2010 data")- Fits models to pre-2011 data and forecasts to present.
- Plots forecasts against actual data for accuracy assessment.
- Evaluate how well each model predicts the actual population growth.