This week's coding goals

  1. Download RStudio onto my laptop
    • Download the relevant packages
  2. Work through as many Week 3 videos and exercises as possible
    • Because this week was divided into 2 parts, I wanted to at least finish the Hello Data section and take it slow with the Data Wrangling section and just make sure I can understand everything

How did I go?

Goal 1: Downloading RStudio onto my laptop

Challenge 1

  • I didn't realise that the RStudio version had to match with the operating system version that my laptop had so I downloaded the latest version of RStudio. This seemed fine until I had to download certain packages like "rstatix" and I kept getting error messages saying that the package was incompatible with the RStudio version that I had.
  • Success: after attending the Q&A session, I was able to figure out that I had to download the matching RStudio version to my current operating system.

Challenge 2

  • Another challenge I faced was reading files onto my desktop RStudio. For example, I would write:
# Load package
library(tidyverse)

# Read the data into R
forensic <- read_csv(file = "data_forensic.csv")
  • It would come up with the error:

Error: 'data_forensic.csv' does not exist in current working directory ('/Users/jadegurtala').

  • After some experimenting, I figured out that I have to set a working directory for the folder in which I'm retrieving the file from and then, I was able to read the data into R!

Goal 2: Work through as many Week 3 Videos and exercises as possible

Exercise 1

# Load the package
library(tidyverse)
## ── Attaching packages ──────────────────────────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.4     ✓ purrr   0.3.4
## ✓ tibble  3.1.2     ✓ dplyr   1.0.6
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.1
## ── Conflicts ─────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
# Load the swow data
swow <- read_tsv("data_swow.csv.zip")
## ! Multiple files in zip: reading ''swow.csv''
## ── Column specification ─────────────────────────────────────────────────────────────────────────────
## cols(
##   cue = col_character(),
##   response = col_character(),
##   R1 = col_double(),
##   N = col_double(),
##   R1.Strength = col_double()
# Adding the "mystery" line
swow <- swow %>% mutate(id = 1:n())     # Adding the id column
# Rename the data
swow <- swow %>% 
  rename(
    n_response = R1, 
    n_total = N, 
    strength = R1.Strength
  )
## ! Multiple files in zip: reading ''swow.csv''
## ── Column specification ─────────────────────────────────────────────────────────────────────────────
## cols(
##   cue = col_character(),
##   response = col_character(),
##   R1 = col_double(),
##   N = col_double(),
##   R1.Strength = col_double()

Exercise 2

Forward associations with 'woman'

woman_fwd <- swow %>%
  filter(cue == "woman", n_response > 1)
  
woman_bck <-swow %>% 
  filter(response == "woman", n_response > 1) %>% 

Exercise 3

Forward and backwards associations with 'man'

man_fwd <- swow %>% 
  filter(cue == "man", n_response >1)

man_bck <- swow %>% 
  filter(response == "man", n_response > 1) %>% 
  arrange(desc(strength))

Exercise 4-5

Selecting variables & creating new variables

# Forward and backwards associates to the word "woman"
woman_fwd <- swow %>%
  filter(cue == "woman", n_response > 1) %>%
  select(cue, response, strength, id) %>%
  mutate(
    rank = rank(-strength),  # rank the data by strength; the minus sign indicates descending order
    type = "forward",        # this is forward associate (i.e., it's woman_FWD)
    word = "woman",          # the word is "woman" (i.e., it's WOMAN_fwd)
    associate = response     # for forward associations, the RESPONSE is the associate
  )

woman_bck <- swow %>%
  filter(response == "woman", n_response > 1)  %>%
  arrange(desc(strength)) %>%
  select(cue, response, strength, id) %>%
  mutate(
    rank = rank(-strength),  # rank the data by strength; the minus sign indicates descending order
    type = "backward",       # this is backward associate (i.e., it's woman_BCK)
    word = "woman",          # the word is "woman" (i.e., it's WOMAN_bck)
    associate = cue          # for backward associations, the CUE is the associate
  )
