My Coding Goals This Week

  1. Completing and following along Danielle’s Week 3 - Data Wrangling videos.
  2. Attending Q&A and gaining more understanding on the basics of R.
  3. Installing RStudio on my laptop and start familiarising myself with it.

How I Made Progress Towards My Goals

Going Through the Exercises

Exercise 1

# load packages
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()
library(dplyr)
# import data
swow <- "data_swow.csv.zip" %>%
  read_tsv() %>%           # read the data from file
  mutate(id = 1:n()) %>%   # add the "id" column
  rename(
    n_response = R1,       # nicer name for the response count
    n_total = N,           # nicer name for the total cue presentations
    strength = R1.Strength # nicer name for the estimated response 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 & 4 & 5 (Add Mutate)

# forward associates to the word "woman"
woman_fwd <- swow %>%
  filter(cue == "woman", n_response > 1) %>% 
  select(cue, response, strength, id) %>% # select cue, response and strength
  mutate(
    rank = rank(-strength), #rank data by strength
    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 asociate
  )
# backward associates to the word "woman"
woman_bck <- swow %>%
  filter (response == "woman", n_response >1) %>%
  arrange(desc(strength)) %>%
  select(-n_response, -n_total) %>% # select cue, response and strength
  mutate(
    rank = rank(-strength),  # rank the data by strength
    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
  )

Exercise 3 & 5 (add Mutate)

# forward associates to the word "man"
man_fwd <- swow %>%
  filter (cue == "man", n_response > 1) %>%
  select(-n_response, -n_total) %>% # select cue, response and strength
  mutate(
    rank = rank(-strength),  # rank the data by strength
   type = "forward",       # this is backward associate (i.e., it's woman_BCK)
   word = "man",          # the word is "woman" (i.e., it's WOMAN_bck)
   associate = response          # for backward associations, the CUE is the associate
)
# backward associates to the word "man"
man_bck <- swow %>%
  filter (response == "man", n_response >1) %>%
  arrange (desc(strength)) %>%  
  select(-n_response, -n_total) %>% # select cue, response and strength
  mutate(
    rank = rank(-strength),  # rank the data by strength
    type = "backward",       # this is backward associate (i.e., it's woman_BCK)
    word = "man",          # the word is "woman" (i.e., it's WOMAN_bck)
    associate = cue          # for backward associations, the CUE is the associate
  )

Exercise 5 Bind variables together

gender <- bind_rows (woman_fwd, woman_bck, man_fwd, man_bck) %>% #create "gender" using bind_rows()
  select(id:associate) %>% #use select() to reduce the number of columns
  filter(associate != "man", associate != "woman") #use filter() to remove the "boring" associations

Exercise 6 Reshape/pivot data to wide form (forward associations)

gender_fwd <- gender %>% #Pivot forward associations 
  filter(type == "forward") %>% 
  pivot_wider(
    id_cols = associate,
    names_from = word,
    values_from = rank
  ) %>% 
  mutate( 
    woman = (1/woman) %>% replace_na(0), # Clean up data - replace NA with 0, and 1/(woman value)
    man = (1/man) %>% replace_na(0),
    diff = woman - man
  ) 

ggplot(
  data = gender_fwd,
) +
  geom_col(
    mapping = aes(
    y = diff,
    x = associate %>% reorder(diff)
    )
  ) +
  coord_flip()

Exercise 7 - Create and plot gender_bck

gender_bck <- gender %>% 
  filter(
    type == "backward"
    ) %>% 
  pivot_wider(
    id_cols = associate,
    names_from = word,
    values_from = rank
  ) %>% 
  mutate(
    woman = (1/woman) %>% replace_na(0),
    man = (1/man) %>% replace_na(0),
    diff = woman - man
  ) %>% 
  arrange(diff)

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)

Wins

  1. I found the Q&A really supportive and the content delivered by Jenny helped me understand how to navigate RStudio a lot more. Looking forward to continuing to attend these!
  2. Grateful for #coding and my peers on Slack for helping me figure out how to get the last plot up - I was really frustrated and annoyed by the plot I got at first which had 477 lines in them (rather than 38). 477 variables on a plot is not legible or helpful! ;)

Challenges

  1. Exercise 7 was a real challenge in terms of getting the plot to show only P<0.05 results, and took awhile (and help from #coding on Slack) to figure out!
  2. I’m still wrapping my head around all the different functions on R and how to use them appropriately. There is a lot of trial and error, and hopefully with more practice over the weeks it’ll all come together for me.

Next Steps in My Coding Journey

  1. Start to look at our data that we are going to reproduce as part of our group project.
  2. Continue practicing coding, especially making it clear what each line and section of code is doing. I think this will really help my understanding and is a good practice to have!