Skip to content

Commit

Permalink
Ready for Week 1
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeAthana committed Feb 22, 2025
1 parent a941355 commit 7bfd272
Show file tree
Hide file tree
Showing 24 changed files with 13,376 additions and 60 deletions.
640 changes: 640 additions & 0 deletions 404.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _freeze/index/execute-results/html.json

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions _freeze/week1/activities/execute-results/html.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"result": {
"engine": "knitr",
"markdown": "---\ntitle: \"Activities: Week 1\"\neditor: source\nengine: knitr\nfilters:\n - live\n - quiz-teachr\nojs-engine: true\nwebr:\n packages:\n - qlcheckr\n - fpp3\n - urca\n autoload-packages: false\n repos:\n - https://repo.r-wasm.org/\n - https://learnr-academy.github.io/qlcheckr\n---\n\n::: {.cell}\n\n:::\n\n\n\n\n# Time series data and patterns\n\n## Exercise 1\n\nThe `pedestrian` dataset contains hourly pedestrian counts from 2015-01-01 to 2016-12-31 at 4 sensors in the city of Melbourne.\n\nThe data is shown below:\n\n\n\n::: {.cell}\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 66,037 × 5\n Sensor Date_Time Date Time Count\n <chr> <dttm> <date> <int> <int>\n 1 Birrarung Marr 2015-01-01 00:00:00 2015-01-01 0 1630\n 2 Birrarung Marr 2015-01-01 01:00:00 2015-01-01 1 826\n 3 Birrarung Marr 2015-01-01 02:00:00 2015-01-01 2 567\n 4 Birrarung Marr 2015-01-01 03:00:00 2015-01-01 3 264\n 5 Birrarung Marr 2015-01-01 04:00:00 2015-01-01 4 139\n 6 Birrarung Marr 2015-01-01 05:00:00 2015-01-01 5 77\n 7 Birrarung Marr 2015-01-01 06:00:00 2015-01-01 6 44\n 8 Birrarung Marr 2015-01-01 07:00:00 2015-01-01 7 56\n 9 Birrarung Marr 2015-01-01 08:00:00 2015-01-01 8 113\n10 Birrarung Marr 2015-01-01 09:00:00 2015-01-01 9 166\n# ℹ 66,027 more rows\n```\n\n\n:::\n:::\n\n\n\n::: {.callout-caution}\n## Your turn!\n\nIdentify the `index` variable, `key` variable(s), and measured variable(s) of this dataset.\n:::\n\n::: {.callout-tip}\n## Hint\n\n* The `index` variable contains the complete time information\n* The `key` variable(s) identify each time series\n* The measured variable(s) are what you want to explore/forecast.\n:::\n\n::: columns\n\n::: {.column width=\"30%\"}\n\n## `index` variable\n:::{.quiz-singlechoice}\n- [ ] [Sensor]{hint=\"x\"}\n- [X] [Date_Time]{hint=\"o\"}\n- [ ] [Date]{hint=\"x\"}\n- [ ] [Time]{hint=\"x\"}\n- [ ] [Count]{hint=\"x\"}\n:::\n:::\n\n::: {.column width=\"30%\"}\n\n## `key` variable(s)\n:::{.quiz-multichoice}\n- [X] [Sensor]{hint=\"o\"}\n- [ ] [Date_Time]{hint=\"x\"}\n- [ ] [Date]{hint=\"x\"}\n- [ ] [Time]{hint=\"x\"}\n- [ ] [Count]{hint=\"x\"}\n:::\n:::\n\n::: {.column width=\"40%\"}\n\n## measured variable(s)\n:::{.quiz-multichoice}\n- [ ] [Sensor]{hint=\"x\"}\n- [ ] [Date_Time]{hint=\"x\"}\n- [ ] [Date]{hint=\"x\"}\n- [ ] [Time]{hint=\"x\"}\n- [X] [Count]{hint=\"o\"}\n:::\n:::\n:::\n\n## Exercise 2\n\nThe `aus_accommodation` dataset contains quarterly data on Australian tourist accommodation from short-term non-residential accommodation with 15 or more rooms, 1998 Q1 - 2016 Q2. The first few lines are shown below.\n\n![](figs/spreadsheet.png)\n\nThe units of the measured variables are as follows:\n\n* Takings are in millions of Australian dollars\n* Occupancy is a percentage of rooms occupied\n* CPI is an index with value 100 in 2012 Q1.\n\n::: {.callout-caution}\n## Your turn!\n\nComplete the code to convert this dataset into a tsibble.\n:::\n\n\n\n::: {.cell exercise='make_tsibble'}\n```{webr}\n#| exercise: make_tsibble\nlibrary(______)\n\naus_accommodation <- read.csv(\n \"https://workshop.nectric.com.au/user2024/data/aus_accommodation.csv\"\n) |>\n mutate(Date = as.Date(Date)) |>\n as_tsibble(\n ______\n )\naus_accommodation\n```\n:::\n\n::: {.cell exercise='make_tsibble' check='true'}\n```{webr}\n#| exercise: make_tsibble\n#| check: true\nlibrary(qlcheckr)\n\napply_checks(\n c(\n \"You need to load the fpp3 package!\" = !(\"fpp3\" %in% .packages()),\n \"You need to use the as_tsibble() function to convert the data into a tsibble.\" = !search_ast(ql_ast(), .fn = as_tsibble),\n \"You should specify which column provides the time of the measurements with `index`.\" = exists_in(ql_messages(), grepl, pattern = \"as index variable\", fixed = TRUE),\n \"You need to specify the key variables that identify each time series\" = exists_in(ql_errors(), grepl, pattern = \"distinct rows\", fixed = TRUE)\n ),\n .msg_correct = if (!exists_in(ql_results(), \\(x) is_tsibble(x) && is_yearquarter(x[[index_var(x)]]))) \"Great, you've got a tsibble!<br>Although something doesn't look right - check the frequency of the data, why isn't it quarterly?\" else \"That's correct! Well done.\"\n)\n```\n:::\n\n\n\n::: { .hint exercise=\"make_tsibble\"}\n::: { .callout-note collapse=\"false\"}\n## Hint\n\nBegin by loading the `fpp3` library to use its time series functions.\n\n```r\nlibrary(fpp3)\n```\n:::\n:::\n\n::: { .hint exercise=\"make_tsibble\"}\n::: { .callout-note collapse=\"false\"}\n## Hint\n\nAfter loading the `fpp3` package, convert the data frame into a tsibble.\n\n```r\nlibrary(fpp3)\naus_accommodation <- read.csv(\n \"https://workshop.nectric.com.au/user2024/data/aus_accommodation.csv\"\n) |> mutate(Date = as.Date(Date))\n```\n:::\n:::\n\n::: { .hint exercise=\"make_tsibble\"}\n::: { .callout-note collapse=\"false\"}\n## Hint\n\nRemember to specify the time index and key for `as_tsibble()` to function correctly.\n\n```r\nlibrary(fpp3)\naus_accommodation <- read.csv(\n \"https://workshop.nectric.com.au/user2024/data/aus_accommodation.csv\"\n) |>\n mutate(Date = as.Date(Date)) |>\n as_tsibble(key = State, index = Date)\n```\n:::\n:::\n\n## Exercise 3\n\n:::{.callout-important}\n## Temporal granularity\n\nThe previous exercise produced a dataset with daily frequency - although clearly the data is quarterly! This is because we are using a daily granularity which is inappropriate for this data.\n:::\n\nCommon temporal granularities can be created with these functions:\n\n\n\n::: {.cell}\n::: {.cell-output-display}\n\n\n|Granularity |Function |\n|:-----------|:--------------------|\n|Annual |`as.integer()` |\n|Quarterly |`yearquarter()` |\n|Monthly |`yearmonth()` |\n|Weekly |`yearweek()` |\n|Daily |`as_date()`, `ymd()` |\n|Sub-daily |`as_datetime()` |\n\n\n:::\n:::\n\n\n\n\n::: {.callout-caution}\n## Your turn!\n\nUse the appropriate granularity for the `aus_accommodation` dataset, and verify that the frequency is now quarterly.\n:::\n\n\n\n\n::: {.cell exercise='process_accommodation_data'}\n```{webr}\n#| exercise: process_accommodation_data\naus_accommodation <- read.csv(\n \"https://workshop.nectric.com.au/user2024/data/aus_accommodation.csv\"\n) |>\n mutate(______) |>\n as_tsibble(\n key = State, index = ______\n )\n```\n:::\n\n::: {.cell exercise='process_accommodation_data' check='true'}\n```{webr}\n#| exercise: process_accommodation_data\n#| check: true\nlibrary(qlcheckr)\napply_checks(\n c(\n \"You need to load the fpp3 package!\" = !(\"fpp3\" %in% .packages()),\n \"You need to save the dataset as `aus_accommodation`\" = !exists(\"aus_accommodation\"),\n \"You need to use the as_tsibble() function to convert the data into a tsibble.\" = !search_ast(ql_ast(), .fn = as_tsibble),\n \"You need to specify the key variables that identify each time series\" = exists_in(ql_errors(), grepl, pattern = \"distinct rows\", fixed = TRUE),\n \"You should use `yearquarter()` to change the time column into a quarterly granularity\" = !is_yearquarter(aus_accommodation[[index_var(aus_accommodation)]])\n )\n)\n```\n:::\n\n\n\n::: { .hint exercise=\"process_accommodation_data\"}\n::: { .callout-note collapse=\"false\"}\n## Hint\n\nStart by reading the CSV file and transform the data using `mutate()` and `yearquarter()` for the Date column.\n\n```r\naus_accommodation <- read.csv(\n \"https://workshop.nectric.com.au/user2024/data/aus_accommodation.csv\"\n) |>\n mutate(Quarter = yearquarter(Date))\n```\n:::\n:::\n\n::: { .hint exercise=\"process_accommodation_data\"}\n::: { .callout-note collapse=\"false\"}\n## Hint\n\nAfter transforming the Date column, make sure you convert the data frame to a tsibble.\n\n```r\naus_accommodation <- read.csv(\n \"https://workshop.nectric.com.au/user2024/data/aus_accommodation.csv\"\n) |>\n mutate(Quarter = yearquarter(Date)) |>\n as_tsibble(key = State, index = Quarter)\n```\n:::\n:::\n\n## Exercise 4\n\nThe `tourism` dataset contains the quarterly overnight trips from 1998 Q1 to 2016 Q4 across Australia.\n\nIt is disaggregated by 3 key variables:\n\n* `State`: States and territories of Australia\n* `Region`: The tourism regions are formed through the aggregation of Statistical Local Areas (SLAs) which are defined by the various State and Territory tourism authorities according to their research and marketing needs\n* `Purpose`: Stopover purpose of visit: \"Holiday\", \"Visiting friends and relatives\", \"Business\", \"Other reason\".\n\nCalculate the total quarterly tourists visiting Victoria from the `tourism` dataset.\n\n\n\n::: {.cell exercise='filter_summarise_tourism'}\n```{webr}\n#| exercise: filter_summarise_tourism\ntourism |>\n filter(______) |>\n summarise(______)\n```\n:::\n\n::: {.cell exercise='filter_summarise_tourism' check='true'}\n```{webr}\n#| exercise: filter_summarise_tourism\n#| check: true\nlibrary(qlcheckr)\napply_checks(\n c(\n \"You need to load the fpp3 package!\" = !(\"fpp3\" %in% .packages()),\n \"You need to use the filter() function to extract only Victorian tourists.\" = !search_ast(ql_ast(), .fn = filter),\n \"You need to use the summarise() function to sum over the Region and Purpose keys.\" = !search_ast(ql_ast(), .fn = summarise)\n )\n)\n```\n:::\n\n\n\n::: { .hint exercise=\"filter_summarise_tourism\"}\n::: { .callout-note collapse=\"false\"}\n## Hint\n\nTo start off, filter the `tourism` dataset for only Victoria.\n\n```r\ntourism |>\n filter(State == \"Victoria\")\n```\n:::\n:::\n\n::: { .hint exercise=\"filter_summarise_tourism\"}\n::: { .callout-note collapse=\"false\"}\n## Hint\n\nAfter filtering, summarise the total trips for Victoria.\n\n```r\ntourism |>\n filter(State == \"Victoria\") |>\n summarise(Trips = sum(Trips))\n```\n:::\n:::\n\nFind what combination of `Region` and `Purpose` had the maximum number of overnight trips on average.\n\n\n\n::: {.cell exercise='group_summarise_filter_tourism'}\n```{webr}\n#| exercise: group_summarise_filter_tourism\ntourism |>\n as_tibble() |>\n group_by(______) |>\n summarise(______) |>\n filter(______)\n```\n:::\n\n::: {.cell exercise='group_summarise_filter_tourism' check='true'}\n```{webr}\n#| exercise: group_summarise_filter_tourism\n#| check: true\nlibrary(qlcheckr)\napply_checks(\n c(\n \"You need to load the fpp3 package!\" = !(\"fpp3\" %in% .packages()),\n \"You need to use the as_tibble() function to convert back to a tibble object.\" = !search_ast(ql_ast(), .fn = as_tibble),\n \"You need to use the group_by() function to group by Region and Purpose.\" = !search_ast(ql_ast(), .fn = group_by)\n )\n)\n```\n:::\n\n\n\n::: { .hint exercise=\"group_summarise_filter_tourism\"}\n::: { .callout-note collapse=\"false\"}\n## Hint\n\nStart by using `as_tibble()` to convert `tourism` back to a tibble and group it by Region and Purpose.\n\n```r\ntourism |>\n as_tibble() |>\n group_by(Region, Purpose)\n```\n:::\n:::\n\n::: { .hint exercise=\"group_summarise_filter_tourism\"}\n::: { .callout-note collapse=\"false\"}\n## Hint\n\nAfter grouping, summarise the mean number of trips and filter for maximum trips.\n\n```r\ntourism |>\n as_tibble() |>\n group_by(Region, Purpose) |>\n summarise(Trips = mean(Trips), .groups = \"drop\") |>\n filter(Trips == max(Trips))\n```\n:::\n:::\n\nCreate a new tsibble which combines the Purposes and Regions, and just has total trips by State.\n\n\n\n::: {.cell exercise='summarise_tourism_by_state'}\n```{webr}\n#| exercise: summarise_tourism_by_state\ntourism |>\n group_by(______) |>\n summarise(______)\n```\n:::\n\n::: {.cell exercise='summarise_tourism_by_state' check='true'}\n```{webr}\n#| exercise: summarise_tourism_by_state\n#| check: true\nlibrary(qlcheckr)\napply_checks(\n c(\n \"You need to group by the State to summarise trips for each state.\" = !search_ast(ql_ast(), .expr = group_by(State)),\n \"You need to use the summarise() function to sum trips for each state.\" = !search_ast(ql_ast(), .expr = summarise(Trips = sum(Trips)))\n )\n)\n```\n:::\n\n\n\n::: { .hint exercise=\"summarise_tourism_by_state\"}\n::: { .callout-note collapse=\"false\"}\n## Hint\n\nTo summarise the number of trips by each State, start by grouping the data by State.\n\n```r\ntourism |>\n group_by(State)\n```\n:::\n:::\n\n::: { .hint exercise=\"summarise_tourism_by_state\"}\n::: { .callout-note collapse=\"false\"}\n## Hint\n\nAfter grouping, use the `summarise()` function to sum the trips.\n\n```r\ntourism |>\n group_by(State) |>\n summarise(Trips = sum(Trips))\n```\n:::\n:::\n",
"supporting": [
"activities_files"
],
"supporting": [],
"filters": [
"rmarkdown/pagebreak.lua"
],
Expand Down
4 changes: 2 additions & 2 deletions _freeze/week1/index/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"hash": "0dfc06e329b0f30f0a195b8230d86134",
"hash": "e0b5be222d3e1ca2e727ef27e0f73b9d",
"result": {
"engine": "knitr",
"markdown": "---\ntitle: \"Week 1: What is forecasting?\"\n---\n\n::: {.cell}\n\n:::\n\n\n\n## What you will learn this week\n\n* How to think about forecasting from a statistical perspective\n* What makes something easy or hard to forecast?\n* Using the `tsibble` package in R\n\n## Pre-class activities\n\nBefore we start classes, make sure you are familiar with R, RStudio and the tidyverse packages. If you've already done one of ETX2250/ETC1010 or something equivalent you should be fairly familiar with these concepts and probably will not need much help. If you're new to R and the tidyverse, then you will need to get yourself up-to-speed. \n\n- Install/update R, RStudio. See [https://otexts.com/fpp3/appendix-using-r.html](https://otexts.com/fpp3/appendix-using-r.html)\n- Install required packages `install.packages(c(\"tidyverse\",\"fpp3\", \"GGally\"), dependencies = TRUE)`\n- Explore StartR: [https://startr.numbat.space/](https://startr.numbat.space/). Work through **Getting started** (5 modules) and **Writing documents** (1 module). Do as much of it as you think you need. For those students new to R, it is strongly recommended that you do all these. For those who have previously used R, concentrate on the parts where you feel you are weakest.\n- Read [Chapter 1 of the textbook](http://OTexts.com/fpp3/intro.html) and watch all embedded videos. Pay particular attention to [Section 1.7](https://otexts.com/fpp3/perspective.html).\n- Read [Section 2.1 of the textbook](https://otexts.com/fpp3/tsibbles.html#tsibbles) and watch the embedded video.\n\n\n\n\n\n## [Workshop activities](activities.qmd)\n\n\n\n\n<!-- ## Seminar code -->\n\n<!-- ::: {.callout appearance=\"minimal\"} -->\n<!-- <i class=\"bi bi-download\"></i> [Seminar_code_week1.R](Seminar_code_week1.R){download=\"Seminar_code_week1.R\"} -->\n<!-- ::: -->\n\n\n## Tutorial exercises\n\nThe main tasks for Week 1 tutorials will be:\n\n1. To ensure that you have successfully installed R and RStudio on your own laptop.\n2. Work your way through **Getting started** (5 modules) and **Writing documents** (1 module). This is material we have prepared for you and other Monash students working in R. You should do these at your own pace to understand the concepts.\n3. Discuss [IA1](https://bf.numbat.space/assignments/A1.html) in class. How do you go about forecasting at the moment that you are untrained? \n\nYour tutors will be in your tutorial class to assist you. \n\n<!-- [**Check your understanding quiz**](https://learning.monash.edu/mod/quiz/view.php?id=2327331) -->\n\n\n\n\n## Assignments\n\n* [IA1](../assignments/A1.qmd) is due on Monday 10 March.\n",
"markdown": "---\ntitle: \"Week 1: What is forecasting?\"\n---\n\n::: {.cell}\n\n:::\n\n\n\n\n## What you will learn this week\n\n* How to think about forecasting from a statistical perspective\n* What makes something easy or hard to forecast?\n* Using the `tsibble` package in R\n\n## Pre-class activities\n\nBefore we start classes, make sure you are familiar with R, RStudio and the tidyverse packages. If you've already done one of ETX2250/ETC1010 or something equivalent you should be fairly familiar with these concepts and probably will not need much help. If you're new to R and the tidyverse, then you will need to get yourself up-to-speed. \n\n- Install/update R, RStudio. See [https://otexts.com/fpp3/appendix-using-r.html](https://otexts.com/fpp3/appendix-using-r.html)\n- Install required packages `install.packages(c(\"tidyverse\",\"fpp3\", \"GGally\"), dependencies = TRUE)`\n- Explore StartR: [https://startr.numbat.space/](https://startr.numbat.space/). Work through **Getting started** (5 modules) and **Writing documents** (1 module). Do as much of it as you think you need. For those students new to R, it is strongly recommended that you do all these. For those who have previously used R, concentrate on the parts where you feel you are weakest.\n- Read [Chapter 1 of the textbook](http://OTexts.com/fpp3/intro.html) and watch all embedded videos. Pay particular attention to [Section 1.7](https://otexts.com/fpp3/perspective.html).\n- Read [Section 2.1 of the textbook](https://otexts.com/fpp3/tsibbles.html#tsibbles) and watch the embedded video.\n\n\n\n\n\n## Slides for seminar\n\n<embed src='/week1/week1.pdf' type='application/pdf' width='100%' height=465></embed>\n<a href=/week1/week1.pdf class='badge badge-small badge-red'>Download pdf</a>\n\n## [Workshop activities](activities.qmd)\n\n\n\n\n\n<!-- ## Seminar code -->\n\n<!-- ::: {.callout appearance=\"minimal\"} -->\n<!-- <i class=\"bi bi-download\"></i> [Seminar_code_week1.R](Seminar_code_week1.R){download=\"Seminar_code_week1.R\"} -->\n<!-- ::: -->\n\n\n## Tutorial exercises\n\nThe main tasks for Week 1 tutorials will be:\n\n1. To ensure that you have successfully installed R and RStudio on your own laptop.\n2. Work your way through **Getting started** (5 modules) and **Writing documents** (1 module). This is material we have prepared for you and other Monash students working in R. You should do these at your own pace to understand the concepts.\n3. Discuss [IA1](https://bf.numbat.space/assignments/A1.html) in class. How do you go about forecasting at the moment that you are untrained? \n\nYour tutors will be in your tutorial class to assist you. \n\n<!-- [**Check your understanding quiz**](https://learning.monash.edu/mod/quiz/view.php?id=2327331) -->\n\n\n\n\n\n## Assignments\n\n* [IA1](../assignments/A1.qmd) is due on Monday 10 March.\n",
"supporting": [],
"filters": [
"rmarkdown/pagebreak.lua"
Expand Down
Loading

0 comments on commit 7bfd272

Please sign in to comment.