Study 14 Anonymity Pilot

Author

Marcus, Dayo

Published

June 26, 2024

Setup

Libraries

Code
knitr::opts_chunk$set(warning = FALSE, message = FALSE) 

Mypackages <-
  c("lme4","tidyverse","effects","ggplot2","psych",
    "MASS","Rmisc","lmerTest","ggthemes", "knitr",
    "lsmeans","pastecs","sjstats","car","ordinal",
    "Rcpp","corrplot", "ggpubr", "EnvStats",
    "easyStats", "cowplot","see","datawizard", 
    "ggcorrplot", "lavaan")

#install.packages(Mypackages) #you must remove the # in this comment if you need to install the packages! 
lapply(Mypackages,
       require,
       character.only = TRUE)

options(knitr.kable.NA = '—')
set.seed(1)  

Load Data

Code
# read in data files
setwd("~/Desktop")
data_raw <-read.csv("/Users/temiday/Documents/Study 14 Folder/UPDATED_JTF Study 14 Anonymity.csv")

Functions

Code
plot_cooker <- function(data, iv, dv) {
  part1 <- ggplot(data, aes(x = {{iv}}, y = {{dv}}, fill = {{iv}})) +
    geom_violin(alpha = 0.3, scale = "count") + 
  stat_summary(fun = "mean", geom = "point", size = 3, color = "black") +
    stat_summary(fun.data = mean_cl_normal, geom = "errorbar", width = 0.2,
                 #change to make a data set from allEffects with mean, low CI, high CI
                 size = 1.5, color = "black") +
    theme_classic() +
    xlab("") +
    ylab("")
  ggpar(part1, legend = "none")
}
  
pol_line <- function(data, iv, dv) {
  ggplot(data, aes(x = {{iv}}, y = {{dv}}, color = condition)) +
  stat_summary(fun.data = "mean_cl_normal", geom = "line") +
  geom_point(position = position_jitter(width = 0.1, height = 0.1), alpha = 0.5) +
  labs(x = "Political Leaning", color = "Condition")
}

lizy_cooker <- function(dv, iv, Title, x_axis_labs, y_label, sample_size, coln, rown) {
  part1 <- ggviolin(gjg, x = dv, y = iv, color = dv,
                    alpha = 0.1, fill = dv, xlab = "Motive",
                    trim = TRUE, ylab = y_label) +
    stat_summary(fun.data = "mean_cl_normal", geom = "crossbar", fatten = 1) +
    scale_y_continuous(breaks = c(1:7)) +
    labs(title = paste0(Title, " (n = ", sample_size, ")")) +
    theme(panel.background = element_rect(fill = "transparent"), 
          legend.position = "right",  ## Consider “gray97” for fill
          plot.title = element_text(face = "bold", hjust = 0.5, size = 16), 
          plot.subtitle = element_text(hjust = 0.5),
          panel.grid.major.y = element_line(color='grey75'), 
          axis.text.x = element_text(face = "plain", size = 13, color = "black"),
          axis.text.y = element_text(face = "plain", size = 13, color = "black"),
          axis.title.y = element_text(face = "plain", size = 13, color = "black", 
                                       margin = margin(t = 0, r = 10, b = 0, l = 0)), ## lower X axis title
          panel.border = element_rect(color = "black", fill = NA, size = 1)) +
  scale_color_discrete(name = "Condition") +
  facet_wrap(~ vignette, ncol = coln, nrow = rown, scales = "free", as.table = TRUE)
  ggpar(part1, legend = "none")
}

#POL_gjg_long <- filter(gjg_long, political_overall %in% c("Democrat", "Republican"))
  
#gjg_long$political_overall
#ggplot(gjg_long, aes(x = condition, y = p_approve, color = condition)) +
  #geom_point(stat="summary", fun="mean", size = 2) +
  #facet_wrap(~political_overall) +
  #scale_x_discrete(labels = NULL)

Reshaping data

Code
#### filtering people who failed the attn check ####
data_raw$attn_self <- as.numeric(data_raw$attn_self)
data <- data_raw %>% filter(attn_self > 2)
# changing numeric DVs to numeric
data <- data %>% mutate_at(vars(X1_anon_public:X72_strange_private, Age), as.numeric)
class(data$X10_anonDV_private)
[1] "numeric"
Code
# changing to wide format 

