```{r, include = FALSE}
current_file <- knitr::current_input()
basename <- gsub(".Rmd$", "", current_file)

knitr::opts_chunk$set(
  fig.path = sprintf("images/%s/", basename),
  fig.width = 6,
  fig.height = 4,
  fig.align = "center",
  fig.retina = 3,
  echo = TRUE,
  warning = FALSE,
  message = FALSE,
  cache = FALSE,
  cache.path = "cache/"
)
```

```{r titleslide, child="assets/titleslide.Rmd"}
```
---

class: center middle bg-gray

.aim-box.tl.w-70[
Today you will:

- Learn about exploratory data techniques and analysis
- Consider ethical standpoints when making recommendations
- Combine multiple sources of data to increase information

]

---

# Bring your minds back

It's August 2020. You're in Victoria, working as a public health advisor to the state government.

Movement restrictions are the tighest they've ever been, and for a long time too.

The number of COVID-19 cases is staying stubbornly high. You've been tasked with working out what should be done, and when.

.question-box.w-100[
  What should you do?
]

---

# Let's get some data

COVID-19 was an unusual succses of open data, **but**

* No standard format
* No standard reporting window
* No standard distribution method

These days, a lot of the COVID data sources are no longer being (regularly) updated. 

The Victorian government has a dataset of cases available [on their website](https://discover.data.vic.gov.au/dataset/victorian-coronavirus-data).

---

```{r, message = FALSE, warning = FALSE}
library(tidyverse)
cases <- read_csv("./data/ncov_cases_by_postcode_lga.csv")

glimpse(cases)
```

--

.question-box[
  What is the structure of this dataset?

  What do the columns mean?
]

---

# Some definitions

* Local Government Area (LGA): A geographic area mostly represented by a single council.
* PCR: Polymerase-chain reaction. A method for replicating virus to detect it's presence/absence.
* RAT: Rapid antigen test. A less specific and sensitive test that provides presence/absence of an organism.

---

# Data exploration

Today is August 1, 2020. Let's have a look back at the last 2 months:

```{r}
date_interval <- interval(ymd("2020-09-30") - months(2), ymd("2020-09-30"))
cases %>%
  filter(diagnosis_date %within% date_interval) %>%
  group_by(diagnosis_date) %>%
  ggplot(aes(x = diagnosis_date, y = Total_case_count)) +
  geom_line() +
  labs(x="Date", y="Cases")
```

---

# Data exploration

Cases are listed separately by geography, so we need to group them up:

```{r}
cases %>%
  filter(diagnosis_date %within% date_interval) %>%
  group_by(diagnosis_date) %>%
  summarise(n = sum(Total_case_count)) %>%
  ggplot(aes(x = diagnosis_date, y = n)) +
  geom_line() +
  labs(x = "Date", y = "Cases")
```

---

class: transition

We've generated evidence of the problem.

What are some ideas for solutions?

---

# Spatial variation

There is much talk about differences in geographical response to COVID. It started as differences between the states, now people are talking about within the state itself.

Senior people are talking about restrictions "not working": what does that mean?

--

Let's have a look at spatially disaggregated data.

---

# Spatial variation

```{r}
cases %>%
  filter(diagnosis_date %within% date_interval) %>%
  group_by(diagnosis_date, lga_name) %>%
  summarise(n = sum(Total_case_count)) %>%
  ggplot(aes(x = diagnosis_date, y = n, colour = lga_name)) +
  geom_line()
```

--

A little hard to see...

---

# Spatial variation

.f4[
```{r}
cases %>%
  filter(diagnosis_date %within% date_interval) %>%
  group_by(lga_name) %>%
  arrange(diagnosis_date) %>%
  mutate(n = cumsum(Total_case_count)) %>%
  ggplot(aes(x = diagnosis_date, y = n, colour = lga_name)) +
  geom_line() + guides(colour="none")
```
]

What do you see?

---

class: transition

### The order of the lines doesn't change much

Perhaps restrictions aren't as effective in certain places

---

# Mobility data

Google released a series of "mobility reports" that attempted to quantify changes in mobility patterns using mobile phone data.

The reports are no longer updated but are available online:

[https://www.google.com/covid19/mobility/](https://www.google.com/covid19/mobility/)

---

# Let's take a peak

.f4[
```{r}
mobility <- read_csv("data/2020_AU_Region_Mobility_Report.csv")
head(mobility)
```

Quite big: `r nrow(mobility)` rows and `r ncol(mobility)` columns.

Let's try to find Victoria...

]

---

# Let's take a peak

.f4[
```{r}
vic_mobility <- mobility %>%
  filter(sub_region_1 == "Victoria", !is.na(sub_region_2))

head(vic_mobility)
```
]

Closer...

--

Incidentally, this is the classic quest of the analyst. A lot of time manipulating data to answer a seemingly straightforward question.

---

# Let's take a peak

```{r}
vic_mobility %>%
  filter(date %within% date_interval) %>%
  ggplot(aes(x = date, y = workplaces_percent_change_from_baseline, colour = sub_region_2)) +
  geom_line() + guides(colour = "none")
```

--

Unreadable.

--

Suggestions for fixes?

---

# So back to the question

After playing around with our data, I find it useful to return to the question. For us that was:

What should be done to try to reduce COVID cases, and why?

--

You've heard talks of movement restrictions being further tightened and are expecting to be asked about that. Let's see if we can get a handle on how explanatory mobility is on cases...

---

# Mobility and cases

In theory, mobility should be tied closely to cases. For an infectious disease to spread between two people:

* There has to be contact between two people
* One has to be _susceptible_
* One has to be infectious
* Virus has to somehow move from the susceptible person to the infectious person

It is hard to control points 2, 3 and 4, so a lot of effort goes to point 1.

Mobility restrictions _decrease_ the amount of time an individual spends in community, so while they may still infect those close to them, they should be less likely to see transmission outside their household.

---

# Mobility and cases

Let's join together our two datasets:

.f4[
```{r}
cases %>%
  left_join(mobility, by = join_by(diagnosis_date == date, lga_name == sub_region_1))
```
]

---

# Mobility and cases

We know the focus is on metropolitan Melbourne, so let's focus down on just those at least:

```{r}
metro_lgas <- c(
  "Melbourne", "Port Phillip", "Yarra", "Stonnington", "Bayside", "Boroondara", "Glen Eira",
  "Melton", "Brimbank", "Hobsons Bay", "Wyndham", "Moonee Valley", "Maribyrnong", "Mitchell (part)",
  "Banyule", "Whittlesea", "Nillumbik", "Hume", "Moreland", "Darebin",
  "Manningham", "Whitehorse", "Knox", "Yarra Ranges", "Maroondah", "Monash",
  "Kingston", "Frankston", "Cardinia", "Casey", "Greater Dandenong", "Mornington Peninsula"
)
```

--

What's coming next is the classic plight of the data analyst...

--

Inconsistent naming conventions.

---

# Challenge: Making the LGA names match

Download the mobility data and the case data from these two websites:

* Case data: [https://discover.data.vic.gov.au/dataset/victorian-coronavirus-data](https://discover.data.vic.gov.au/dataset/victorian-coronavirus-data)
* Mobility data: [https://www.google.com/covid19/mobility/](https://www.google.com/covid19/mobility/)

Have a go at getting `sub_region_2` to match `lga_name`.

When you make some progress, shout it out - let's try to solve it together.

---

# Challenge: Making the LGA names match

```{r, echo=FALSE}
chosen_date <- ymd("2020-09-01")
vic_mobility <- vic_mobility |>
  mutate(
    new_lga_name = str_remove_all(
      sub_region_2, " Shire|City of | City|Shire of | Rural City"
    )
  ) |>
  mutate(
    new_lga_name =
      case_when(
        new_lga_name == "Colac Otway" ~ "Colac-Otway",
        new_lga_name == "Moreland" ~ "Merri-bek",
        .default = new_lga_name
      )
  )

cases <- cases |>
  filter(!lga_name %in% c("Unknown", "Interstate")) |>
  filter(diagnosis_date >= chosen_date - 30, diagnosis_date <= chosen_date) |>
  mutate(
    lga_name = str_remove_all(lga_name, " \\([CS]\\)| \\(RC\\)")
  ) %>%
  filter(lga_name %in% metro_lgas)
```

Let's look at the total cases over the previous month to now, and compare that to mobility.

```{r}
cases_vs_mobility <- cases %>%
  group_by(diagnosis_date, lga_name) %>%
  summarise(total_cases = sum(Total_case_count)) %>%
  left_join(vic_mobility, by = join_by(lga_name == new_lga_name, diagnosis_date == date)) %>%
  group_by(lga_name) %>%
  summarise(
    n = sum(total_cases),
    mean_mobility_change = mean(workplaces_percent_change_from_baseline, na.rm = TRUE)
  )
```

---

# Challenge: Making the LGA names match

.f4[
```{r}
cases_vs_mobility
```
]

--

Let's try and plot

---

# Plotting our exploratory analysis

```{r}
cases_vs_mobility %>%
  ggplot(aes(x = n, y = mean_mobility_change)) +
  geom_point()
```

--

Thoughts?

---

# Plotting our exploratory analysis

An aside: Let's think about how to format this for a report. Non-technical readers will struggle with the previous plot, and we can make the point much more clearly.

```{r}
cases_vs_mobility %>%
  ggplot(aes(x = lga_name, y = mean_mobility_change)) +
  geom_col()
```

--

Column graphs like this are very easy to read and understand. This one could do with some work.

---

# Challenge: Create this plot

```{r, echo=FALSE, fig.height=8, fig.width = 13}
library(colorspace)
cases_vs_mobility %>%
  ggplot(aes(x = -1 * mean_mobility_change, y = forcats::fct_reorder(lga_name, n), fill = n)) +
  geom_col() +
  labs(x = "Reduction in workplace mobility", y = "LGA", fill = "Cases") +
  ggtitle("The trend between workplace mobility and cases") +
  scale_fill_continuous_sequential(palette = "BurgYl") +
  theme_bw()
```

---

# Interpreting our results

Before we go to writing our report, it is good practice to think about the ethical dilemma of this situation.

✅ We have a deidentified, aggregated dataset, which we have further aggregated

✅ We have filtered the dataset to only "high" numbers of cases

But our conclusions here have real-world impacts: People in a position of power are relying on this evidence to decide whether to increase lockdowns.

--

[One doesn't have to look far to see when this can go wrong](https://www.ombudsman.vic.gov.au/our-impact/news/public-housing-tower-lockdown/)

--

This is a different type of ethics to what we've discussed previously, but is an important part of generating new knowledge.

An ethics committee will only approve research if **the potential benefits of the project justify any risks**.

--

Do you think that is the case here?

---

# Interpreting our results

What is the conclusion here?

We have _some_ (weak) evidence that mobility is associated with lower cases.

--

**But** there is little to no evidence that further decreasing mobility will decrease cases more.

--

#### Why?

---

class: transition

# Conclusion

Challenge for 5 minutes: Write a two sentence executive summary outlining what you think the findings are.

Then, swap with someone else in the room and see if you agree.

---

# Conclusion and communication

The reality is, most stakeholders won't read past your executive summary and a key picture.

So, **spend time on the things that matter**!

Here, we set out to think about what COVID measures may or may not further impact transmission. We have _answered what probably won't work_ but not provided any solutions.

* In most cases this will get sent back with a question: "So what should we do?"

How do you deal with that?

--

#### Keep looking!

--

More exploration will hopefully lead to more possibilities.

---

class: bg-gray middle center



.idea-box.tl.w-70[

## Summary

* We looked at using open data to answer a specific question
* We generated evidence _against_ a specific policy
* We thought about how to communicate this, both written and visually
* We learnt about the plight of no standards being adhered to

]

---

class: transition

#### Slides created by Dr Michael Lydeamore

---

```{r endslide, child="assets/endslide.Rmd"}
```
