Workshop Activities: Week 2
Week 2 Mini-Studio
This page follows the same sequence as week2-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 week2-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 olympic_running data
This section introduces the olympic_running tsibble.
olympic_running
olympic_running |> distinct(Length)
olympic_running$Year |> range()
NoteWhat this code is doing
- Displays the olympic_running data.
- Shows unique lengths and year range.
NoteWhat to notice
- The data covers different running lengths and years.
- Note the range of years.
B. Plot 100m times
Plot the 100m running times.
olympic_running |>
filter(Length=="100") |>
autoplot(Time) +
geom_point()
NoteWhat this code is doing
- Filters for 100m events.
- Plots time vs year with points.
NoteWhat to notice
- Look for trends in running times.
- Note any missing observations.
C. Faceted plot of all lengths
Create a faceted plot for all lengths.
olympic_running |>
ggplot(aes(x=Year, y = Time, colour = Sex)) +
geom_line() +
geom_point(size = 1) +
facet_wrap(~ Length, scales = "free_y", nrow = 2) +
theme_minimal() +
scale_color_brewer(palette = "Dark2") +
theme(legend.position = "bottom", legend.title = element_blank()) +
labs(title = "Olympic running times",
y="Seconds")
NoteWhat this code is doing
- Plots times for all lengths, colored by sex.
- Uses facets for each length.
NoteWhat to notice
- Compare trends across lengths and sexes.
- See how times have changed over years.
D. Summarise A10 costs
Summarise total A10 costs from PBS.
a10 <- PBS |>
filter(ATC2 == "A10") |>
select(Month, Concession, Type, Cost) |>
summarise(TotalC = sum(Cost)) |>
mutate(Cost = TotalC / 1e6)
a10
NoteWhat this code is doing
- Filters PBS for A10 drugs.
- Sums costs across concession and type.
- Scales to millions.
NoteWhat to notice
- The resulting tsibble has monthly data.
- Cost is now in millions.
E. Plot A10 costs
Plot the A10 cost time series.
a10 |>
autoplot(Cost) +
labs(
title = "Australian antidiabetic drug sales",
y = "Cost $ (millions)"
)
NoteWhat this code is doing
- Plots the cost over time.
- Adds title and y-label.
NoteWhat to notice
- Identify patterns: trend, seasonality, etc.
- This is a time series plot example.
F. Explore Snowy Mountains tourism
Filter and summarise Snowy Mountains data.
snowy <- tourism |>
filter(Region == "Snowy Mountains") |>
summarise(Trips = sum(Trips))
NoteWhat this code is doing
- Filters tourism for Snowy Mountains.
- Sums trips across purposes.
NoteWhat to notice
- This creates a quarterly series for the region.
G. Plot Snowy Mountains data
Use autoplot, gg_season, gg_subseries, ACF.
snowy |> autoplot()
snowy |> gg_season()
snowy |> gg_subseries()
snowy |> ACF(Trips) |> autoplot()
NoteWhat this code is doing
- Various plots: time plot, seasonal plot, subseries, ACF.
NoteWhat to notice
- What patterns do you learn from each plot?
- Seasonal effects, trends, autocorrelation.
H. ACF matching quiz
The activities include matching time plots to ACF plots.
NoteExam-style prompt
Match the time plots (1-4) to the ACF plots (A-D). Explain your reasoning based on the patterns you observe.
```
- You can compute and plot the daily changes in the Amazon stock price in 2018 using the code below. Do the daily changes look like white noise?