My initial goal was to go through all the exercises in Dani’s tutorial videos and apply those lessons to other data, but I was unexpectedly overwhelmed with other work this week so I really only had time to do the exercises in the tutorial.
# Reading SWOW (inserted in global environment)
swow <- read_tsv(file = "data_swow.csv.zip")
swow <- swow %>% mutate(id = 1:n())
# Load Packages
library(tidyverse)
# Renaming variables
swow <- swow %>%
rename(R1 = n_response,
N = n_total,
R1.strength = strength)
I am not entirely sure if I did this right. I was under the impression that I was changing the variable names from the tutorial back to the original names, but I couldn’t do that by importing “data_swow.csv.zip” again. Maybe I just misunderstood the exercise, but regardless I was able to rename the variables!
library(tidyverse)
# Filtering SWOW
swow %>%
filter(response == "woman")
# Plotting SWOW woman_bck
woman_bck <- swow %>%
filter(response == "woman", n_response > 1)
I was able to filter the responses quite easily.
woman_fwd <- swow %>%
filter(cue == "woman", n_response > 1) %>%
select(cue, response, strength, id)
woman_bck <- swow %>%
filter(response == "woman", n_response > 1) %>%
arrange(desc(strength)) %>%
select(-n_response, -n_total)
man_fwd <- swow %>%
filter(cue == "man", n_response > 1) %>%
select(cue, response, strength,)
man_bck <- swow %>%
filter(response == "man", n_response > 1) %>%
arrange(desc(strength)) %>%
select(-starts_with("n_"))
While I did try to figure out how to do the exercise another way, I ultimately could not figure it out and copied and pasted a lot of code.
man_fwd <- swow %>%
filter(cue == "man", n_response > 1) %>%
select(-n_response, -n_total) %>%
mutate(rank = rank(-strength),
type = "forward",
word = "man",
associate = response)
man_bck <- swow %>%
filter(response == "man", n_response > 1) %>%
arrange(desc(strength)) %>%
select(-starts_with("n_")) %>%
mutate(rank = rank(-strength),
type = "backward",
word = "man",
associate = cue)
Again, this exercise was pretty straightforward.
For the other exercises where I just followed what Dani did, Everything was rather straight forward and I did not run into many issues. However, I did run into an issue toward the end, but I will talk about that in Challenges.
# Reading SWOW (inserted in global environment)
swow <- read_tsv(file = "data_swow.csv.zip")
swow <- swow %>% mutate(id = 1:n())
# Manual name cleaning
swow <- swow %>%
rename(n_response = R1,
n_total = N,
strength = R1.Strength)
# Filtering
swow %>%
filter(cue == "woman")
# Filter to keep a subset of the data
woman_fwd <- swow %>%
filter(cue == "woman") %>%
filter (n_response >1)
ggplot(woman_fwd) +
geom_col(aes(x = response, y = strength)) +
coord_flip()
# Creating woman_bck
woman_bck <- swow %>%
filter(response == "woman", n_response > 1)
# Data arranging
swow %>%
filter(response == "woman", n_response > 1) %>%
arrange(desc(strength))
# Forward associations for man
man_fwd <- swow %>%
filter(cue == "man", n_response >1)
# Backward associations for man
man_bck <- swow %>%
filter(response == "man", n_response >1)
# Select cue, response and strength
swow %>%
filter(response == "woman", n_response >1) %>%
arrange(desc(strength)) %>%
select(cue, response, strength)
# Mutate new variables
woman_fwd %>%
mutate(rank = rank(-strength))
woman_bck <- swow %>%
filter(response == "woman", n_response > 1) %>%
arrange(desc(strength)) %>%
select(-n_response, -n_total) %>%
mutate(rank = rank(-strength), type = "backwards")
woman_fwd <- swow %>%
filter(cue == "woman", n_response > 1) %>%
select(cue, response, strength, id) %>%
mutate(
rank = rank(-strength),
type = "forward",
word = "woman",
associate = response)
woman_bck <- swow %>%
filter(response == "woman", n_response > 1) %>%
arrange(desc(strength)) %>%
select(cue, response, strength, id) %>%
mutate(rank = rank(-strength),
type = "backward",
word = "woman",
associate = cue)
man_fwd <- swow %>%
filter(cue == "man", n_response > 1) %>%
select(-n_response, -n_total) %>%
mutate(rank = rank(-strength),
type = "forward",
word = "man",
associate = response)
man_bck <- swow %>%
filter(response == "man", n_response > 1) %>%
arrange(desc(strength)) %>%
select(-starts_with("n_")) %>%
mutate(rank = rank(-strength),
type = "backward",
word = "man",
associate = cue)
# Bind rows
gender <- bind_rows(woman_bck, woman_fwd,
man_fwd, man_bck) %>%
select(id:associate) %>%
filter(associate != "man", associate != "woman")
# Checking that bind worked
gender %>%
group_by(word, type) %>%
count()
# Pivot
gender_fwd <- gender %>%
filter(type == "forward") %>%
pivot_wider(
id_cols = associate,
names_from = word,
values_from = rank)
# Reshape data
gender_fwd <- gender %>%
mutate(
woman = replace_na(1/woman, 0),
man = replace_na(1/man, 0),
diff = woman - man) %>%
arrange(diff)
# Plotting gender_fwd
ggplot(gender_fwd) +
geom_col(mapping = aes(y = associate, x = diff))
# Create gender_bck
gender_bck <- gender %>%
mutate(
woman = replace_na(1/woman, 0),
man = replace_na(1/man, 0),
diff = woman - man) %>%
arrange(diff)
# Restoring data set
gender %>%
left_join(swow, by = "id")
While the exercises were very long, I managed to get through them. Dani’s tutorials were so easy to understand and her enthusiasm did not make it hard for me to watch all the videos.
I ran into some errors when running these lines of code:
# Create gender_bck
gender_bck <- gender %>%
mutate(
woman = replace_na(1/woman, 0),
man = replace_na(1/man, 0),
diff = woman - man) %>%
arrange(diff)
R kept saying that they could not find “object woman” even though it was there. I could not figure out why this happened, and Google wasn’t of much help either. I have been finding that when I get errors, I google the error but everyone who is asking/answering the question has really complicated code that I cannot follow.
However, for other errors I received, it was a lot of trial and error which worked about 75% of the time!
I would like to be able to do all of these functions and coding without consulting notes, and on a completely new set of data for practice. I will also look into the problems I encountered with the set of data.