#### make dataset long ###
data_long <- data %>% gather(stim, resp, "X1_anon_public":"X72_strange_private")
data_long<-data_long %>%
  separate(stim, into= c("scenario", "DV", "condition" ), sep="_")

## shift dataset back to wide format ##
data_long <- spread(data_long, DV, resp)

# replacing NA's in this column with the value 0
data_long$anon[is.na(data_long$anon)] <- 0 # the scale is from 1-7, so any zeros means the original value was an NA
data_long$anonDV[is.na(data_long$anonDV)] <- 0 # the scale is from 1-7, so any zeros means the original value was an NA

data_long <- data_long %>%
 mutate(anon = anon + anonDV) %>% # Sum columns A and B
 dplyr::select(-anonDV) # Remove column anonDV

# putting back the NA in the anon
data_long <- data_long %>% mutate(anon = ifelse(anon == 0, NA, anon))

# removing NAs (based on strange & anon column)
 data_long <- data_long %>% filter(!(is.na(strange) & is.na(anon)))
 data_long <- data_long %>% filter(scenario != "X73")

Renaming variables (scenario shorthand)

Code
data_long_scenario <- data_long # creating new data table so the below changes don't overwrite

# renaming scenarios
data_long_scenario <- data_long_scenario %>% mutate(scenario = case_when(
  scenario == "X1" ~ 'birthday gift',
  scenario == "X2" ~ 'crowded park',
  scenario == "X3" ~ 'sick colleague soup',
  scenario == "X4" ~ 'donations local charity',
  scenario == "X5" ~ 'GoFundMe Donation',
  scenario == "X6" ~ 'serving the homeless',
  scenario == "X7" ~ 'inform the police',
  scenario == "X8" ~ 'climate change petition signature',
  scenario == "X9" ~ 'reinvesting in the community',
  scenario == "X10" ~ 'defuse fight',
  scenario == "X11" ~ 'complimenting colleague',
  scenario == "X12" ~ 'holding door open',
  scenario == "X13" ~ 'helping elderly person cross street',
  scenario == "X14" ~ 'hugging someone crying',
  scenario == "X15" ~ 'rescue stray dog',
  scenario == "X16" ~ 'pushing someone out the way',
  scenario == "X17" ~ 'town hall meeting policy',
  scenario == "X18" ~ 'defending kid against bully',
  scenario == "X19" ~ 'reading at the cafe',
  scenario == "X20" ~ 'asking coworker about hobbies',
  scenario == "X21" ~ 'emphathizing with injured friends pain',
  scenario == "X22" ~ 'referee makes fair calls',
  scenario == "X23" ~ 'deceased family member',
  scenario == "X24" ~ ' referee makes fair calls',
  scenario == "X25" ~ ' lunch server gives food',
  scenario == "X26" ~ ' head coach',
  scenario == "X27" ~ ' crowded park bag',
  scenario == "X28" ~ ' birthday dinner',
  scenario == "X29" ~ 'work meeting costly mistake',
  scenario == "X30" ~ 'giving money to homeless individual',
  scenario == "X31" ~ 'staying late to help a colleague',
  scenario == "X32" ~ 'leaving 40% tip',
  scenario == "X33" ~ 'tutoring classmate',
  scenario == "X34" ~ 'writing thank you card',
  scenario == "X35" ~ 'saying thank you for services',
  scenario == "X36" ~ 'customer thanking cashier',
  scenario == "X37" ~ ' seeing someone testify',
  scenario == "X38" ~ ' telling truth about lying',
  scenario == "X39" ~ ' coworker project',
  scenario == "X40" ~ ' coworker promotion ',
  scenario == "X41" ~ ' perfect score' ,
  scenario == "X42" ~ ' trips and laughs ',
  scenario == "X43" ~ ' football game bet',
  scenario == "X44" ~ ' concert with friends ',
  scenario == "X45" ~ ' bribed testimony ',
  scenario == "X46" ~ ' coworker smile ',
  scenario == "X47" ~ ' teacher compliment ',
  scenario == "X48" ~ ' helping elderly carrying groceries',
  scenario == "X49" ~ ' cafe love letter',
  scenario == "X50" ~ 'kiss partner at party ',
  scenario == "X51" ~ ' romantic dinner',
  scenario == "X52" ~ 'in a relationship ',
  scenario == "X53" ~ 'staying at the company ',
  scenario == "X54" ~ 'small business regular ',
  scenario == "X55" ~ 'uber airport ',
  scenario == "X56" ~ ' 3 hour wait at concert ',
  scenario == "X57" ~ ' 30 minute wait at dinner ',
  scenario == "X58" ~ ' four mile run ',
  scenario == "X59" ~ ' graduate school exam ',
  scenario == "X60" ~ ' new personal record ',
  scenario == "X61" ~ ' church with friends',
  scenario == "X62" ~ 'protesting a social issue ',
  scenario == "X63" ~ 'save lives',
  scenario == "X64" ~ 'social distancing',
  scenario == "X65" ~ 'paying full attention ',
  scenario == "X66" ~ 'raise your hand ',
  scenario == "X67" ~ ' partner chores',
  scenario == "X68" ~ ' dog poop',
  scenario == "X69" ~ ' paying bills',
  scenario == "X70" ~ ' two people arguing',
  scenario == "X71" ~ 'train station bag ',
  scenario == "X72" ~ ' captain team meeting ',
  TRUE ~ scenario
))

