Load libraries
library(ggplot2)
library(dplyr)
library(langcog)
library(readr)
library(cowplot)
library(data.table)
library(magrittr)
library(lubridate)
library(tidyr)
source('~/Projects/langcog/R/multiboot.R')
na.mean <- function(x){mean(x,na.rm=T)}
pilot.data1 <- read_csv('data/pilot.data.csv')
pilot.data2 <- read_csv('data/pilot.data.2.csv')
pilot.data <- bind_rows(pilot.data1,pilot.data2) %>%
select(EndDate,Finished,ID,game_neg:game_pos,
Self_1:Self_6,liberal,repub,other_1:socialclas,race) %>%
rename(self_movies = Self_1, self_run = Self_2, self_pjs = Self_3,
self_music = Self_4, self_train = Self_5, self_games = Self_6,
other_movies = other_1, other_run = other_2, other_pjs = other_3,
other_music = other_4, other_train = other_5, other_games = other_6) %>%
rename(similar1 = `sim-1`,similar2 = `sim-2`, like1 = `like-1`,
like2 =`like-2`, poli1 = `poli-1`, poli2 = `poli-2`)
#Exclusions
pilot.data %<>%
mutate(EndDate = mdy_hm(EndDate)) %>%
arrange(ID,EndDate) %>%
distinct(ID) %>% #only the first response from each participant
filter(Finished == 1) #only complete data
Get data into tidy form
munged.data <- pilot.data %>%
mutate(other_orientation = factor(ifelse(is.na(liberal), "Conservative", "Liberal")),
other_check = factor(Mcheck, levels = c(-1,1),
labels = c("Conservative","Liberal"))) %>%
select(-liberal,-repub,-Mcheck) %>%
rowwise() %>%
mutate(movies_prime = if(nchar(Movie_neg) > 0 & nchar(Movie_pos) == 0) "Negative"
else if(nchar(Movie_pos) > 0 & nchar(Movie_neg) == 0) "Positive"
else "None",
run_prime = if(nchar(Run_neg) > 0 & nchar(Run_Pos) == 0) "Negative"
else if(nchar(Run_Pos) > 0 & nchar(Run_neg) == 0) "Positive"
else "None",
pjs_prime = if(nchar(PJ_neg) > 0 & nchar(PJ_pos) == 0) "Negative"
else if(nchar(PJ_pos) > 0 & nchar(PJ_neg) == 0) "Positive"
else "None",
music_prime = if(nchar(music_neg) > 0 & nchar(music_pos) == 0) "Negative"
else if(nchar(music_pos) > 0 & nchar(music_neg) == 0) "Positive"
else "None",
train_prime = if(nchar(train_neg) > 0 & nchar(train_pos) == 0) "Negative"
else if(nchar(train_pos) > 0 & nchar(train_neg) == 0) "Positive"
else "None",
games_prime = if(nchar(game_neg) > 0 & nchar(game_pos) == 0) "Negative"
else if(nchar(game_pos) > 0 & nchar(game_neg) == 0) "Positive"
else "None") %>%
select(ID,self_movies:poli2,other_orientation:games_prime)
# Gather primes into long format
tidy.primes <- munged.data %>%
gather(activity,prime,movies_prime:games_prime) %>%
separate(activity, c("activity", "measure")) %>%
select(ID,activity,prime,similar1:other_check)
# Gather self-ratings into long format
tidy.self <- munged.data %>%
gather(person_activity,score,self_movies:self_games) %>%
separate(person_activity, c("person", "activity")) %>%
select(ID,person,activity,score,similar1:other_check)
# Gather other-ratings into long format
tidy.other <- munged.data %>%
gather(person_activity,score,other_movies:other_games) %>%
separate(person_activity, c("person", "activity")) %>%
select(ID,person,activity,score,similar1:other_check)
tidy.self.data <- left_join(tidy.primes,tidy.self)
# Split other into similar and non-similar
tidy.other.data <- left_join(tidy.primes,tidy.other) %>%
rowwise() %>%
mutate(similar = mean(c(similar1,similar2),na.rm=T)) %>%
mutate(similarity = if(similar >= 4) "similar"
else if(similar <= 2) "dissimilar"
else "neither") %>%
filter(similarity %in% c("similar", "dissimilar")) %>%
unite(person.similar,person,similarity) %>%
rename(person = person.similar)
tidy.data <- bind_rows(tidy.self.data,tidy.other.data) %>%
mutate(person = factor(person, levels = c("self", "other_dissimilar", "other_similar"),
labels = c("self", "other-dissimilar", "other-similar")),
prime = factor(prime, levels = c("Negative", "None", "Positive"))) %>%
group_by(person,prime,activity)
Similarity scores seem low…
ggplot(aes(x = similar),data=tidy.other.data) +
geom_histogram(breaks = seq(.5,6.5,by=1),
color="white",fill="steelblue") +
scale_x_continuous(name = "Similarity Rating (1-7)",
breaks = seq(1,5),
limits = c(0,6)) +
scale_y_continuous(name = "Frequency")
Aggregate scores by activity and prime
aggregate.data <- tidy.data %>%
summarise(mean = na.mean(score)) %>%
left_join(multi_boot(tidy.data,column="score", summary_function = "na.mean",
statistics_functions = c("ci_lower","ci_upper")),
copy = TRUE)
ggplot(aes(x = activity, y = mean, color = prime), data = aggregate.data) +
facet_grid(person ~ .) +
geom_pointrange(aes(ymin = ci_lower, ymax = ci_upper),
position=position_dodge(.3),size=.75) +
scale_color_manual(values = c("steelblue", "gray", "darkred")) +
scale_y_continuous(name = "Mean Rating (1-7)")