Experiment 1 data from McManus et al. (2021) should be loaded into R: https://osf.io/kv6sw/. Additionally, analyses from that experiment should be conducted using the .Rmd file from the paper’s OSF page: https://osf.io/6mtg9/. Then, this script can be run.
options(scipen = 99) # removes scientific notation# Select E1a-b long datasets, select variables of interest, widen data, create new vars
E1ab_wide <- E1_all_long %>%
filter(BSs_cond != "CUZ vs SIB") %>% # removes dataset which compares judgments of helping family to other family
select(ResponseId,
BSs_cond, Relation, `Choice Context`,
moral) %>% # selects only relevant vars
pivot_wider(names_from = c(`Choice Context`, Relation), values_from = moral) %>% # creates dataset with four within-subj conditions per participant (similar to how data would be structured in SPSS)
mutate(NoChoice_Moral_Diff = (`No Choice_Distant` - `No Choice_Close`)) %>%
mutate(Choice_Moral_Diff = (Choice_Distant - Choice_Close)) %>% # creates person-level difference scores for each simple effect of interest
mutate(Int_Moral = (NoChoice_Moral_Diff - Choice_Moral_Diff)) # creates person-level interaction scoreE1ab_wide <- E1ab_wide %>%
mutate(`2x2_Pattern` = case_when(
(NoChoice_Moral_Diff == 0 & Choice_Moral_Diff == 0) ~ "Zero, Zero, Zero",
(NoChoice_Moral_Diff == 0 & Choice_Moral_Diff < 0) ~ "Zero, Neg, Pos",
(NoChoice_Moral_Diff == 0 & Choice_Moral_Diff > 0) ~ "Zero, Pos, Neg",
(NoChoice_Moral_Diff < 0 & Choice_Moral_Diff == 0) ~ "Neg, Zero, Neg",
(NoChoice_Moral_Diff < 0 & Choice_Moral_Diff < 0 & NoChoice_Moral_Diff == Choice_Moral_Diff) ~ "Neg, Neg, Zero",
(NoChoice_Moral_Diff < 0 & Choice_Moral_Diff > 0) ~ "Neg, Pos, Neg",
(NoChoice_Moral_Diff < 0 & Choice_Moral_Diff < 0 & NoChoice_Moral_Diff > Choice_Moral_Diff) ~ "Neg, Neg, Pos",
(NoChoice_Moral_Diff < 0 & Choice_Moral_Diff < 0 & NoChoice_Moral_Diff < Choice_Moral_Diff) ~ "Neg, Neg, Neg",
(NoChoice_Moral_Diff > 0 & Choice_Moral_Diff == 0) ~ "Pos, Zero, Pos",
(NoChoice_Moral_Diff > 0 & Choice_Moral_Diff < 0) ~ "Pos, Neg, Pos", # predicted effect
(NoChoice_Moral_Diff > 0 & Choice_Moral_Diff > 0 & NoChoice_Moral_Diff == Choice_Moral_Diff) ~ "Pos, Pos, Zero",
(NoChoice_Moral_Diff > 0 & Choice_Moral_Diff > 0 & NoChoice_Moral_Diff < Choice_Moral_Diff) ~ "Pos, Pos, Neg",
(NoChoice_Moral_Diff > 0 & Choice_Moral_Diff > 0 & NoChoice_Moral_Diff > Choice_Moral_Diff) ~ "Pos, Pos, Pos"))
# make variable a factor
E1ab_wide$`2x2_Pattern` <- as.factor(E1ab_wide$`2x2_Pattern`)print(E1a_MMY_Moral_Person <- ggplot(data = E1ab_wide %>% filter(BSs_cond == "STR vs SIB"), aes(x = `2x2_Pattern`,
fill = `2x2_Pattern`)) +
geom_bar(position = "dodge", size = 0.5) +
scale_y_continuous(labels = function(x) paste0(round(x/203*100), "%"), breaks = seq(0,101.5,20.3)) +
coord_cartesian(ylim = c(1,101.5)) +
scale_x_discrete(drop = FALSE) +
scale_fill_manual(drop = FALSE, values = c(
"lightgrey",
"azure4",
"lightgrey",
"lightgrey",
"lightgrey",
"black", # group-level pattern
"lightgrey",
"azure4",
"lightgrey",
"azure4",
"azure4",
"lightgrey",
"lightgrey"))+
theme_classic() +
theme(legend.position = "none") +
xlab("\n2x2 Direction (Simple Effects = Stranger - Sibling; Interaction = No Choice Simple - Choice Simple)") +
ylab("Perentage of Participants\n") +
theme(axis.title.x = element_text(size = 18),
axis.title.y = element_text(size = 20),
axis.text.x = element_text(color = "black", size = 13, angle = 60, vjust = 0.5, hjust=0.5),
axis.text.y = element_text(color = "black", size = 20),
strip.text.x = element_text(color = "black", size = 20),
legend.title = element_text(color = "black", size = 18),
legend.text = element_text(color = "black", size = 16)))
ggsave("E1a_MMY_Moral_Person.png")Saving 14 x 9 in image
print(E1b_MMY_Moral_Person <- ggplot(data = E1ab_wide %>% filter(BSs_cond == "STR vs CUZ"), aes(x = `2x2_Pattern`,
fill = `2x2_Pattern`)) +
geom_bar(position = "dodge", size = 0.5) +
scale_y_continuous(labels = function(x) paste0(round(x/203*100), "%"), breaks = seq(0,101.5,20.3)) +
coord_cartesian(ylim = c(1,101.5)) +
scale_x_discrete(drop = FALSE) +
scale_fill_manual(drop = FALSE, values = c(
"lightgrey",
"azure4",
"lightgrey",
"lightgrey",
"lightgrey",
"black", # group-level pattern
"lightgrey",
"azure4",
"lightgrey",
"azure4",
"azure4",
"lightgrey",
"lightgrey"))+
theme_classic() +
theme(legend.position = "none") +
xlab("\n2x2 Direction (Simple Effects = Stranger - Cousin; Interaction = No Choice Simple - Choice Simple)") +
ylab("Perentage of Participants\n") +
theme(axis.title.x = element_text(size = 18),
axis.title.y = element_text(size = 20),
axis.text.x = element_text(color = "black", size = 13, angle = 60, vjust = 0.5, hjust=0.5),
axis.text.y = element_text(color = "black", size = 20),
strip.text.x = element_text(color = "black", size = 20),
legend.title = element_text(color = "black", size = 18),
legend.text = element_text(color = "black", size = 16)))
ggsave("E1b_MMY_Moral_Person.png")Saving 14 x 9 in image
E1ab_wide %>%
group_by(BSs_cond, `2x2_Pattern`) %>%
dplyr::summarize(`2x2_pattern` = n())`summarise()` regrouping output by 'BSs_cond' (override with `.groups` argument)