Renaming variables (virtue shorthand)

Code
data_long_virtue <- data_long # creating new data table so the above changes don't overwrite

# renaming scenarios
data_long_virtue <- data_long_virtue %>% mutate(scenario = case_when(
  scenario == "X1" ~ 'care1',
  scenario == "X2" ~ 'care 2',
  scenario == "X3" ~ 'care 3',
  scenario == "X4" ~ 'charity1',
  scenario == "X5" ~ 'charity2',
  scenario == "X6" ~ 'charity3',
  scenario == "X7" ~ 'citzenship1',
  scenario == "X8" ~ 'citzenship2',
  scenario == "X9" ~ 'citzenship3',
  scenario == "X10" ~ 'civility1',
  scenario == "X11" ~ 'civility2',
  scenario == "X12" ~ 'civility3',
  scenario == "X13" ~ 'compassionate1',
  scenario == "X14" ~ 'compassionate2',
  scenario == "X15" ~ 'compassionate3',
  scenario == "X16" ~ 'courage1',
  scenario == "X17" ~ 'courage2',
  scenario == "X18" ~ 'courage3',
  scenario == "X19" ~ 'curiosity1',
  scenario == "X20" ~ 'curiosity2',
  scenario == "X21" ~ 'empathy1',
  scenario == "X22" ~ 'empathy2',
  scenario == "X23" ~ 'empathy3',
  scenario == "X24" ~ 'fairness1',
  scenario == "X25" ~ 'fairness2',
  scenario == "X26" ~ 'fairness3',
  scenario == "X27" ~ 'forgivness1',
  scenario == "X28" ~ 'forgivness2',
  scenario == "X29" ~ 'forgivness3',
  scenario == "X30" ~ 'generosity1',
  scenario == "X31" ~ 'generosity2',
  scenario == "X32" ~ 'generosity3',
  scenario == "X33" ~ 'generosity4',
  scenario == "X34" ~ 'gratitude1',
  scenario == "X35" ~ 'gratitude2',
  scenario == "X36" ~ 'gratitude3',
  scenario == "X37" ~ 'honesty1',
  scenario == "X38" ~ 'honesty2',
  scenario == "X39" ~ 'honesty3',
  scenario == "X40" ~ 'humility1',
  scenario == "X41" ~ 'humility2',
  scenario == "X42" ~ 'humility3',
  scenario == "X43" ~ 'integrity1 ',
  scenario == "X44" ~ 'integrity2 ',
  scenario == "X45" ~ 'integrity3 ',
  scenario == "X46" ~ 'kindness1',
  scenario == "X47" ~ 'kindness2 ',
  scenario == "X48" ~ 'kindness3',
  scenario == "X49" ~ 'love1',
  scenario == "X50" ~ 'love2',
  scenario == "X51" ~ 'love3',
  scenario == "X52" ~ 'loyalty1',
  scenario == "X53" ~ 'loyalty2',
  scenario == "X54" ~ 'loyalty3',
  scenario == "X55" ~ 'patience1',
  scenario == "X56" ~ 'patience 2',
  scenario == "X57" ~ 'patience 3',
  scenario == "X58" ~ 'perseverance1',
  scenario == "X59" ~ ' perseverance2',
  scenario == "X60" ~ 'perseverance3',
  scenario == "X61" ~ 'purpose1',
  scenario == "X62" ~ ' purpose2',
  scenario == "X63" ~ 'purpose3',
  scenario == "X64" ~ 'respect1',
  scenario == "X65" ~ 'respect2',
  scenario == "X66" ~ 'respect3',
  scenario == "X67" ~ 'responsibility1 ',
  scenario == "X68" ~ 'responsibility2 ',
  scenario == "X69" ~ 'responsibility3 ',
  scenario == "X70" ~ 'self-control1 ',
  scenario == "X71" ~ 'trustworthiness1 ',
  scenario == "X72" ~ 'trustworthiness2 ',
  
  TRUE ~ scenario
))

