This week’s goals
- Get started on Danielle’s week 3 video early this week
- Aim to finish those videos and exercises before the Thursday QnA session in case I need to ask anything
- Get started on group work for the verification report by completing set tasks and getting familiar with my group mates
My progress this week
Exercise 1: Load packages, read data, and rename variables
#load the packages
library(tidyverse)## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.1.2 v dplyr 1.0.6
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
#read in the 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()
## )
swow <- swow %>% mutate(id = 1:n())
#clean data
swow <- swow %>%
rename(n_response = R1, n_total = N, strength = R1.Strength)Exercise 2 - 3: Forward and backward associations with ‘woman’ and ‘man’
woman_fwd <- swow %>%
filter(cue == "woman", n_response >1)
woman_bck <- swow %>%
filter(response == "woman", n_response > 1) %>%
arrange(desc(strength))
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 (mutate)
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 indicates desc 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
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
)
man_fwd <- swow %>%
filter(cue == "man", n_response > 1) %>%
select(cue, response, strength, id) %>%
mutate(rank = rank(-strength),type = "foward",word = "man", associate = response)
man_bck <- swow %>%
filter(response == "man", n_response > 1) %>%
arrange(desc(strength)) %>%
select(cue, response, strength, id) %>%
mutate(rank = rank(-strength), type = "backward", word = "man", associate = cue)Exercise 6: Combining data rows
gender <- bind_rows(woman_fwd, woman_bck, man_fwd, man_bck) %>%
select(id:associate) %>%
filter(associate != "man", associate !="woman")Exercise 7: Reshaping the data (pivot) and producing the plot for 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)
pic_bck <- ggplot(data = gender_bck)+
geom_col(mapping = aes(x = associate %>% reorder(diff), y = diff))+
coord_flip()
plot(pic_bck)Okay… that looks very messy and there are so many values on the y axis, so I might to change the filter part to make the graph neater using the help from slack, hopefully it works
pic_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(pic_bck)Challenges
- This week was definitely very tough for me
- I still make many silly mistakes here and there such as forgetting the pipe symbol, commas etc that lengthened the time it took to complete each exercise
- As I progressed through the videos, I realized that I could follow the exercises and produce the same output but I wasn’t really sure of what I was really doing. Particularly with the pivot function, I just couldn’t understand it
- Finally when attempting exercise 7, I had some troubles with the final output of the graph, luckily there was help in slack which I followed successfully, but I am still a little lost with what labels on the axes were, and what diff exactly meant. This hindered me when I tried to add a title and label the axes because I simply did not know what would be the best title, and labels for the axes were.
Successes
- Nevertheless I still managed to finish the videos on time which was good
- I managed to do most of the exercises whilst fully understanding what I was doing
- I had a go at trying to fix my code using what I’d learnt before I looked online or in slack for extra help
Next steps from here
Given the difficulty of this week’s content, I will want to review the videos sometime soon to see if I can better understand things the second time round. If not, I will ask for help. I really want to make sure that I understand the pivot function as it seems like it is really important.
Particularly as I begin the verification report with my group, I want to make sure that I understand all the functions that Danielle has taught us before we go in and try to reproduce any graphs.
And finally one thing I noted when looking at Slack for help with the final exercise graph was that Jenny noted that the data could be cleaned up before creating the plot, but when I tried to do that I got an error, here’s what I tried to do:
gender_bck <- gender %>% filter(type ==“backward”) %>% filter(diff<-0.05 | diff> 0.05) %>% 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)
I would like to get some help on this sometime.
But that’s it for now :)