Workshop Activities: Week 1
Week 1 Mini-Studio
This page follows the same sequence as week1-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.
TipHow to use this page
- Open week1-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. Explore the tourism dataset
This opening block introduces the tourism data and basic tsibble operations.
library(fpp3)
tourism
NoteWhat this code is doing
- Loads the fpp3 package.
- Displays the tourism tsibble structure.
NoteWhat to notice
- The key variables: State, Region, Purpose.
- The time index is Quarter.
- The data spans 1998 Q1 to 2016 Q4.
B. Filter and summarise tourism data
This section shows how to filter for Victoria and summarise trips.
tourism |>
filter(State == "Victoria") |>
summarise(Total_Trips = sum(Trips))
NoteWhat this code is doing
- Filters the data to Victoria only.
- Sums the trips across all regions and purposes.
NoteWhat to notice
- The result is a single time series for Victoria’s total trips.
- The index remains Quarter.
C. Explore PBS data
Shifting to the PBS dataset for pharmaceutical costs.
PBS
NoteWhat this code is doing
- Displays the PBS tsibble.
NoteWhat to notice
- Disaggregated by ATC2, Concession, Type.
- Time index is Month.
- Many series (84 × 2 × 2 = 336).
D. Filter PBS data
Filter for A10 drug type.
PBS |>
filter(ATC2 == "A10")
NoteWhat this code is doing
- Selects rows where ATC2 is “A10”.
NoteWhat to notice
- Reduces to 4 series (2 Concession × 2 Type).
E. Select columns
Select specific columns from the filtered data.
PBS |>
filter(ATC2 == "A10") |>
select(Month, Concession, Type, Cost)
NoteWhat this code is doing
- Keeps only the specified columns.
- Index is always included.
NoteWhat to notice
- Focuses on the cost variable.
F. Summarise over keys
Summarise total cost for A10.
PBS |>
filter(ATC2 == "A10") |>
select(Month, Concession, Type, Cost) |>
summarise(total_cost = sum(Cost))
NoteWhat this code is doing
- Sums cost over the key variables.
- Results in a single time series.
NoteWhat to notice
- Aggregation reduces multiple series to one.
G. Mutate to create new variables
Scale the cost to millions.
PBS |>
filter(ATC2 == "A10") |>
select(Month, Concession, Type, Cost) |>
summarise(total_cost = sum(Cost)) |>
mutate(total_cost = total_cost / 1e6)
NoteWhat this code is doing
- Divides total_cost by 1e6 to get millions.
NoteWhat to notice
- Mutate adds or modifies columns.
- Useful for scaling or transformations.
H. Assign to variable
Create and assign the a10 object.
a10 <- PBS |>
filter(ATC2 == "A10") |>
select(Month, Concession, Type, Cost) |>
summarise(total_cost = sum(Cost)) |>
mutate(total_cost = total_cost / 1e6)
NoteWhat this code is doing
- Pipes the operations and assigns to a10.
NoteWhat to notice
- Assignment creates reusable objects.
- The pipe (%>%) chains operations.