splitting data

Code
data_public_scenario <-  data_long_scenario %>% dplyr::filter(data_long_scenario$condition == "public")
data_private_scenario <-  data_long_scenario %>% dplyr::filter(data_long_scenario$condition == "private") 
data_public_virtue <-  data_long_virtue %>% dplyr::filter(data_long_virtue$condition == "public")
data_private_virtue <-  data_long_virtue %>% dplyr::filter(data_long_virtue$condition == "private") 

public scenario plot

Code
ggplot(data_public_scenario, aes(x = anon, y = reorder(scenario, -anon, decreasing = TRUE))) +
 stat_summary(fun = mean, geom = "bar") + labs(x = "1=private, 7=public", y = "Scenario", title = "How Public are Public Scenarios (N = 30)") + coord_cartesian(xlim = c(1, 7)) + scale_x_continuous(breaks = c(1,2,3,4,5,6,7)) + theme(
    plot.title = element_text(hjust = 0.5, size = 30),
    axis.text.x = element_text(face = "plain", size = 20, color = "black"),
    axis.text.y = element_text(face = "plain", size = 20, color = "black"),
    axis.title.y = element_text(face = "plain", size = 20, color = "black"),
    axis.title.x = element_text(face = "plain", size = 20, color = "black"))

public virtue plot

Code
ggplot(data_public_scenario, aes(x = anon, y = reorder(scenario, -anon, decreasing = TRUE))) +
 stat_summary(fun = mean, geom = "bar") + labs(x = "1=private, 7=public", y = "Scenario", title = "How Public are Public Scenarios (N = 30)") + coord_cartesian(xlim = c(1, 7)) + scale_x_continuous(breaks = c(1,2,3,4,5,6,7)) + theme(
    plot.title = element_text(hjust = 0.5, size = 30),
    axis.text.x = element_text(face = "plain", size = 20, color = "black"),
    axis.text.y = element_text(face = "plain", size = 20, color = "black"),
    axis.title.y = element_text(face = "plain", size = 20, color = "black"),
    axis.title.x = element_text(face = "plain", size = 20, color = "black"))

private scenario plot

Code
ggplot(data_private_scenario, aes(x = anon, y = reorder(scenario, -anon, decreasing = FALSE))) +
 stat_summary(fun = mean, geom = "bar") + labs(x = "1=private, 7=public", y = "Scenario", title = "How Private are Private Scenarios (N = 30)") + coord_cartesian(xlim = c(1, 7)) + scale_x_continuous(breaks = c(1,2,3,4,5,6,7))  + theme(
    plot.title = element_text(hjust = 0.5, size = 30),
    axis.text.x = element_text(face = "plain", size = 20, color = "black"),
    axis.text.y = element_text(face = "plain", size = 20, color = "black"),
    axis.title.y = element_text(face = "plain", size = 20, color = "black"),
    axis.title.x = element_text(face = "plain", size = 20, color = "black"))

