DAPR1 Workshops
  • 1: Exploratory Data Analysis
    • W1: Introductions
    • W2: Data & Variables
    • W3: Visualising Distributions
    • W4: Summarising Distributions I – Central Tendency
    • W5: Summarising Distributions II – Variability
  • 2: Introduction to Inference
    • W7: Z-scores & the Normal Distribution
  • 3: Common Statistical Tests
  • 4: The Move to Modelling

W3: Visualising Distributions

Pick someone new to be the driver this week. They will type the code. The rest of you are navigators, you need to tell the driver where to go (i.e., what to type!).

Driver instructions:

  1. Log in to the bigger screen at your table
  2. Open RStudio Server. See the first drop-down in the FAQs page for instructions
  3. Open a new .R script, and load the tidyverse package.
  4. Listen to your navigators

Navigator instructions:

  1. Tell your driver where to go (i.e., what to type)!
Question 1

For this week, we are going to use the same data as last week (the survey that many of you completed in the first week). The data are stored at https://uoepsy.github.io/data/dapr1_2627_survey.csv
(Check back to your work from last week to remind yourself how to get the data into R).

One of the questions in the survey asked people to choose between Dog and Cat (with options for “both” and “neither” as well).
Create a frequency table for this variable (catdog).

🗂️ See Read in and inspect data flash card.

🗂️ See Make a frequency table flash card.

Solution 1.

library(tidyverse)
sdata <- read_csv("https://uoepsy.github.io/data/dapr1_2627_survey.csv")

sdata |>
  count(catdog) |>
  mutate(
    Percent = round((n/sum(n))*100, 2)
  )
# A tibble: 4 × 3
  catdog      n Percent
  <chr>   <int>   <dbl>
1 both       37   27.6 
2 cat        47   35.1 
3 dog        44   32.8 
4 neither     6    4.48

Question 2

Based on the previous question, what do you think a visualisation of the distribution of the catdog variable will look like?

To check if your guess is right, plot the catdog variable.

🗂️ See Plot a variable flash card.

Solution 2.

ggplot(sdata, aes(x = catdog)) +
  geom_bar()

Question 3

Another question in the survey asked people how far away (in kilometers) they were born (the distance_born variable in the dataset).

Visualise this variable using a histogram.

🗂️ See Plot a variable flash card.

Solution 3.

ggplot(sdata, aes(x = distance_born)) + 
  geom_histogram()

Question 4

Now visualise this same variable using a density plot.

🗂️ See Plot a variable flash card.

Solution 4.

ggplot(sdata, aes(x = distance_born)) + 
  geom_density()

Question 5

Write a few sentences commenting on the distribution of birthplace distances from Edinburgh. Specifically, make sure to comment on:

  • centre
  • spread
  • shape (unimodal/bimodal/multimodal)
  • shape (symmetric vs positive/negative skew)

Solution 5. The distribution of birthplace distances from Edinburgh is very spread out, with values spanning over 15,000 km. Most values are piled up around 0 km, suggesting that most respondents were born near Edinburgh. The shape of the distribution is bimodal, and the extended right tail shows positive skew (i.e., it is asymmetrical).

Finishing up

Once you’ve finished, don’t forget to:

  1. Save your R script
  2. Post the R script to the group discussion space on Learn, to ensure that everyone has access to it! (For step-by-step instructions on how to do this, click here)