Coding goals for this week:

This week, my coding goals were to FINALLY finish Dani’s modules on data wrangling, as well as have a meeting with my group to get started on our assignment!!

Thankfully, these goals were achieved! By finishing the modules, I learned how to filter so that I could keep a subset of data, how to arrange data, how to select specific variables in a data set, how to use the mutate function to compute new variables, as well as how to stack data sets vertically by using the bind function.

My group and I also met on Thursday morning to start on our assignment and it was a great success! Everyone worked and communicated really well, so we were able to make good progress. Since there are four studies in our COVID paper, we were assigned a study each (with two of us working on the study 4, which was the biggest one) we started off by opening our assigned data sets and translating the variable names from German to English (since none of us can speak German XD). I found translating my study alone very time-consuming, so I was very glad that we did all the translating as a group. We also worked on reproducing the descriptive statistics, such as the mean and standard deviation, as well as the demographics for each study. So overall, I am very happy with the progress that my group is making so far, and I genuinely feel like everyone is pulling their weight.

Successes and challenges:

This week, I thought that I would make things a bit easier for myself by adding comments to my code as I do the exercises so that when I look over my learning logs throughout the term, I can actually remember what I did and how I did it. I will aim to add comments to my previous learning logs as well, but this will probably be much easier said than done!

Believe it or not, there weren’t too many challenges for me this week (believe it or not) because Dani made her modules so straightforward and Jennifer has been super helpful through the Q and A’s and the coding channel. One challenge I did have though was when I tried to use the filter function for the cases that responded with “woman”, it kept coming up with an error.

Luckily, I figured out that I wrote filter(cue = “woman”) instead of filter(cue == “woman”), so in future I need to remember that I need to use two “=” signs when I use the filter function.

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.2.1     ✓ purrr   0.3.3
## ✓ tibble  2.1.3     ✓ dplyr   0.8.4
## ✓ tidyr   1.0.2     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.5.0
## ── Conflicts ────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(janitor)
## 
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
swow <- read_tsv(file = 'data_swow.csv.zip') # Using read_tsv() to import the swow data into a data frame called "swow"
## Multiple files in zip: reading 'swow.csv'
## Parsed with column specification:
## cols(
##   cue = col_character(),
##   response = col_character(),
##   R1 = col_double(),
##   N = col_double(),
##   R1.Strength = col_double()
## )
swow %>%
  mutate(id = 1:n()) %>% # adding the id column (the "mystery" line)
  clean_names-> swow # automated name cleaning (since I was too lazy to do the name cleaning manually)

swow <- swow[,c(6,1:5)] # reordering id column to position 1 
swow %>% # was able to successfully use a pipe YAY!! I wanted to practise using these more, so I'm glad I got a chance to do it this week!
  rename(n_response = r1,
  n_total = n,
  strength = r1_strength) -> swow # Using rename() to get new variable names:
swow %>%
  filter(cue == "woman")
## # A tibble: 28 x 6
##        id cue   response n_response n_total strength
##     <int> <chr> <chr>         <dbl>   <dbl>    <dbl>
##  1 477315 woman man              38     100     0.38
##  2 477316 woman female           22     100     0.22
##  3 477317 woman girl              7     100     0.07
##  4 477318 woman lady              5     100     0.05
##  5 477319 woman beauty            2     100     0.02
##  6 477320 woman me                2     100     0.02
##  7 477321 woman strong            2     100     0.02
##  8 477322 woman wife              2     100     0.02
##  9 477323 woman adult             1     100     0.01
## 10 477324 woman birth             1     100     0.01
## # … with 18 more rows
woman_fwd <-swow %>%
  filter(cue == "woman") %>% filter(n_response > 1) # Extracting the cases with women only. NOTE must write the code as filter(cue == "woman", not filter(cue = "woman"))

ggplot(woman_fwd) +
  geom_col(aes(x = response, y = strength)) + coord_flip() # Creating a graph of this subset of data using ggplot

# Arranging the backward data by descending strength to make it neater
woman_bck <- swow %>%
  filter(response == "woman", n_response > 1) %>%
  arrange(desc(strength)) %>%
  select(cue, response, strength)
# Arranging forward data by descending strength for when "man" is the response
man_fwd <- swow %>%
  filter(cue == "man", n_response > 1) %>%
  select(cue, response, strength, id) %>%
  mutate( # ex5
    rank = rank(-strength), 
    type = "forward",       
    word = "man",           
    associate = response    
  )

# Doing the same for the forward data for cases where "Man" is the 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        
  )
man_bck %>% 
  ggplot(aes(x=rank, y=strength)) + geom_point() # Creating a graph of the "Man" subset of data using ggplot

gender <- bind_rows(woman_fwd, woman_bck, 
  man_fwd, man_bck) %>% # Binding the rows so that data sets stack vertically
  select(id:associate) %>% # Cleaning up the data
  filter(associate != 'man', associate != 'woman') # NOTE: to create =/= (in the slides), write "!="

gender %>%
  group_by(word,type) %>%
  count() # Checking that code written above worked
## # A tibble: 2 x 3
## # Groups:   word, type [2]
##   word  type         n
##   <chr> <chr>    <int>
## 1 man   backward   288
## 2 man   forward      7

Next steps in my coding journey:

My next steps will be to go over my previous learning logs and add comments to my lines of code (as I mentioned above). I will also continue to work on my contribution to the group assignment, and will include more details about that in my learning log for next week. Overall, I am happy with how my coding journey is progressing so far - I feel like I have come quite a long way since week 1 - and I am looking forward to meeting up more with my group! :D