private virtues plot

Code
ggplot(data_private_virtue, aes(x = anon, y = reorder(scenario, -anon, decreasing = FALSE))) +
 stat_summary(fun = mean, geom = "bar") + labs(x = "1=private, 7=public", y = "Scenario", title = "How Private are Private Scenarios (N = 30)") + coord_cartesian(xlim = c(1, 7)) + scale_x_continuous(breaks = c(1,2,3,4,5,6,7)) + theme(
    plot.title = element_text(hjust = 0.5, size = 30),
    axis.text.x = element_text(face = "plain", size = 20, color = "black"),
    axis.text.y = element_text(face = "plain", size = 20, color = "black"),
    axis.title.y = element_text(face = "plain", size = 20, color = "black"),
    axis.title.x = element_text(face = "plain", size = 20, color = "black"))

public scenario strange plot

Code
ggplot(data_public_scenario , aes(x = strange, y = reorder(scenario, -strange, decreasing = TRUE))) +
 stat_summary(fun = mean, geom = "bar") + labs(x = "1=strange, 7=normal", y = "Scenario", title = "How Normal are the Scenarios (N = 30)") + coord_cartesian(xlim = c(1, 7)) + scale_x_continuous(breaks = c(1,2,3,4,5,6,7)) + theme(
    plot.title = element_text(hjust = 0.5, size = 30),
    axis.text.x = element_text(face = "plain", size = 20, color = "black"),
    axis.text.y = element_text(face = "plain", size = 20, color = "black"),
    axis.title.y = element_text(face = "plain", size = 20, color = "black"),
    axis.title.x = element_text(face = "plain", size = 20, color = "black"))

private scenario strange plot

Code
ggplot(data_private_scenario, aes(x = strange, y = reorder(scenario, -strange, decreasing = TRUE))) +
 stat_summary(fun = mean, geom = "bar") + labs(x = "1=strange, 7=public", y = "virtue", title = "How Normal are Private Scenarios   (N = 30)") + coord_cartesian(xlim = c(1, 7)) + scale_x_continuous(breaks = c(1,2,3,4,5,6,7)) + theme(
    plot.title = element_text(hjust = 0.5, size = 30),
    axis.text.x = element_text(face = "plain", size = 20, color = "black"),
    axis.text.y = element_text(face = "plain", size = 20, color = "black"),
    axis.title.y = element_text(face = "plain", size = 20, color = "black"),
    axis.title.x = element_text(face = "plain", size = 20, color = "black"))

public virtue scenario plot

Code
ggplot(data_public_virtue, aes(x = strange, y = reorder(scenario, -strange, 
decreasing = TRUE))) +
 stat_summary(fun = mean, geom = "bar") + labs(x = "1=strange, 7=public", y = "virtue", title = "How Normal are Public virtue Scenarios   (N = 30)") + coord_cartesian(xlim = c(1, 7)) + scale_x_continuous(breaks = c(1,2,3,4,5,6,7)) + theme(
    plot.title = element_text(hjust = 0.5, size = 30),
    axis.text.x = element_text(face = "plain", size = 20, color = "black"),
    axis.text.y = element_text(face = "plain", size = 20, color = "black"),
    axis.title.y = element_text(face = "plain", size = 20, color = "black"),
    axis.title.x = element_text(face = "plain", size = 20, color = "black"))

#private virtue scenario plot

Code
ggplot(data_private_virtue, aes(x = strange, y = reorder(scenario, -strange, decreasing = TRUE))) +
 stat_summary(fun = mean, geom = "bar") + labs(x = "1=strange, 7=public", y = "virtue", title = "How normal are private virtue Scenarios   (N = 30)") + coord_cartesian(xlim = c(1, 7)) + scale_x_continuous(breaks = c(1,2,3,4,5,6,7)) + theme(
    plot.title = element_text(hjust = 0.5, size = 30),
    axis.text.x = element_text(face = "plain", size = 20, color = "black"),
    axis.text.y = element_text(face = "plain", size = 20, color = "black"),
    axis.title.y = element_text(face = "plain", size = 20, color = "black"),
    axis.title.x = element_text(face = "plain", size = 20, color = "black"))