---
title: "Generosity vs Justice V8"
author: 'Marcus + Lizy + Nadia'
date: "9/6/2023"
format:
html:
code-fold: true
code-tools: true
fontsize: 16px
self-contained: true
toc: true
toc-location: left
output:
html_document:
code_folding: hide
number_sections: true
toc: true
toc_float: true
toc_collapsed: true
toc_depth: 3
keep_md: true
header-includes:
- \usepackage{Roboto Condensed}
knitr:
opts_chunk:
dev: ragg_png
execute:
warning: false
---
# Overview and Methodology
- Study of third party judgments of donors motivated by a justice or generosity virtue when the information is shared either from a third person perspective
- Data collected September 22, 2023
- N = 300
# Setup {.tabset .tabset-pills}
## Libraries and functions {.unlisted .unnumbered}
```{r setup, message=F, results='hide', warning=FALSE}
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" ,
"RColorBrewer" , "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
```{r, message=F, results='hide', warning=FALSE}
gjg_raw <- read.csv ("/Users/mtrenfield17/Desktop/Research/Boston College Research/Morality Lab Research/Generosity Vs Justice Project/just_vs_gen_v8/Generosity vs Justice V8.csv" )
```
## Reshaping data
```{r}
gjg <- gjg_raw %>%
filter (consent == 5 , attn_bucket_num == 1 , Finished == 1 , attn_self >= 3 )
# Explanation:
# filter() function is used to filter rows based on specified conditions.
# Rows are kept where consent is 5, attn_bucket_num is 1, Finished is 1, and attn_self is 3 or greater.
# changing appropriate DVs to numeric
cols_to_convert <- c ("Age" , "Income" , "SES" , "Political_overall" , "Political_social" , "Political_economic" , "attn_self" , "PID" ,
"Religiosity" , "Education" )
gjg[cols_to_convert] <- lapply (gjg[cols_to_convert], as.numeric)
gjg <- gjg %>%
mutate (
norm_signal_just = ifelse (vigFirstVirtue == "justice" , norm_signal_10,
ifelse (vigFirstVirtue == "generosity" , norm_signal_11, NA )),
norm_signal_gen = ifelse (vigFirstVirtue == "generosity" , norm_signal_10,
ifelse (vigFirstVirtue == "justice" , norm_signal_11, NA ))
)
gjg <- gjg %>%
mutate (
reputation_signal_just = ifelse (vigFirstVirtue == "justice" , reputation_signal_1,
ifelse (vigFirstVirtue == "generosity" , reputation_signal_2, NA )),
reputation_signal_gen = ifelse (vigFirstVirtue == "generosity" , reputation_signal_1,
ifelse (vigFirstVirtue == "justice" , reputation_signal_2, NA ))
)
gjg <- gjg %>%
mutate (
approval_just = ifelse (vigFirstVirtue == "justice" , approval_1,
ifelse (vigFirstVirtue == "generosity" , approval_2, NA )),
approval_gen = ifelse (vigFirstVirtue == "generosity" , approval_1,
ifelse (vigFirstVirtue == "justice" , approval_2, NA ))
)
gjg <- gjg %>%
mutate (
moral_just = ifelse (vigFirstVirtue == "justice" , moral_1,
ifelse (vigFirstVirtue == "generosity" , moral_2, NA )),
moral_gen = ifelse (vigFirstVirtue == "generosity" , moral_1,
ifelse (vigFirstVirtue == "justice" , moral_2, NA ))
)
gjg <- gjg %>%
mutate (
genuine_just = ifelse (vigFirstVirtue == "justice" , genuine_1,
ifelse (vigFirstVirtue == "generosity" , genuine_2, NA )),
genuine_gen = ifelse (vigFirstVirtue == "generosity" , genuine_1,
ifelse (vigFirstVirtue == "justice" , genuine_2, NA ))
)
gjg <- gjg %>%
mutate (
deliberate_just = ifelse (vigFirstVirtue == "justice" , deliberate_1,
ifelse (vigFirstVirtue == "generosity" , deliberate_2, NA )),
deliberate_gen = ifelse (vigFirstVirtue == "generosity" , deliberate_1,
ifelse (vigFirstVirtue == "justice" , deliberate_2, NA ))
)
gjg <- gjg %>%
mutate (
spontaneous_just = ifelse (vigFirstVirtue == "justice" , spontaneous_1,
ifelse (vigFirstVirtue == "generosity" , spontaneous_2, NA )),
spontaneous_gen = ifelse (vigFirstVirtue == "generosity" , spontaneous_1,
ifelse (vigFirstVirtue == "justice" , spontaneous_2, NA ))
)
gjg <- gjg %>%
mutate (
emotion_just = ifelse (vigFirstVirtue == "justice" , emotion_1,
ifelse (vigFirstVirtue == "generosity" , emotion_2, NA )),
emotion_gen = ifelse (vigFirstVirtue == "generosity" , emotion_1,
ifelse (vigFirstVirtue == "justice" , emotion_2, NA ))
)
gjg <- gjg %>%
mutate (
logic_just = ifelse (vigFirstVirtue == "justice" , logic_1,
ifelse (vigFirstVirtue == "generosity" , logic_2, NA )),
logic_gen = ifelse (vigFirstVirtue == "generosity" , logic_1,
ifelse (vigFirstVirtue == "justice" , logic_2, NA ))
)
gjg <- gjg %>%
mutate (
quick_just = ifelse (vigFirstVirtue == "justice" , quick_1,
ifelse (vigFirstVirtue == "generosity" , quick_2, NA )),
quick_gen = ifelse (vigFirstVirtue == "generosity" , quick_1,
ifelse (vigFirstVirtue == "justice" , quick_2, NA ))
)
gjg <- gjg %>%
mutate (
slow_just = ifelse (vigFirstVirtue == "justice" , slow_1,
ifelse (vigFirstVirtue == "generosity" , slow_2, NA )),
slow_gen = ifelse (vigFirstVirtue == "generosity" , slow_1,
ifelse (vigFirstVirtue == "justice" , slow_2, NA ))
)
gjg <- gjg %>%
mutate (
warm_just = ifelse (vigFirstVirtue == "justice" , warm_1,
ifelse (vigFirstVirtue == "generosity" , warm_2, NA )),
warm_gen = ifelse (vigFirstVirtue == "generosity" , warm_1,
ifelse (vigFirstVirtue == "justice" , warm_2, NA ))
)
gjg <- gjg %>%
mutate (
good_natured_just = ifelse (vigFirstVirtue == "justice" , good.natured_1,
ifelse (vigFirstVirtue == "generosity" , good.natured_2, NA )),
good_natured_gen = ifelse (vigFirstVirtue == "generosity" , good.natured_1,
ifelse (vigFirstVirtue == "justice" , good.natured_2, NA ))
)
gjg <- gjg %>%
mutate (
tolerant_just = ifelse (vigFirstVirtue == "justice" , tolerant_1,
ifelse (vigFirstVirtue == "generosity" , tolerant_2, NA )),
tolerant_gen = ifelse (vigFirstVirtue == "generosity" , tolerant_1,
ifelse (vigFirstVirtue == "justice" , tolerant_2, NA ))
)
gjg <- gjg %>%
mutate (
sincere_just = ifelse (vigFirstVirtue == "justice" , sincere_1,
ifelse (vigFirstVirtue == "generosity" , sincere_2, NA )),
sincere_gen = ifelse (vigFirstVirtue == "generosity" , sincere_1,
ifelse (vigFirstVirtue == "justice" , sincere_2, NA ))
)
gjg <- gjg %>%
mutate (
competent_just = ifelse (vigFirstVirtue == "justice" , competent_1,
ifelse (vigFirstVirtue == "generosity" , competent_2, NA )),
competent_gen = ifelse (vigFirstVirtue == "generosity" , competent_1,
ifelse (vigFirstVirtue == "justice" , competent_2, NA ))
)
gjg <- gjg %>%
mutate (
confident_just = ifelse (vigFirstVirtue == "justice" , confident_1,
ifelse (vigFirstVirtue == "generosity" , confident_2, NA )),
confident_gen = ifelse (vigFirstVirtue == "generosity" , confident_1,
ifelse (vigFirstVirtue == "justice" , confident_2, NA ))
)
gjg <- gjg %>%
mutate (
independent_just = ifelse (vigFirstVirtue == "justice" , independent_1,
ifelse (vigFirstVirtue == "generosity" , independent_2, NA )),
independent_gen = ifelse (vigFirstVirtue == "generosity" , independent_1,
ifelse (vigFirstVirtue == "justice" , independent_2, NA ))
)
gjg <- gjg %>%
mutate (
competitive_just = ifelse (vigFirstVirtue == "justice" , competitive_1,
ifelse (vigFirstVirtue == "generosity" , competitive_2, NA )),
competitive_gen = ifelse (vigFirstVirtue == "generosity" , competitive_1,
ifelse (vigFirstVirtue == "justice" , competitive_2, NA ))
)
gjg <- gjg %>%
mutate (
intelligent_just = ifelse (vigFirstVirtue == "justice" , intelligent_1,
ifelse (vigFirstVirtue == "generosity" , intelligent_2, NA )),
intelligent_gen = ifelse (vigFirstVirtue == "generosity" , intelligent_1,
ifelse (vigFirstVirtue == "justice" , intelligent_2, NA ))
)
gjg <- gjg %>%
mutate (
politics_just = ifelse (vigFirstVirtue == "justice" , politics_1,
ifelse (vigFirstVirtue == "generosity" , politics_2, NA )),
politics_gen = ifelse (vigFirstVirtue == "generosity" , politics_1,
ifelse (vigFirstVirtue == "justice" , politics_2, NA ))
)
gjg <- gjg %>%
mutate (
first_text = ifelse (grepl ("Value" , vigOrder, ignore.case = TRUE ), "value" ,
ifelse (grepl ("Commit" , vigOrder, ignore.case = TRUE ), "commit" , NA ))
)
```
# Attention check
```{r,message=F, results='hide', warning=FALSE}
# filtering out failures/nonresponses to attention checks
length (gjg_raw$ PID)
gjg_raw_filter <- gjg_raw %>%
filter (consent == 5 )
length (gjg_raw_filter$ PID)
gjg_raw_filter <- gjg_raw_filter %>%
filter (! is.na (attn_bucket), attn_self> 2 , attn_bucket_num == 1 )
length (gjg_raw_filter$ PID)
```
1 participants failed the bot check.
# Demographics
```{r,message=F, results='hide', warning=FALSE}
# Analyzing numeric variables
# Specify the variables you want to include in the table
vars_to_include <- c ("Age" , "Income" , "Education" , "SES" , "Political_overall" , "Political_social" , "Political_economic" , "Religiosity" )
# Create an empty data frame to store the summary
summary_table <- data.frame (Variable = character (0 ),
Mean = numeric (0 ),
Median = numeric (0 ),
Min = numeric (0 ),
Max = numeric (0 ),
N = numeric (0 ))
# Loop through each variable and calculate summary statistics
for (var in vars_to_include) {
summary_stats <- summary (gjg[[var]])
var_data <- data.frame (Variable = var,
Mean = mean (gjg[[var]], na.rm = TRUE ),
Median = median (gjg[[var]], na.rm = TRUE ),
Min = min (gjg[[var]], na.rm = TRUE ),
Max = max (gjg[[var]], na.rm = TRUE ),
N = length (gjg[[var]]))
summary_table <- rbind (summary_table, var_data)
}
# Print the summary table
print (summary_table)
# Analyzing categorical demos
# Subset your data frame to include only the demographic columns
demo_gjg <- gjg[, c ("Gender_TEXT" , "Race_Ethnicity_TEXT" , "Income_TEXT" , "Education_TEXT" , "Political_party_TEXT" )]
# Loop through each demographic column and calculate frequency counts
freq_tables <- list ()
for (col in names (demo_gjg)) {
{
freq_table <- as.data.frame (table (demo_gjg[[col]]))
freq_table$ Percent <- round (freq_table$ Freq / sum (freq_table$ Freq) * 100 , 2 )
freq_tables[[col]] <- freq_table
}
}
# Print the frequency tables
for (i in seq_along (freq_tables)) {
if (! is.null (freq_tables[[i]])) {
cat (" \n Table of frequencies for" , names (freq_tables)[i], ": \n " )
print (freq_tables[[i]])
}
}
```
# Correlation
```{r fig.dim = c(12, 10)}
cols_to_convert <- c ("reputation_signal_just" , "reputation_signal_gen" , "norm_signal_just" , "norm_signal_gen" , "approval_just" , "approval_gen" , "moral_just" , "moral_gen" , "genuine_just" , "genuine_gen" , "deliberate_just" , "deliberate_gen" , "spontaneous_just" , "spontaneous_gen" , "emotion_just" , "emotion_gen" , "logic_just" , "logic_gen" , "quick_just" , "quick_gen" , "slow_just" , "slow_gen" , "warm_just" , "warm_gen" , "good_natured_just" , "good_natured_gen" , "tolerant_just" , "tolerant_gen" , "sincere_just" , "sincere_gen" , "competent_just" , "competent_gen" , "confident_just" , "confident_gen" , "independent_just" , "independent_gen" , "competitive_just" , "competitive_gen" , "intelligent_just" , "intelligent_gen" , "politics_just" , "politics_gen" , "Age" , "SES" , "Political_overall" , "Political_social" , "Political_economic" )
gjg[cols_to_convert] <- lapply (gjg[cols_to_convert], as.numeric)
DVs <- gjg[c ("reputation_signal_just" , "reputation_signal_gen" , "norm_signal_just" , "norm_signal_gen" , "approval_just" , "approval_gen" , "moral_just" , "moral_gen" , "genuine_just" , "genuine_gen" , "deliberate_just" , "deliberate_gen" , "spontaneous_just" , "spontaneous_gen" , "emotion_just" , "emotion_gen" , "logic_just" , "logic_gen" , "quick_just" , "quick_gen" , "slow_just" , "slow_gen" , "warm_just" , "warm_gen" , "good_natured_just" , "good_natured_gen" , "tolerant_just" , "tolerant_gen" , "sincere_just" , "sincere_gen" , "competent_just" , "competent_gen" , "confident_just" , "confident_gen" , "independent_just" , "independent_gen" , "competitive_just" , "competitive_gen" , "intelligent_just" , "intelligent_gen" , "politics_just" , "politics_gen" , "Age" , "SES" , "Political_overall" , "Political_social" , "Political_economic" )]
# Compute pairwise correlations
corr_DVs <- cor (DVs, use = "pairwise.complete.obs" )
# Plot the correlation matrix
corrplot (corr_DVs, is.corr = TRUE , type = "lower" , lower = "circle" , tl.cex = 0.7 , insig = "label_sig" , diag = TRUE )
# New columns for composite of warmth and competence, moral goodness
gjg <- gjg %>%
mutate (warmth_just= (warm_just+ good_natured_just+ tolerant_just+ sincere_just)/ 4 )%>%
mutate (warmth_gen= (warm_gen+ good_natured_gen+ tolerant_gen+ sincere_gen)/ 4 )%>%
mutate (competence_just= (competent_just+ confident_just+ independent_just+ competitive_just+
intelligent_just)/ 5 )%>%
mutate (competence_gen= (competent_gen+ confident_gen+ independent_gen+ competitive_gen+
intelligent_gen)/ 5 ) %>%
mutate (moralGoodness_just= (approval_just+ moral_just+ genuine_just)/ 3 )%>%
mutate (moralGoodness_gen= (approval_gen+ moral_gen+ genuine_gen)/ 3 ) %>%
mutate (decisionSpeed_just= (quick_just+ spontaneous_just)/ 2 )%>%
mutate (decisionSpeed_gen= (quick_gen+ spontaneous_gen)/ 2 )
# DVs 2
DVs_2 <- gjg[c ("reputation_signal_just" , "reputation_signal_gen" , "norm_signal_just" , "norm_signal_gen" , "approval_just" , "approval_gen" , "moral_just" , "moral_gen" , "genuine_just" , "genuine_gen" , "deliberate_just" , "deliberate_gen" , "spontaneous_just" , "spontaneous_gen" , "emotion_just" , "emotion_gen" , "logic_just" , "logic_gen" , "quick_just" , "quick_gen" , "slow_just" , "slow_gen" , "warmth_just" , "warmth_gen" , "competence_just" , "competence_gen" , "moralGoodness_just" , "moralGoodness_gen" , "decisionSpeed_just" , "decisionSpeed_gen" , "politics_just" , "politics_gen" , "Age" , "SES" , "Political_overall" , "Political_social" , "Political_economic" )]
# Compute pairwise correlations
corr_DVs_2 <- cor (DVs_2, use = "pairwise.complete.obs" )
# Plot the correlation matrix
corrplot (corr_DVs_2, is.corr = TRUE , type = "lower" , lower = "circle" , tl.cex = 0.7 , insig = "label_sig" , diag = TRUE )
# DVs just
DVs_just <- gjg[c ("reputation_signal_just" , "norm_signal_just" , "approval_just" , "moral_just" , "genuine_just" , "deliberate_just" , "spontaneous_just" , "emotion_just" , "logic_just" , "quick_just" , "slow_just" , "warmth_just" , "competence_just" , "politics_just" , "Age" , "SES" , "Political_overall" , "Political_social" , "Political_economic" )]
# Compute pairwise correlations
corr_DVs_just <- cor (DVs_just, use = "pairwise.complete.obs" )
# Plot the correlation matrix
corrplot (corr_DVs_just, is.corr = TRUE , type = "lower" , lower = "circle" , tl.cex = 0.7 , insig = "label_sig" , diag = TRUE )
# DVs gen
DVs_gen <- gjg[c ("reputation_signal_gen" , "norm_signal_gen" , "approval_gen" , "moral_gen" , "genuine_gen" , "deliberate_gen" , "spontaneous_gen" , "emotion_gen" , "logic_gen" , "quick_gen" , "slow_gen" , "warmth_gen" , "competence_gen" , "politics_gen" , "Age" , "SES" , "Political_overall" , "Political_social" , "Political_economic" )]
# Compute pairwise correlations
corr_DVs_gen <- cor (DVs_gen, use = "pairwise.complete.obs" )
# Plot the correlation matrix
corrplot (corr_DVs_gen, is.corr = TRUE , type = "lower" , lower = "circle" , tl.cex = 0.7 , insig = "label_sig" , diag = TRUE )
# DVs collapsed
# renaming DVs with underscores in name
gjg <- gjg %>%
dplyr:: rename ("reputationSignal_just" = "reputation_signal_just" ,
"reputationSignal_gen" = "reputation_signal_gen" ,
"normSignal_just" = "norm_signal_just" ,
"normSignal_gen" = "norm_signal_gen" ,
"goodNatured_gen" = "good_natured_gen" ,
"goodNatured_just" = "good_natured_just" )
gjg_long<- gjg %>% gather (DV, resp, "reputationSignal_just" ,"reputationSignal_gen" ,"normSignal_just" ,"normSignal_gen" ,"approval_just" ,"approval_gen" ,"moral_just" ,"moral_gen" ,"genuine_just" ,"genuine_gen" ,"deliberate_just" ,"deliberate_gen" ,"spontaneous_just" ,"spontaneous_gen" ,"emotion_just" ,"emotion_gen" ,"logic_just" ,"logic_gen" ,"quick_just" ,"quick_gen" ,"slow_just" ,"slow_gen" ,"warm_just" ,"warm_gen" ,"goodNatured_just" ,"goodNatured_gen" ,"tolerant_just" ,"tolerant_gen" ,"sincere_just" ,"sincere_gen" ,"competent_just" ,"competent_gen" ,"confident_just" ,"confident_gen" , "independent_just" ,"independent_gen" ,"competitive_just" ,"competitive_gen" ,"intelligent_just" ,"intelligent_gen" ,"warmth_just" ,"warmth_gen" ,"competence_just" ,"competence_gen" , "moralGoodness_just" , "moralGoodness_gen" , "decisionSpeed_just" , "decisionSpeed_gen" , "politics_just" , "politics_gen" )
gjg_long<- gjg_long %>%
separate (DV, into= c ("DV" , "motive" ), sep= "_" )
gjg_long <- spread (gjg_long, DV, resp)
DVs_col <- gjg_long[c ("reputationSignal" ,"normSignal" , "approval" , "moral" , "genuine" , "deliberate" , "spontaneous" , "emotion" , "logic" , "quick" , "slow" , "warm" , "goodNatured" , "tolerant" , "sincere" , "competent" , "confident" , "independent" , "competitive" , "intelligent" , "warmth" , "competence" ,"politics" , "Age" , "SES" , "Political_overall" , "Political_social" , "Political_economic" )]
# Compute pairwise correlations
corr_DVs_col <- cor (DVs_col, use = "pairwise.complete.obs" )
# Plot the correlation matrix
corrplot (corr_DVs_col, is.corr = TRUE , type = "lower" , lower = "circle" , tl.cex = 0.7 , insig = "label_sig" , diag = TRUE )
```
# EFA
```{r, include=FALSE}
factorDVs <- gjg_long[c ("reputationSignal" ,"normSignal" , "approval" , "moral" , "genuine" , "deliberate" , "spontaneous" , "emotion" , "logic" , "quick" , "slow" , "warm" , "goodNatured" , "tolerant" , "sincere" , "competent" , "confident" , "independent" , "competitive" , "intelligent" )]
```
## Evaluating the correlation matrix
```{r}
factorCor <- cor (factorDVs, use = "complete.obs" )
# Assuming you have a correlation matrix named "correlation_matrix"
correlation_threshold <- 0.8
high_correlations <- which (factorCor > correlation_threshold & upper.tri (factorCor, diag = FALSE ), arr.ind = TRUE )
# Extract the row and column indices of high correlations
row_indices <- high_correlations[, 1 ]
column_indices <- high_correlations[, 2 ]
# Extract the correlations greater than 0.8
high_correlation_values <- factorCor[high_correlations]
# Print the results
high_correlation_results <- data.frame (row_indices, column_indices, high_correlation_values)
print (high_correlation_results)
# removing one from all pairs of overcorrelated variables
# overcorrelated <- c("")
# efaDVs <- factorDVs[ ,!(names(factorDVs) %in% overcorrelated)]
efaDVs <- factorDVs
```
## Determining number of factors
* Eigenvalues suggests 5 factors
* Scree plot suggests 2 or 5 factors
* Parallel Analysis suggests 5
```{r}
## evaluating data
corr_DVs = cor (efaDVs, use= "complete.obs" )
KMO (efaDVs)
cortest.bartlett (efaDVs) #tests correlations between variables
##
ev<- eigen (corr_DVs) #gets eigenvalues (variance explained by each component)
ev$ values
scree (factorDVs, pc = FALSE ) #number of factors until plot levels off
fa.parallel (factorDVs, fa= "fa" ) #checks eigenvalues of factors against eigenvalues of identity (no correlation) matrix
dat_fa <- na.omit (DVs)
```
## 5 Factors
```{r}
fit <- factanal (na.omit (efaDVs), factors= 5 , rotation= "promax" , scores = "regression" )
print (fit, digits = 2 , cutoff = .3 , sort = TRUE )
loads <- fit$ loadings
fa.diagram (loads)
## Cronbach's Alpha
f1 <- efaDVs[ , c ("approval" , "moral" , "genuine" , "sincere" , "deliberate" , "emotion" , "logic" )]
f2 <- efaDVs[ , c ("competent" , "confident" , "independent" , "intelligent" )]
f3 <- efaDVs[ , c ("warm" , "goodNatured" , "tolerant" )]
f4 <- efaDVs[ , c ("quick" , "spontaneous" )]
f5 <- efaDVs[ , c ("reputationSignal" , "normSignal" , "competitive" )]
alpha (f1)
alpha (f2)
alpha (f3)
alpha (f4)
alpha (f5)
```
# CFA
```{r, include=FALSE}
model <- '
moralGoodness =~ approval + moral + genuine
competence =~ competent + confident + independent + intelligent + competitive + logic
warmth =~ warm + goodNatured + tolerant + sincere
decisionSpeed =~ quick + spontaneous
signaling =~ reputationSignal + normSignal
'
fit <- cfa (model, data = factorDVs)
summary (fit, fit.measures= TRUE )
```
# Factor 1: Warmth
* Significant
```{r fig.dim=c(12,10)}
plot_cooker <- function (dv, iv, Title, x_axis_labs, y_label, sample_size) {
part1 <- ggviolin (gjg_long, 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 : 5 )) +
labs (title = paste0 (Title, " (n = " , sample_size, ")" )) +
scale_x_discrete (labels = x_axis_labs) +
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 ))
ggpar (part1, legend = "none" )
}
gjg_long$ motive <- as.factor (gjg_long$ motive)
plot_cooker ("motive" , "warmth" , "Warmth" , c ("Generosity" , "Justice" )," " , 300 )
```
## Inferential Tests
```{r}
mod_warmth <- lmer (warmth ~ motive + (1 | PID), data = gjg_long)
summary (mod_warmth)
mod_warmth_pol <- lmer (warmth ~ motive* Political_overall + (1 | PID), data = gjg_long)
summary (mod_warmth_pol)
```
# Factor 2: Competence
* Significant
```{r fig.dim=c(12,10)}
plot_cooker ("motive" , "competence" , "Competence" , c ("Generosity" , "Justice" )," " , 300 )
```
## Inferential Tests
```{r}
mod_comp <- lmer (competence ~ motive + (1 | PID), data = gjg_long)
summary (mod_comp)
mod_comp_pol <- lmer (competence ~ motive* Political_overall + (1 | PID), data = gjg_long)
summary (mod_comp_pol)
```
# Factor 3: Moral Goodness
```{r fig.dim=c(12,10)}
plot_cooker ("motive" , "moralGoodness" , "Moral Goodness" , c ("Generosity" , "Justice" )," " , 300 )
```
## Inferential Tests
```{r}
mod_moral <- lmer (moralGoodness ~ motive + (1 | PID), data = gjg_long)
summary (mod_moral)
mod_moral_pol <- lmer (moralGoodness ~ motive* Political_overall + (1 | PID), data = gjg_long)
summary (mod_moral_pol)
```
# Factor 4: Decision Speed
* Significant main effect
* Interaction w/ participants' pol leaning -- conservatives think generous donor decision time is significantly longer
```{r fig.dim=c(12,10)}
plot_cooker ("motive" , "decisionSpeed" , "decisionSpeed" , c ("Generosity" , "Justice" )," " , 300 )
pol_line <- function (data, iv, dv) {
ggplot (data, aes (x = {{iv}}, y = {{dv}}, color = motive)) +
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 = "Motive" )
}
pol_line (gjg_long, Political_overall, decisionSpeed)
```
## Inferential Tests
```{r}
mod_speed <- lmer (decisionSpeed ~ motive + (1 | PID), data = gjg_long)
summary (mod_speed)
mod_speed_pol <- lmer (decisionSpeed ~ motive* Political_overall + (1 | PID), data = gjg_long)
summary (mod_speed_pol)
```
# Factor 5: Signaling
* Significant Norm Signaling
* Marginal Reputation Signaling
```{r fig.dim=c(12,10)}
plot_cooker ("motive" , "reputationSignal" , "Reputation Signaling" , c ("Generosity" , "Justice" )," " , 300 )
plot_cooker ("motive" , "normSignal" , "Norm Signaling" , c ("Generosity" , "Justice" )," " , 300 )
```
## Inferential Tests
```{r}
mod_rep <- lmer (reputationSignal ~ motive + (1 | PID), data = gjg_long)
summary (mod_rep)
mod_rep_pol <- lmer (reputationSignal ~ motive* Political_overall + (1 | PID), data = gjg_long)
summary (mod_rep_pol)
mod_norm <- lmer (normSignal ~ motive + (1 | PID), data = gjg_long)
summary (mod_norm)
mod_norm_pol <- lmer (normSignal ~ motive* Political_overall + (1 | PID), data = gjg_long)
summary (mod_norm_pol)
```
# Factor 6: Emotion
```{r fig.dim=c(12,10)}
plot_cooker ("motive" , "emotion" , "Emotion" , c ("Generosity" , "Justice" )," " , 300 )
```
## Inferential Tests
```{r}
mod_emotion <- lmer (emotion ~ motive + (1 | PID), data = gjg_long)
summary (mod_emotion)
mod_emotion_pol <- lmer (emotion ~ motive* Political_overall + (1 | PID), data = gjg_long)
summary (mod_emotion_pol)
```
# Factors by Text Order
## Factor 1: Warmth
```{r fig.dim=c(12,10)}
gjg_long <- gjg_long %>%
mutate (
motive_long = ifelse (motive == "just" , "justice" ,
ifelse (motive == "gen" , "generosity" , NA ))
)
#
# gjg_long %>% mutate(
# type = case_when(
# height > 200 | mass > 200 ~ "large",
# species == "Droid" ~ "robot",
# .default = "other"
# )
# )
lizy_cooker <- function (dv, iv, facet, Title, x_axis_labs, y_label, sample_size, coln, rown) {
part1 <- ggviolin (gjg_long, 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 (~ vigOrder, ncol = coln, nrow = rown, scales = "free" , as.table = TRUE )
ggpar (part1, legend = "none" )
}
lizy_cooker ("motive" , "warmth" , "vigOrder" , "Warmth" , c ("Generosity" , "Justice" )," " , 300 , 2 , 2 )
```
### Inferential Tests
```{r}
# mod_warmth_vigOrder <- lmer(warmth ~ motive*first_text + (1 | PID), data = gjg_long)
# summary(mod_warmth_vigOrder)
# view(gjg_long)
```
## Factor 2: Competence
```{r fig.dim=c(12,10)}
lizy_cooker ("motive" , "competence" , "vigOrder" , "Competence" , c ("Generosity" , "Justice" )," " , 300 , 2 , 2 )
mod_competence_vigOrder <- lmer (competence ~ motive* vigOrder + (1 | PID), data = gjg_long)
summary (mod_competence_vigOrder)
```
## Factor 3: Moral Goodness
```{r fig.dim=c(12,10)}
lizy_cooker ("motive" , "moralGoodness" , "vigOrder" , "Moral Goodness" , c ("Generosity" , "Justice" )," " , 300 , 2 , 2 )
mod_moral_vigOrder <- lmer (moralGoodness ~ motive* vigOrder + (1 | PID), data = gjg_long)
summary (mod_moral_vigOrder)
```
## Factor 4: Decision Speed
```{r fig.dim=c(12,10)}
lizy_cooker ("motive" , "decisionSpeed" , "vigOrder" , "Decision Speed" , c ("Generosity" , "Justice" )," " , 300 , 2 , 2 )
mod_speed_vigOrder <- lmer (decisionSpeed ~ motive* vigOrder + (1 | PID), data = gjg_long)
summary (mod_speed_vigOrder)
```
## Factor 5: Signaling
```{r fig.dim=c(12,10)}
lizy_cooker ("motive" , "reputationSignal" , "vigOrder" , "Reputation Signaling" , c ("Generosity" , "Justice" )," " , 300 , 2 , 2 )
mod_rep_vigOrder <- lmer (reputationSignal ~ motive* vigOrder + (1 | PID), data = gjg_long)
summary (mod_rep_vigOrder)
lizy_cooker ("motive" , "normSignal" , "vigOrder" , "Norm Signaling" , c ("Generosity" , "Justice" )," " , 300 , 2 , 2 )
mod_norm_vigOrder <- lmer (normSignal ~ motive* vigOrder + (1 | PID), data = gjg_long)
summary (mod_norm_vigOrder)
```
## Factor 6: Emotion
```{r fig.dim=c(12,10)}
lizy_cooker ("motive" , "emotion" , "Emotion" , "Reputation Signaling" , c ("Generosity" , "Justice" )," " , 300 , 2 , 2 )
mod_emotion_vigOrder <- lmer (emotion ~ motive* vigOrder + (1 | PID), data = gjg_long)
summary (mod_emotion_vigOrder)
```