# Forward and backwards associates to the word "man"
man_fwd <- swow %>%
  filter(cue == "man", n_response > 1)  %>%
  select(-n_response, -n_total) # ... the minus sign means "remove"-
  mutate(
    rank = rank(-strength),     # rank the data by strength; the minus sign indicates descending order
    type = "forward",           # this is forward associate (i.e., it's man_FWD)
    word = "man",               # the word is "man" (i.e., it's MAN_fwd)
    associate = response        # for forward associations, the RESPONSE is the associate

man_bck <- swow %>%
  filter(response == "man", n_response > 1) %>%
  arrange(desc(strength)) %>%
  select(-starts_with("n_"))  # ... remove variables starting with "n_"
  mutate(
    rank = rank(-strength),   # rank the data by strength; the minus sign indicates descending order
    type = "backward",        # this is backward associate (i.e., it's man_BCK)
    word = "man",             # the word is "man" (i.e., it's MAN_bck)
    associate = cue           # for backward associations, the CUE is the associate

Exercise 6

Combining the data sets

# Creating gender
gender <- bind_rows(woman_fwd, woman_bck, man_fwd, man_bck) %>% 
  select(id:associate) %>%                        # Reducing the number of columns  
  filter(associate !="man", associate !="woman")  # Removing the 'boring' associations

Exercise 7

Create and plot gender_fwd

# Create gender_fwd
gender_fwd <- gender %>% 
  filter(
    type == "forward"
  ) %>% 
  pivot_wider(
    id_cols = associate, 
    names_from = word, 
    values_from = rank
  ) %>%
  mutate(
    woman = replace_na(1/woman, 0),
    man = replace_na(1/man, 0), 
    diff = woman - man
  )  %>%  
  arrange(diff) 
# Plot gender_fwd
picture_fwd <- ggplot(
  data = gender_fwd,
  mapping = aes(
    x = associate %>% reorder(diff), 
    y = diff
  )) + 
  geom_col() + 
  coord_flip()

plot(picture_fwd)

Create and plot gender_bck

# Create gender_bck
gender_bck <- gender %>% 
  filter(
    type == "backward"
  ) %>% 
  pivot_wider(
    id_cols = associate, 
    names_from = word, 
    values_from = rank
  ) %>%
  mutate(
    woman = replace_na(1/woman, 0),
    man = replace_na(1/man, 0), 
    diff = woman - man
  )  %>%  
  arrange(diff) 
# Plot gender_bck
picture_bck <- ggplot(
  data = gender_bck,
  mapping = aes()
    x = associate %>% reorder(diff), 
    y = diff
  )) + 
  geom_col() + 
  coord_flip()

plot(picture_bck)

It looks incredibly messy:

Using advice from slack, I decided to reduce the values on the y-axis:

# Plot gender_bck with less values on y-axis
picture_bck <- ggplot(
  data = gender_bck %>% 
    filter(diff < -0.05 | diff > 0.05), 
  mapping = aes(
    x = associate %>% reorder(diff), 
    y = diff
    ))+
  geom_col() +
  coord_flip()

plot(picture_bck)

Challenges

  • This week was definitely challenging
  • I still make silly errors here and there that make me extremely frustrated with RStudio as it prolongs the time it takes to complete each exercise
  • I still don't fully understand what's happening, particularly with the different functions and what they do.
  • Even though I can follow the instructions and reach the same outputs, I still feel unsure and less confident about my abilities to use RStudio because I do not fully understand what I'm doing

Successes

  • I managed to go through all 7 exercises even though I was only anticipating to finish about half of the exercises this week!
    • It did feel a bit rushed so I do want to go over these exercises and videos again to make sure I fully understand what is happening
  • I managed to figure out most of the mistakes I was making and fix it, without having to consult Slack or Google!

Next steps in the coding journey

  • I do want to review and possibly redo the exercises for this week, since I struggled so much with them
  • I still don't understand the functions so I do want to spend more time practising coding
  • Start playing around with the data for my group's verification report