Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 10 additions & 79 deletions s4/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ In this session, we will learn how to use origin-destination data. To do that we

# Review Homework

Your homework last week was to review some AI written code. Divide into groups of 2-3 people and share the question you asked AI, the code it produced, and the results it got.
In the previous session and for your homework, you used AI to assist with loading datasets, creating visualizations, and working through vignettes on origin-destination (OD) using the `od` and `pct` packages. Let's evaluate your findings in groups of 2-3.

* Does the code run first time?
* Do the results answer the question?
* Try modifying the code and the prompt to improve the code generated by the AI.
* Discuss in your groups the strengths and weaknesses of AI written code.
* **The Workflow**: Show your group the specific prompts you gave the AI, the code it generated, and the resulting output.

* **The "First Run"** Test: Did the code run the first time? If it failed, what caused the error (e.g., outdated library syntax, incorrect file paths, or spatial projection issues)?

* **Accuracy**: Did the AI truly understand the spatial logic of data, or did it just provide a generic visualization?

* **Refinement**: Share how you modified your prompts or the code itself to achieve a better, more accurate result.

# Getting started with GIS in R

Expand Down Expand Up @@ -1073,79 +1076,7 @@ bike_trips |>
# Homework

1. Read Chapters 2-5 of [Geocomputation with R](https://r.geocompx.org/transport.html)
2. Using knowledge about datasets and new skills covered in the practicals 2 and 3, think of a simple research question that could be answered by analysing/visualising/modelling one of the datasets imported into R in your previous homework (or another dataset you have imported into R).
3. Write a prompt, starting with your own code that imports the code, to generate some code answering the question and write it down in a new Quarto file called `gen-ai-test.qmd`.
4. Copy the prompt and paste it into a generative AI chat interface such as [ChatGPT](https://chatgpt.com), [Claude](https://claude.ai/), [DeepSeek](https://chat.deepseek.com/) or [Gemini](https://gemini.google.com/)
5. Paste the resulting code into a code chunk in a new .qmd file, e.g. called `gen-ai-test.qmd`.
- Does the code run first time?
- Do the results answer the question?
- Try modifying the code and the prompt to improve the code generated by the AI.
- Note: in the next practical session we will review the AI-generated code you will share the code with a colleague and they will try to run it.
6. Bonus: try setting-up Copilot or other code auto-completion system in RStudio using the documentation at
<!-- https://docs.posit.co/ide/user/ide/guide/tools/copilot.html -->
[docs.posit.co](https://docs.posit.co/ide/user/ide/guide/tools/copilot.html) or VSCode using the [GitHub Copilot](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot) extension.
7. Bonus: share your code on GitHub, for example by pasting it into the discussion group at [github.com/ITSLeeds/TDS/discussions](https://github.com/itsleeds/tds/discussions/172) or by creating a repo on your own GitHub account.
8. Bonus: Read more about using the [tmap package](https://r-tmap.github.io/tmap/)
9. Bonus: Read more about the [ggplot2 package](https://ggplot2.tidyverse.org/)

<details>

I wrote the following prompt:

Starting with the following R code that starts by loading the tidyverse and stats19 R packages, write a script that finds out which local authorities saw the greatest percentage point decrease in the number of road traffic collisions between 2019 and 2020.
Explore this relationship for the total number of collisions with summary statistics, ggplot2 visualisations, and perhaps a basic model. Furthermore, explore how the % change in collision numbers vary depending on factors such as urban or rural area, casualty severity, and the month used for comparison.

```{r}
#| eval: false
library(tidyverse)
library(stats19)
collisions_2019 = get_stats19(2019)
collisions_2020 = get_stats19(2020)
collisions_combined = bind_rows(
mutate(collisions_2019, year = 2019),
mutate(collisions_2020, year = 2020)
)
# names(collisions_2020)
# [1] "accident_index"
# [2] "accident_year"
# [3] "accident_reference"
# [4] "location_easting_osgr"
# [5] "location_northing_osgr"
# [6] "longitude"
# [7] "latitude"
# [8] "police_force"
# [9] "accident_severity"
# [10] "number_of_vehicles"
# [11] "number_of_casualties"
# [12] "date"
# [13] "day_of_week"
# [14] "time"
# [15] "local_authority_district"
# [16] "local_authority_ons_district"
# [17] "local_authority_highway"
# [18] "first_road_class"
# [19] "first_road_number"
# [20] "road_type"
# [21] "speed_limit"
# [22] "junction_detail"
# [23] "junction_control"
# [24] "second_road_class"
# [25] "second_road_number"
# [26] "pedestrian_crossing_human_control"
# [27] "pedestrian_crossing_physical_facilities"
# [28] "light_conditions"
# [29] "weather_conditions"
# [30] "road_surface_conditions"
# [31] "special_conditions_at_site"
# [32] "carriageway_hazards"
# [33] "urban_or_rural_area"
# [34] "did_police_officer_attend_scene_of_accident"
# [35] "trunk_road_flag"
# [36] "lsoa_of_accident_location"
# [37] "enhanced_severity_collision"
# [38] "datetime"
```

</details>
2. Bonus: Read more about using the [tmap package](https://r-tmap.github.io/tmap/)
3. Bonus: Read more about the [ggplot2 package](https://ggplot2.tidyverse.org/)

# References