Skip to content

Commit

Permalink
tutorial for week 8
Browse files Browse the repository at this point in the history
  • Loading branch information
dicook committed Apr 20, 2024
1 parent 4414109 commit faeb6c9
Show file tree
Hide file tree
Showing 21 changed files with 248,251 additions and 49 deletions.
248,068 changes: 248,068 additions & 0 deletions docs/data/domestic_trips_2023-10-08.csv

Large diffs are not rendered by default.

100 changes: 100 additions & 0 deletions docs/data/tourism.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
library(tsibble)
library(tidyverse)
library(lubridate)
library(ggbeeswarm)

# Data downloaded from Monash A-Z Databases
# "Tourism Research Australia online for students"
# Row: Quarter/SA2
# Column: Stopover reason was Holiday, Visiting friends and relatives, Business, Other reason
# Sum Overnight trips ('000)
# Australia: Domestic Overnight Trips ('000) ----
domestic_trips <- read_csv(
"data/domestic_trips_2023-10-08.csv",
skip = 9,
col_names = c("Quarter", "Region", "Holiday", "Visiting", "Business", "Other", "Total"),
n_max = 248056
) %>% select(-X8)

# fill NA in "Quarter" using the last obs
fill_na <- domestic_trips %>%
fill(Quarter, .direction = "down") %>%
filter(Quarter != "Total")

# gather Stopover purpose of visit
long_data <- fill_na %>%
pivot_longer(cols=Holiday:Total,
names_to="Purpose",
values_to="Trips")

# manipulate Quarter
qtr_data <- long_data %>%
mutate(
Quarter = paste(gsub(" quarter", "", Quarter), "01"),
Quarter = yearquarter(myd(Quarter))
)

# convert to tsibble
tourism <- qtr_data %>%
as_tsibble(key = c(Region, Purpose), index = Quarter)
usethis::use_data(tourism, overwrite = TRUE, compress = "xz")

saveRDS(tourism, file="data/tourism.rds")

# Standarise the counts
tourism_max <- tourism |>
as_tibble() |>
group_by(Region) |>
summarise(mx = max(Trips))

tourism_std <- left_join(tourism, tourism_max)
tourism_std <- tourism_std |>
as_tibble() |>
mutate(Trips_std = ifelse(mx > 0,
Trips/mx,
0))
tourism_std |> summarise(m = max(Trips_std))
tourism_std |> group_by(Region) |> summarise(m = max(Trips_std))
tourism_std <- tourism_std |>
as_tsibble(key = c(Region, Purpose), index = Quarter)

library(feasts)
tourism_features1 <- tourism_std |>
features(Trips_std, list(mean = mean,
sd = sd))
tourism_features2 <- tourism_std |>
features(Trips_std, feat_stl)
tourism_features3 <- tourism_std |>
features(Trips_std, feat_acf) |>
select(-acf1, -acf10)

tourism_features <- bind_cols(tourism_features1,
tourism_features2[,3:11],
tourism_features3[,3:7]) |>
filter(Purpose != "Total") |>
mutate(Purpose = factor(Purpose)) |>
mutate_if(is.numeric, function(x) ifelse(is.nan(x), 0, x))

tourism_features |>
count(Purpose)

library(randomForest)
tourism_rf <- randomForest(Purpose~.,
data=tourism_features[,-1])
tourism_rf
tourism_rf$importance

ggplot(tourism_features, aes(x=mean, y=sd, colour=Purpose)) +
geom_point(alpha=0.5)

tourism_features |>
pivot_longer(mean:`season_acf1`,
names_to="var",
values_to="value") |>
ggplot(aes(x=Purpose, y=value, colour=Purpose)) +
geom_quasirandom() +
facet_wrap(~var, ncol=6, scales="free") +
xlab("") + ylab("") +
coord_flip() +
theme(legend.position="none")

Binary file added docs/data/tourism.rda
Binary file not shown.
Binary file added docs/data/tourism.rds
Binary file not shown.
23 changes: 15 additions & 8 deletions docs/search.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</url>
<url>
<loc>https://iml.numbat.space/week8/index.html</loc>
<lastmod>2024-02-05T21:28:13.682Z</lastmod>
<lastmod>2024-04-20T06:01:33.376Z</lastmod>
</url>
<url>
<loc>https://iml.numbat.space/week7/slides.html</loc>
Expand Down Expand Up @@ -38,7 +38,7 @@
</url>
<url>
<loc>https://iml.numbat.space/week4/index.html</loc>
<lastmod>2024-03-15T04:09:22.102Z</lastmod>
<lastmod>2024-04-19T00:32:10.657Z</lastmod>
</url>
<url>
<loc>https://iml.numbat.space/week3/slides.html</loc>
Expand Down
2 changes: 1 addition & 1 deletion docs/week1/slides.html

Large diffs are not rendered by default.

Binary file modified docs/week2/images/slides.rmarkdown/data-in-model-space1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/week2/slides.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/week3/tutorialsol.html

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions docs/week4/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ <h2 id="toc-title">On this page</h2>
<li><a href="#lecture-slides" id="toc-lecture-slides" class="nav-link" data-scroll-target="#lecture-slides">Lecture slides</a></li>
<li><a href="#tutorial-instructions" id="toc-tutorial-instructions" class="nav-link" data-scroll-target="#tutorial-instructions">Tutorial instructions</a></li>
<li><a href="#assignments" id="toc-assignments" class="nav-link" data-scroll-target="#assignments">Assignments</a></li>
<li><a href="#assignments-1" id="toc-assignments-1" class="nav-link" data-scroll-target="#assignments-1">Assignments</a></li>
</ul>
</nav>
</div>
Expand Down Expand Up @@ -253,9 +252,6 @@ <h2 class="anchored" data-anchor-id="tutorial-instructions">Tutorial instruction
</section>
<section id="assignments" class="level2">
<h2 class="anchored" data-anchor-id="assignments">Assignments</h2>
</section>
<section id="assignments-1" class="level2">
<h2 class="anchored" data-anchor-id="assignments-1">Assignments</h2>
<ul>
<li><a href="../assignments/assign01.zip">Assignment 1</a> is due on Friday 22 March.</li>
<li><a href="../assignments/assign02.zip">Assignment 2</a> is due on Friday 12 April.</li>
Expand Down
Loading

0 comments on commit faeb6c9

Please sign in to comment.