## `r emo::ji("target")` Objectives

In this tutorial, you will learn to

- integrate data from different sources (census and election) to make exploratory inferences
- compare summary statistics by region using different geographical statistics
- we will use the 2016 census data (you will use 2021 data on your assignment)


## `r emo::ji("wrench")` Preparation  

Note: you should do Preparation **_before_** the tutorial.  

**1. Ensure you load the packages you'll need** 

```{r warning = FALSE, message = FALSE}
library(sf)
library(tidyverse)
```


**2. Get the  geographical boundaries for 2016 census regions**. 

Go to https://www.abs.gov.au/census/find-census-data/geopackages select the following options:

      * 2016  
      * Victoria  
      * Employment, Income and Unpaid Work (EIUW).  
      * EIUW GeoPackage A.  

```{r}
SA1map <- read_sf(here::here("data/Geopackage_2016_EIUWA_for_VIC/census2016_eiuwa_vic_short.gpkg"), 
                  layer = "census2016_eiuwa_vic_sa1_short")
```

**3. You will also need the data for the 2018 electoral boundaries**. 

You have a copy of the 2022 boundaries from Tutorial 5.  

For today download the [2018 boundaries](https://www.aec.gov.au/electorates/gis/gis_datadownload.htm) from here. These are closer to the 2016 year of the census

```{r, message=FALSE}
vic_map <- read_sf(here::here("data/vic-july-2018-esri/E_AUGFN3_region.shp")) %>% 
   # to match up with election data
   mutate(DivisionNm = toupper(Elect_div)) 
```

## 🏂 Exercise 6A

**Integrate data from different sources**

* Import the GeoPackage data with SA1 regions. 

* Calculate the centroids for each SA1 region.   

* Plot the median weekly personal income data on top of the electoral boundaries like below. Can you find which regions have wealthy individuals? 

```{r income-map, echo = FALSE, message = FALSE, warning = FALSE}
SA1map <- SA1map %>% 
   mutate(centroid = st_centroid(geom))

ggplot(SA1map) +
   geom_sf(aes(geometry = centroid, color = Median_tot_prsnl_inc_weekly), shape = 3) + 
   geom_sf(data = vic_map, aes(geometry = geometry), fill = "transparent", size = 1.3, color = "black") +
   coord_sf(xlim = c(144.8, 145.2), ylim = c(-38.1, -37.6)) +
  scale_color_viridis_c(name = "Median weekly\nperson income", option = "magma")
```

* Looking at the map above, there is one electorate won by the Green party. Looking at the map above, this is where a lot of wealthy individuals live? 

* Can you say that those who vote for the Green party are rich individuals? Why or why not? Discuss with your classmates.   

* Why do some geographical regions look sparse in terms of the census reported median weekly personal income?  

* What is **ecological fallacy**? How does it relate to your conclusion from before?  

* Estimate a median weekly personal income for the Melbourne district.  


## 🗾 Exercise 6B

**Compare with different a layer**

Repeat 6A using now the SED regions. How does the estimate of median weekly personal income for the Melbourne district differ to your calculation from 6A? What about estimates in other districts?

```{r}
SEDmap <- read_sf(here::here("data/Geopackage_2016_EIUWA_for_VIC/census2016_eiuwa_vic_short.gpkg"), 
                  layer = "census2016_eiuwa_vic_sed_short")
```

### Material maintained and updated by Dr. Kate Saunders. Material originally developed by Dr. Emi Tanaka. 
