---
title: "IS Obesity Pilot (N = 150)"
author: 'Marcus'
date: "8/6/2024"
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: yes
header-includes:
- \usepackage{Roboto Condensed}
knitr:
opts_chunk:
dev: ragg_png
execute:
warning: false
---
# 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", "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}
# read in data files
setwd("~/Desktop")
gjg_raw <-read.csv("/Users/mtrenfield17/Desktop/Research/Boston College Research/SISC Lab Research/IS Project/Obesity/IS Obesity Pilot 1.csv")
```
## Functions
```{r, message=F, results='hide', warning=FALSE}
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
```{r}
#### filtering people who failed the attn check ####
gjg <- gjg_raw %>% filter (attentionCheck == 3 )
## changing condition to factor and reordering ##
gjg$ condition <- as.factor (gjg$ condition)
gjg$ condition <- factor (gjg$ condition, levels = c ("individualScope" , "populationScope" , "mergedScope" ))
# changing numeric DVs to numeric
gjg <- gjg %>% mutate_at (vars (policyDV, donation, helpDV_1: efficacy_3, age, pol, pid, edu, inc, weight, charityRealYN, Duration..in.seconds.), as.numeric)
## renaming matrix variables
names (gjg)[names (gjg) == 'helpDV_1' ] <- 'usGovHelp'
names (gjg)[names (gjg) == 'helpDV_2' ] <- 'manufacturerHelp'
names (gjg)[names (gjg) == 'helpDV_3' ] <- 'individualHelp'
names (gjg)[names (gjg) == 'helpDV_4' ] <- 'youHelp'
names (gjg)[names (gjg) == 'preventDV_1' ] <- 'usGovPrevent'
names (gjg)[names (gjg) == 'preventDV_2' ] <- 'manufacturerPrevent'
names (gjg)[names (gjg) == 'preventDV_3' ] <- 'individualPrevent'
names (gjg)[names (gjg) == 'preventDV_4' ] <- 'youPrevent'
names (gjg)[names (gjg) == 'feelingsMeasures_1' ] <- 'upset'
names (gjg)[names (gjg) == 'feelingsMeasures_2' ] <- 'sympathetic'
names (gjg)[names (gjg) == 'feelingsMeasures_3' ] <- 'touched'
names (gjg)[names (gjg) == 'moral_1' ] <- 'donatingMoral'
names (gjg)[names (gjg) == 'moral_2' ] <- 'eatingMoral'
names (gjg)[names (gjg) == 'moral_3' ] <- 'adMoral'
names (gjg)[names (gjg) == 'moral_4' ] <- 'sugarMoral'
names (gjg)[names (gjg) == 'blame_1' ] <- 'manufacturerBlame'
names (gjg)[names (gjg) == 'blame_2' ] <- 'individualBlame'
names (gjg)[names (gjg) == 'efficacy_1' ] <- 'studyDonationEfficacy'
names (gjg)[names (gjg) == 'efficacy_2' ] <- 'studyPolicyEfficacy'
names (gjg)[names (gjg) == 'efficacy_3' ] <- 'donationEfficacy'
```
# Data Quality Checks
## Attention Check
* 3 people failed the attention check
```{r, message=F, results='hide', warning=FALSE}
gjg_raw <- gjg_raw %>% filter(consent == 8)
gjg_raw %>%
group_by(attentionCheck) %>%
dplyr::summarise(n = n()) %>%
mutate(freq = n / sum(n))
```
## Charity Belief (Return and double check this)
- People are *less* doubtful of the individual charity in the individual frame than combined frame (neither different from structural)
```{r}
ggplot (gjg, aes (x = condition, y = charityRealYN)) +
geom_violin () +
geom_boxplot (width= 0.1 , fill= "white" ) +
theme_minimal () +
labs (y = "Not at all to Extremely" , x = "Condition" , title = "Extent Participants Doubted the Charity was real" )
# Check for duplicate column names
anyDuplicated (names (gjg))
names (gjg)
gjg$ condition <- relevel (gjg$ condition, ref = "mergedScope" )
gjg_I <- gjg
gjg_I$ condition <- relevel (gjg_I$ condition, ref = "individualScope" )
mod_belief <- lm (charityRealYN ~ condition, data = gjg)
summary (mod_belief)
mod_belief_I <- lm (charityRealYN ~ condition, data = gjg_I)
summary (mod_belief_I)
```
# Demographics
```{r fig.dim = c(15, 13)}
# Subset your data frame to include only the demographic columns
demo_gjg <- gjg[, c("weight_TEXT", "gen_TEXT", "race_TEXT", "inc_TEXT", "edu_TEXT", "pol_TEXT", "pid_TEXT", "area_TEXT")]
# Age
mean(gjg$age, na.rm=TRUE)
sd(gjg$age, na.rm=TRUE)
# 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("\nTable of frequencies for", names(freq_tables)[i], ":\n")
print(freq_tables[[i]])
}
}
```
# Correlations
```{r}
DVs <- gjg[c ("policyDV" , "donation" , "usGovHelp" , "manufacturerHelp" , "individualHelp" , "youHelp" , "usGovPrevent" , "manufacturerPrevent" , "individualPrevent" , "youPrevent" , "upset" , "sympathetic" , "touched" , "donatingMoral" , "eatingMoral" , "adMoral" , "sugarMoral" , "individualBlame" , "manufacturerBlame" , "studyDonationEfficacy" , "studyPolicyEfficacy" , "donationEfficacy" , "pol" , "edu" , "inc" , "age" , "weight" )]
# Compute pairwise correlations
corr_DVs <- cor (DVs, use = "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 )
```
# EFA
```{r, include=FALSE}
factorDVs <- gjg[c("policyDV", "donation", "usGovHelp", "manufacturerHelp", "individualHelp", "youHelp", "usGovPrevent", "manufacturerPrevent", "individualPrevent", "youPrevent", "upset", "sympathetic", "touched", "donatingMoral", "eatingMoral", "adMoral", "sugarMoral", "individualBlame", "manufacturerBlame", "studyDonationEfficacy", "studyPolicyEfficacy", "donationEfficacy")]
```
## Evaluating the correlation matrix
```{r, include=FALSE}
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()
# youPrevent and individualPrevent overcorrelated
efaDVs <- factorDVs[ ,!(names(factorDVs) %in% overcorrelated)]
efaDVs <- factorDVs
```
## Determining number of factors
- Scree plot suggests 3-5
- eigenvalue method suggests 3
- Parallel Analysis suggests 5
```{r, include=FALSE}
## evaluating data
corr_DVs = cor(efaDVs, use="complete.obs")
KMO(efaDVs)
cortest.bartlett(efaDVs) #tests correlations between variables
## finding number of factors
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)
```
## 3 Factors
```{r}
fit <- factanal (na.omit (efaDVs), factors= 3 , rotation= "promax" , scores = "regression" )
print (fit, digits = 2 , cutoff = .3 , sort = TRUE )
loads <- fit$ loadings
fa.diagram (loads)
# ## Cronbach's Alpha
# f1 <- efaDVs[ , c("futureSacrifice", "futureImpact", "futureResponsibility", "moralMitigate",
# "moralCollective", "intergenerational1", "opportunityChoiceNum", "donation", "moralProtect", "dayToDayEfficacy")]
# f2 <- efaDVs[ , c("effortEfficacy", "americansEfficacy1", "americansEfficacy2", "optimism")]
# f3 <- efaDVs[ , c("thankfulPG", "sacrificesPG", "gratitudePG")]
# f4 <- efaDVs[ , c("intergenerational1", "intergenerational2", "american1", "american2")]
# f5 <- efaDVs[ , c("hope", "optimism")]
# alpha(f1)
# alpha(f2)
# alpha(f3)
# alpha(f4)
# alpha(f5)
```
## 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("futureSacrifice", "futureImpact", "futureResponsibility", "moralMitigate",
# "moralCollective", "intergenerational1", "opportunityChoiceNum", "donation", "moralProtect", "dayToDayEfficacy")]
# f2 <- efaDVs[ , c("effortEfficacy", "americansEfficacy1", "americansEfficacy2", "optimism")]
# f3 <- efaDVs[ , c("thankfulPG", "sacrificesPG", "gratitudePG")]
# f4 <- efaDVs[ , c("intergenerational1", "intergenerational2", "american1", "american2")]
# f5 <- efaDVs[ , c("hope", "optimism")]
# alpha(f1)
# alpha(f2)
# alpha(f3)
# alpha(f4)
# alpha(f5)
```
# CFA
- Bad fit
```{r}
model <- '
responsibilityHelp =~ usGovHelp + manufacturerHelp + individualHelp + youHelp
responsibilityPrevent =~ usGovPrevent + manufacturerPrevent + individualPrevent + youPrevent
affect =~ upset + sympathetic + touched
moralIssue =~ donatingMoral + eatingMoral + adMoral + sugarMoral
blame =~ manufacturerBlame + individualBlame
efficacy =~ studyDonationEfficacy + studyPolicyEfficacy + donationEfficacy
'
fit <- cfa (model, data = factorDVs)
summary (fit, fit.measures= TRUE )
```
# Behavioral Outcomes
```{r fig.dim = c(12, 10)}
gjg$condition <- factor(gjg$condition, levels = c("individualScope", "populationScope", "mergedScope"))
percep_plot_list <- list(plot_cooker(gjg, condition, donation),
plot_cooker(gjg, condition, policyDV))
# Adding titles to each plot
percep_plot_list[[1]] <- percep_plot_list[[1]] +
ggtitle("Donations")
percep_plot_list[[2]] <- percep_plot_list[[2]] +
ggtitle("Support for Policy")
percep_plot_arranged <- ggarrange(plotlist = percep_plot_list, ncol = 2, nrow = 1)
overall_percep_title <- ggdraw() +
draw_label("Behavioral DVs", fontface = "bold")
plot_grid(overall_percep_title, percep_plot_arranged, ncol = 1, rel_heights = c(0.1, 0.9))
gjg %>%
group_by(condition) %>%
dplyr::summarise(mean(policyDV))
gjg %>%
group_by(condition) %>%
dplyr::summarise(mean(donation))
```
<!-- ## Cleaner Plots -->
<!-- ```{r} -->
<!-- gjg %>% -->
<!-- group_by(condition) %>% -->
<!-- dplyr::summarise(meanDonation = mean(donation), meanSupport = mean(policyDV)) %>% -->
<!-- print() -->
<!-- # reordering data -->
<!-- gjg$condition <- factor(gjg$condition, levels = c("individualScope", "populationScope", "mergedScope")) -->
<!-- # Donation Plot -->
<!-- donationP <- ggplot(gjg, aes(x = condition, y = donation)) + -->
<!-- geom_point(stat = "summary", fun = "mean", size = 4, position = position_dodge(width = 0.25)) + -->
<!-- stat_summary(fun.data = "mean_cl_normal", geom = "errorbar", position = position_dodge(width = 0.25), width = 0.2, size = 1.5) + -->
<!-- scale_x_discrete(labels = c("Individual", "Structural", "Combined")) + -->
<!-- labs(x = "Narrative Frame", y = "Amount ($)", title = "Donation to an Individual Victim") + -->
<!-- theme_minimal(base_size = 15) + # Use a minimal theme -->
<!-- theme( -->
<!-- plot.title = element_text(hjust = 0.5, size = 35), -->
<!-- axis.text.x = element_text(face = "plain", size = 25, color = "black"), -->
<!-- axis.text.y = element_text(face = "plain", size = 25, color = "black"), -->
<!-- axis.title.y = element_text(face = "plain", size = 30, color = "black"), -->
<!-- axis.title.x = element_text(face = "plain", size = 30, color = "black"), -->
<!-- legend.title = element_text(size = 14), # Increase legend title size -->
<!-- legend.text = element_text(size = 12), -->
<!-- panel.grid.major = element_line(color = "gray"), # Set major grid lines to gray -->
<!-- panel.grid.minor = element_blank(), # Hide minor grid lines -->
<!-- panel.background = element_rect(fill = "white", color = "white"), -->
<!-- panel.border = element_rect(color = "black", fill = NA, size = 1) -->
<!-- ) + -->
<!-- coord_cartesian(ylim = c(1, 6)) + -->
<!-- scale_y_continuous(breaks = c(1,2,3,4,5,6)) -->
<!-- print(donationP) -->
<!-- ggsave("obesity_donations.png", plot = donationP, width = 10, height = 12) -->
<!-- gjg_noDem <- gjg %>% filter(pol<5) -->
<!-- ## Policy Support Plot -->
<!-- policyP <- ggplot(gjg, aes(x = condition, y = policyDV)) + -->
<!-- geom_point(stat = "summary", fun = "mean", size = 4, position = position_dodge(width = 0.25)) + -->
<!-- stat_summary(fun.data = "mean_cl_normal", geom = "errorbar", position = position_dodge(width = 0.25), width = 0.2, size = 1.5) + -->
<!-- geom_hline(yintercept = 4, linetype = "dashed", color = "black", size = 1) + -->
<!-- scale_x_discrete(labels = c("Individual", "Structural", "Combined")) + -->
<!-- labs(x = "Narrative Frame", y = "Support", title = " Support for Federal \n\ Decarbonization Policy") + -->
<!-- theme_minimal(base_size = 15) + # Use a minimal theme -->
<!-- theme( -->
<!-- plot.title = element_text(hjust = 0.5, size = 35), -->
<!-- axis.text.x = element_text(face = "plain", size = 25, color = "black"), -->
<!-- axis.text.y = element_text(face = "plain", size = 25, color = "black"), -->
<!-- axis.title.y = element_text(face = "plain", size = 30, color = "black"), -->
<!-- axis.title.x = element_text(face = "plain", size = 30, color = "black"), -->
<!-- legend.title = element_text(size = 14), # Increase legend title size -->
<!-- legend.text = element_text(size = 12), -->
<!-- panel.grid.major = element_line(color = "gray"), # Set major grid lines to gray -->
<!-- panel.grid.minor = element_blank(), # Hide minor grid lines -->
<!-- panel.background = element_rect(fill = "white", color = "white"), -->
<!-- panel.border = element_rect(color = "black", fill = NA, size = 1) -->
<!-- ) + -->
<!-- coord_cartesian(ylim = c(1, 7)) + -->
<!-- scale_y_continuous(breaks = c(1,2,3,4,5,6,7)) -->
<!-- print(policyP) -->
<!-- ggsave("obesity_policy_support.png", plot = policyP, width = 10, height = 12) -->
<!-- library(gridExtra) -->
<!-- # Now arrange your plots with adjusted spacing -->
<!-- combinedB <- grid.arrange(donationP, policyP, ncol = 2, nrow = 1, -->
<!-- widths = c(1, 1), # Adjust the relative widths of the plots -->
<!-- layout_matrix = rbind(c(1, 2))) -->
<!-- ggsave("combined_behavioral_outcomes.png", plot = combinedB, width = 14, height = 10) -->
<!-- ``` -->
## Inferential Stats
```{r}
gjg$ condition <- relevel (gjg$ condition, ref = "mergedScope" )
gjg_I <- gjg
gjg_I$ condition <- relevel (gjg_I$ condition, ref = "individualScope" )
mod_donation<- lm (donation ~ condition, data = gjg)
summary (mod_donation)
confint (mod_donation)
mod_donation<- lm (donation ~ condition* pol, data = gjg)
summary (mod_donation)
mod_donationI <- lm (donation ~ condition* pol, data = gjg_I)
summary (mod_donationI)
mod_donationI <- lm (donation ~ condition, data = gjg_I)
summary (mod_donationI)
mod_policy<- lm (policyDV ~ condition, data = gjg)
summary (mod_policy)
mod_policyI <- lm (policyDV ~ condition, data = gjg_I)
summary (mod_policyI)
```
# Responsibility (Help and Prevent)
```{r fig.dim = c(12, 10)}
gjg_long<-gjg %>% gather(stim, resp, "usGovHelp":"donationEfficacy")
gjg_long$condition <- factor(gjg_long$condition, levels = c("individualScope", "populationScope", "mergedScope"))
responsibilityHelpLong <- gjg_long %>%
filter(grepl("Help", stim))
facet_cooker <- function(data, iv, dv, coln, rown) {
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("") +
facet_wrap(~ stim, ncol = coln, nrow = rown, scales = "free", as.table = TRUE)
ggpar(part1, legend = "none")
}
facet_cooker(responsibilityHelpLong, condition, resp, coln = 2, rown = 2)
responsibilityPreventLong <- gjg_long %>%
filter(grepl("Prevent", stim))
facet_cooker(responsibilityPreventLong, condition, resp, coln = 2, rown = 2)
```
## Inferential Stats
```{r }
mod_usGovHelp <- lm(usGovHelp ~ condition, data = gjg)
summary(mod_usGovHelp)
mod_usGovHelpI <- lm(usGovHelp ~ condition, data = gjg_I)
summary(mod_usGovHelpI)
mod_manufacturerHelp <- lm(manufacturerHelp ~ condition, data = gjg)
summary(mod_manufacturerHelp)
mod_manufacturerHelpI <- lm(manufacturerHelp ~ condition, data = gjg_I)
summary(mod_manufacturerHelpI)
mod_individualHelp <- lm(individualHelp ~ condition, data = gjg)
summary(mod_individualHelp)
mod_individualHelpI <- lm(individualHelp ~ condition, data = gjg_I)
summary(mod_individualHelpI)
mod_youHelp <- lm(youHelp ~ condition, data = gjg)
summary(mod_youHelp)
mod_youHelpI <- lm(youHelp ~ condition, data = gjg_I)
summary(mod_youHelpI)
# Prevent
mod_usGovPrevent <- lm(usGovPrevent ~ condition, data = gjg)
summary(mod_usGovPrevent)
mod_usGovPreventI <- lm(usGovPrevent ~ condition, data = gjg_I)
summary(mod_usGovPreventI)
mod_manufacturerPrevent <- lm(manufacturerPrevent ~ condition, data = gjg)
summary(mod_manufacturerPrevent)
mod_manufacturerPreventI <- lm(manufacturerPrevent ~ condition, data = gjg_I)
summary(mod_manufacturerPreventI)
mod_individualPrevent <- lm(individualPrevent ~ condition, data = gjg)
summary(mod_individualPrevent)
mod_individualPreventI <- lm(individualPrevent ~ condition, data = gjg_I)
summary(mod_individualPreventI)
mod_youPrevent <- lm(youPrevent ~ condition, data = gjg)
summary(mod_youPrevent)
mod_youPreventI <- lm(youPrevent ~ condition, data = gjg_I)
summary(mod_youPreventI)
```
# Affect Help
```{r fig.dim = c(12, 10)}
affectLong <- gjg_long %>%
filter(stim %in% c("upset", "sympathetic", "touched"))
facet_cooker(affectLong, condition, resp, coln = 2, rown = 2)
```
## Inferential Stats
```{r }
mod_upset <- lm(upset ~ condition, data = gjg)
summary(mod_upset)
mod_upsetI <- lm(upset ~ condition, data = gjg_I)
summary(mod_upsetI)
mod_sympathetic <- lm(sympathetic ~ condition, data = gjg)
summary(mod_sympathetic)
mod_sympatheticI <- lm(sympathetic ~ condition, data = gjg_I)
summary(mod_sympatheticI)
mod_touched <- lm(touched ~ condition, data = gjg)
summary(mod_touched)
mod_touchedI <- lm(touched ~ condition, data = gjg_I)
summary(mod_touchedI)
```
# Efficacy
```{r fig.dim = c(12, 10)}
efficacyHelpLong <- gjg_long %>%
filter(grepl("Efficacy", stim))
facet_cooker(efficacyHelpLong, condition, resp, coln = 2, rown = 2)
```
## Inferential Stats
```{r }
mod_studyDonationEfficacy <- lm(studyDonationEfficacy ~ condition, data = gjg)
summary(mod_studyDonationEfficacy)
mod_studyDonationEfficacyI <- lm(studyDonationEfficacy ~ condition, data = gjg_I)
summary(mod_studyDonationEfficacyI)
mod_studyPolicyEfficacy <- lm(studyPolicyEfficacy ~ condition, data = gjg)
summary(mod_studyPolicyEfficacy)
mod_studyPolicyEfficacyI <- lm(studyPolicyEfficacy ~ condition, data = gjg_I)
summary(mod_studyPolicyEfficacyI)
mod_donationEfficacy <- lm(donationEfficacy ~ condition, data = gjg)
summary(mod_donationEfficacy)
mod_donationEfficacyI <- lm(donationEfficacy ~ condition, data = gjg_I)
summary(mod_donationEfficacyI)
```
# Morality
```{r fig.dim = c(12, 10)}
moralIssueLong <- gjg_long %>%
filter(grepl("Moral", stim))
facet_cooker(moralIssueLong, condition, resp, coln = 2, rown = 2)
blameLong <- gjg_long %>%
filter(grepl("Blame", stim))
facet_cooker(blameLong, condition, resp, coln = 2, rown = 2)
```
## Inferential Stats
```{r }
mod_donatingMoral <- lm(donatingMoral ~ condition, data = gjg)
summary(mod_donatingMoral)
mod_donatingMoralI <- lm(donatingMoral ~ condition, data = gjg_I)
summary(mod_donatingMoralI)
mod_eatingMoral <- lm(eatingMoral ~ condition, data = gjg)
summary(mod_eatingMoral)
mod_eatingMoralI <- lm(eatingMoral ~ condition, data = gjg_I)
summary(mod_eatingMoralI)
mod_adMoral <- lm(adMoral ~ condition, data = gjg)
summary(mod_adMoral)
mod_adMoralI <- lm(adMoral ~ condition, data = gjg_I)
summary(mod_adMoralI)
mod_sugarMoral <- lm(sugarMoral ~ condition, data = gjg)
summary(mod_sugarMoral)
mod_sugarMoralI <- lm(sugarMoral ~ condition, data = gjg_I)
summary(mod_sugarMoralI)
mod_manufacturerBlame <- lm(manufacturerBlame ~ condition, data = gjg)
summary(mod_manufacturerBlame)
mod_manufacturerBlameI <- lm(manufacturerBlame ~ condition, data = gjg_I)
summary(mod_manufacturerBlameI)
mod_indBlame <- lm(individualBlame ~ condition, data = gjg)
summary(mod_indBlame)
mod_indBlameI <- lm(individualBlame ~ condition, data = gjg_I)
summary(mod_indBlameI)
```
# Creating Composites Z-score
```{r}
gjg <- gjg %>%
mutate (
govResponsibility = (usGovHelp + usGovPrevent) / 2 ,
indivResponsibility = (individualHelp + individualPrevent + individualBlame) / 3 ,
manufacturerResponsibility = (manufacturerHelp + manufacturerPrevent + manufacturerBlame) / 3 ,
manufacturerMoral = (adMoral + sugarMoral) / 2 ,
youResponsibility = (youHelp + youPrevent) / 2 ,
compassion = (upset + sympathetic + touched) / 3 ,
indivEfficacy = (studyDonationEfficacy + donationEfficacy) / 2 ,
indivMoral = (donatingMoral + eatingMoral) / 2
)
# Standardizing variables
variables_to_standardize <- c ("usGovHelp" , "manufacturerHelp" , "individualHelp" , "youHelp" , "usGovPrevent" , "manufacturerPrevent" , "individualPrevent" , "youPrevent" , "upset" , "sympathetic" , "touched" , "donatingMoral" , "eatingMoral" , "adMoral" , "sugarMoral" , "manufacturerBlame" , "individualBlame" , "studyDonationEfficacy" , "studyPolicyEfficacy" , "donationEfficacy" , "govResponsibility" , "indivResponsibility" , "manufacturerResponsibility" , "youResponsibility" , "compassion" , "indivEfficacy" , "manufacturerMoral" , "indivMoral" )
gjg_z <- gjg %>%
mutate (across (all_of (variables_to_standardize), ~ as.numeric (scale (.))))
```
## Inferential Stats
- Individual & Merged donate more than Structural
```{r}
gjg$ condition <- relevel (gjg$ condition, ref = "mergedScope" )
gjg_I <- gjg
gjg_I$ condition <- relevel (gjg_I$ condition, ref = "individualScope" )
mod_compRes<- lm (manufacturerResponsibility ~ condition, data = gjg)
summary (mod_compRes)
confint (mod_compRes)
mod_indRes<- lm (indivResponsibility ~ condition, data = gjg)
summary (mod_indRes)
confint (mod_indRes)
mod_compassion<- lm (compassion ~ condition, data = gjg)
summary (mod_compassion)
confint (mod_compassion)
mod_indivEff<- lm (indivEfficacy ~ condition, data = gjg)
summary (mod_indivEff)
confint (mod_indivEff)
mod_polEff<- lm (studyPolicyEfficacy ~ condition, data = gjg)
summary (mod_polEff)
confint (mod_polEff)
```
<!-- # Mechanisms Plot -->
<!-- ## Plot with all measures -->
<!-- ```{r fig.width=12, fig.height=10} -->
<!-- # gather the standardized variables into a long format -->
<!-- gjg_z_long <- gjg_z %>% -->
<!-- gather(key = "measure", value = "value", -->
<!-- manufacturerHelp, usGovHelp, youHelp, manufacturerPrevent, individualPrevent, -->
<!-- usGovPrevent, youPrevent, upset, sympathetic, touched, -->
<!-- studyDonationEfficacy, donationEfficacy, studyPolicyEfficacy, -->
<!-- manufacturerBlame, donatingMoral, manufacturerMoral) -->
<!-- # setting order -->
<!-- gjg_z_long$measure <- factor( -->
<!-- gjg_z_long$measure, -->
<!-- levels = rev(c("studyDonationEfficacy", "donationEfficacy", -->
<!-- "studyPolicyEfficacy", "sympathetic", "touched", "upset", -->
<!-- "individualPrevent", "youHelp", "youPrevent", "usGovHelp", -->
<!-- "usGovPrevent", "manufacturerHelp", "manufacturerPrevent","manufacturerBlame", -->
<!-- "individualBlame", "donatingMoral", "manufacturerMoral")) -->
<!-- ) -->
<!-- # Rename levels -->
<!-- levels(gjg_z_long$measure) <- rev(c( -->
<!-- "Efficacy: Study Donation Efficacy", -->
<!-- "Efficacy: Donations", -->
<!-- "Efficacy: Policy", -->
<!-- "Affect: Sympathetic", -->
<!-- "Affect: Touched", -->
<!-- "Affect: Upset", -->
<!-- "Responsibility: Individual Prevent", -->
<!-- "Responsibility: You Help", -->
<!-- "Responsibility: You Prevent", -->
<!-- "Responsibility: US Gov Help", -->
<!-- "Responsibility: US Gov Prevent", -->
<!-- "Responsibility: manufacturer Help", -->
<!-- "Responsibility: manufacturer Prevent", -->
<!-- "Responsibility: manufacturer Blame", -->
<!-- "Responsibility: Individual Blame", -->
<!-- "Moral Issue: Donating to Victims", -->
<!-- "Moral Issue: Companies Reducing Emissions" -->
<!-- )) -->
<!-- # Update the condition factor with new labels -->
<!-- gjg_z_long$condition <- factor(gjg_z_long$condition, -->
<!-- levels = c("individualScope", "populationScope", "mergedScope"), -->
<!-- labels = c("Individual", "Structural", "Combined")) -->
<!-- # Custom colors -->
<!-- library(RColorBrewer) -->
<!-- set1_palette <- brewer.pal(n = 3, name = 'Set1') -->
<!-- custom_colors <- c("Individual" = set1_palette[1], -->
<!-- "Structural" = set1_palette[2], -->
<!-- "Combined" = "#800080") -->
<!-- # Custom shapes -->
<!-- custom_shapes <- c("Individual" = 16, "Structural" = 15, "Combined" = 17) -->
<!-- # Create the plot with customizations -->
<!-- zplot <- ggplot(gjg_z_long, aes(x = measure, y = value, color = condition, shape = condition)) + -->
<!-- stat_summary(fun = mean, geom = "point", position = position_dodge(width = 0.5), size = 3) + -->
<!-- stat_summary(fun.data = mean_cl_normal, geom = "errorbar", -->
<!-- position = position_dodge(width = 0.5), width = 0.2) + -->
<!-- scale_color_manual(values = custom_colors) + -->
<!-- scale_shape_manual(values = custom_shapes) + -->
<!-- coord_flip() + -->
<!-- theme_minimal() + -->
<!-- labs(x = "Measure", y = "Z-Score", title = "Performance of Each Narrative on Outcomes", color = "Narrative Frame", shape = "Narrative Frame") + -->
<!-- theme( -->
<!-- legend.position = "bottom", -->
<!-- legend.text = element_text(size = 20), -->
<!-- legend.title = element_text(size = 20), -->
<!-- plot.title = element_text(size = 25, hjust = 0.5, face = "bold"), -->
<!-- axis.title.y = element_text(face = "plain", size = 22, color = "black"), -->
<!-- axis.title.x = element_text(face = "plain", size = 22, color = "black"), axis.text.x = element_text(face = "plain", size = 18), -->
<!-- axis.text.y = element_text(face = "plain", size = 18), -->
<!-- panel.border = element_rect(color = "black", fill = NA, size = 1), -->
<!-- legend.key.size = unit(3, "lines") -->
<!-- ) -->
<!-- zplot <- zplot + -->
<!-- theme(panel.spacing = unit(2, "lines")) # Adjust the space between facets/panels -->
<!-- # Print the plot -->
<!-- print(zplot) -->
<!-- ``` -->
<!-- ## Plot with collapsed measures -->
<!-- ```{r} -->
<!-- # First, let's gather the standardized variables into a long format -->
<!-- gjg_z_long <- gjg_z %>% -->
<!-- gather(key = "measure", value = "value", -->
<!-- manufacturerResponsibility, usGovResponsibility, individualPrevent, -->
<!-- selfResponsibility, individualPrevent, compassion, donationEfficacy, -->
<!-- studyPolicyEfficacy) -->
<!-- # setting order -->
<!-- gjg_z_long$measure <- factor( -->
<!-- gjg_z_long$measure, -->
<!-- levels = rev(c( -->
<!-- "donationEfficacy", "studyPolicyEfficacy", -->
<!-- "compassion", "selfResponsibility", "individualPrevent", -->
<!-- "usGovResponsibility", "manufacturerResponsibility" -->
<!-- )) -->
<!-- ) -->
<!-- # Rename levels -->
<!-- levels(gjg_z_long$measure) <- rev(c( -->
<!-- "Efficacy: Donations", -->
<!-- "Efficacy: Policy", -->
<!-- "Responsibility: Self", -->
<!-- "Compassion", -->
<!-- )) -->
<!-- # Update the condition factor with new labels -->
<!-- gjg_z_long$condition <- factor(gjg_z_long$condition, -->
<!-- levels = c("individualScope", "populationScope", "mergedScope"), -->
<!-- labels = c("Individual", "Structural", "Combined")) -->
<!-- # Custom colors -->
<!-- library(RColorBrewer) -->
<!-- set1_palette <- brewer.pal(n = 3, name = 'Set1') -->
<!-- custom_colors <- c("Individual" = set1_palette[1], -->
<!-- "Structural" = set1_palette[2], -->
<!-- "Combined" = "#800080") -->
<!-- # Custom shapes -->
<!-- custom_shapes <- c("Individual" = 16, "Structural" = 15, "Combined" = 17) -->
<!-- # Create the plot with customizations -->
<!-- zplot <- ggplot(gjg_z_long, aes(x = measure, y = value, color = condition, shape = condition)) + -->
<!-- stat_summary(fun = mean, geom = "point", position = position_dodge(width = 0.7), size = 3) + -->
<!-- stat_summary(fun.data = mean_cl_normal, geom = "errorbar", -->
<!-- position = position_dodge(width = 0.7), width = 0.2) + -->
<!-- scale_color_manual(values = custom_colors) + -->
<!-- scale_shape_manual(values = custom_shapes) + -->
<!-- coord_flip() + -->
<!-- theme_minimal() + -->
<!-- labs(x = "Measure", y = "Z-Score", title = "Performance of Each Narrative on Outcomes", color = "Narrative Frame", shape = "Narrative Frame") + -->
<!-- theme( -->
<!-- legend.position = "bottom", -->
<!-- legend.text = element_text(size = 20, color = "black"), -->
<!-- legend.title = element_text(size = 20, color = "black"), -->
<!-- plot.title = element_blank(), -->
<!-- axis.title.y = element_text(face = "plain", size = 22, color = "black"), -->
<!-- axis.title.x = element_text(face = "plain", size = 22, color = "black"), axis.text.x = element_text(face = "plain", size = 18, color = "black"), -->
<!-- axis.text.y = element_text(face = "plain", size = 18, color = "black"), -->
<!-- panel.border = element_rect(color = "black", fill = NA, size = 1), -->
<!-- legend.key.size = unit(3, "lines") -->
<!-- ) -->
<!-- zplot <- zplot + -->
<!-- theme(panel.spacing = unit(2.5, "lines")) # Adjust the space between facets/panels -->
<!-- # Print the plot -->
<!-- print(zplot) -->
<!-- ``` -->
<!-- # Mediation -->
<!-- ## S to I Policy DV Mediation -->
<!-- ```{r} -->
<!-- gjg_noCombined <- gjg %>% filter(condition != "mergedScope") -->
<!-- gjg_noCombined <- within(gjg_noCombined, { -->
<!-- structuralNarrative <- ifelse(condition == "populationScope", 1, 0) -->
<!-- }) -->
<!-- model <- ' -->
<!-- # outcome model -->
<!-- policyDV ~ c*structuralNarrative + b1*youResponsibility + b2*indivResponsibility + b3*manufacturerResponsibility + b4*govResponsibility + b5*indivEfficacy + -->
<!-- b6*studyPolicyEfficacy + b7*compassion + b8*donatingMoral + b9*manufacturerMoral -->
<!-- # mediator models -->
<!-- youResponsibility ~ a1*structuralNarrative -->
<!-- indivResponsibility ~ a2*structuralNarrative -->
<!-- manufacturerResponsibility ~ a3*structuralNarrative -->
<!-- govResponsibility ~ a4*structuralNarrative -->
<!-- indivEfficacy ~ a5*structuralNarrative -->
<!-- studyPolicyEfficacy ~ a6*structuralNarrative -->
<!-- compassion ~ a7*structuralNarrative -->
<!-- donatingMoral ~ a8*structuralNarrative -->
<!-- manufacturerMoral ~ a9*structuralNarrative -->
<!-- # Indirect Effects -->
<!-- youResIDE := a1*b1 -->
<!-- indivResIDE := a2*b2 -->
<!-- manufacturerResIDE := a3*b3 -->
<!-- govResIDE := a4*b4 -->
<!-- indivEffIDE := a5*b5 -->
<!-- studyPolEffIDE := a6*b6 -->
<!-- compassionIDE := a7*b7 -->
<!-- donatingMoralIDE := a8*b8 -->
<!-- manufacturerMoralIDE := a9*b9 -->
<!-- # total effect -->
<!-- total := c + (a1*b1) + (a2*b2) + (a3*b3) + (a4*b4) + (a5*b5) + (a6*b6) + (a7*b7) + -->
<!-- (a8*b8) + (a9*b9) -->
<!-- # total indirect effect -->
<!-- totalIDE := (a1*b1) + (a2*b2) + (a3*b3) + (a4*b4) + (a5*b5) + (a6*b6) + (a7*b7) + -->
<!-- (a8*b8) + (a9*b9) -->
<!-- ' -->
<!-- fit <- sem(model, data = gjg_noCombined) -->
<!-- summary(fit, fit.measures = TRUE, standardized = TRUE, rsquare = TRUE) -->
<!-- summary(lm(policyDV ~ structuralNarrative, gjg_noCombined)) -->
<!-- summary(lm(policyDV ~ structuralNarrative + youResponsibility + indivResponsibility + -->
<!-- manufacturerResponsibility + indivEfficacy + studyPolicyEfficacy + compassion -->
<!-- + donatingMoral + manufacturerMoral, gjg_noCombined)) -->
<!-- library(lavaanPlot) -->
<!-- lavaanPlot(model=fit, node_options = list(shape = "box", fontname = "Helvetica"), coefs = TRUE) -->
<!-- lavaanPlot(model=fit, node_options = list(shape = "box", fontname = "Helvetica"), coefs = TRUE, sig = .05) -->
<!-- ``` -->
<!-- ## S to I Phonebank DV Mediation -->
<!-- ```{r} -->
<!-- gjg_noCombined <- gjg %>% filter(condition != "mergedScope") -->
<!-- gjg_noCombined <- within(gjg_noCombined, { -->
<!-- structuralNarrative <- ifelse(condition == "populationScope", 1, 0) -->
<!-- }) -->
<!-- model <- ' -->
<!-- # outcome model -->
<!-- phoneYN ~ c*structuralNarrative + b1*youResponsibility + b2*indivResponsibility + b3*manufacturerResponsibility + b4*govResponsibility + b5*indivEfficacy + -->
<!-- b6*studyPolicyEfficacy + b7*compassion + b8*donatingMoral + b9*manufacturerMoral -->
<!-- # mediator models -->
<!-- youResponsibility ~ a1*structuralNarrative -->
<!-- indivResponsibility ~ a2*structuralNarrative -->
<!-- manufacturerResponsibility ~ a3*structuralNarrative -->
<!-- govResponsibility ~ a4*structuralNarrative -->
<!-- indivEfficacy ~ a5*structuralNarrative -->
<!-- studyPolicyEfficacy ~ a6*structuralNarrative -->
<!-- compassion ~ a7*structuralNarrative -->
<!-- donatingMoral ~ a8*structuralNarrative -->
<!-- manufacturerMoral ~ a9*structuralNarrative -->
<!-- # Indirect Effects -->
<!-- youResIDE := a1*b1 -->
<!-- indivResIDE := a2*b2 -->
<!-- manufacturerResIDE := a3*b3 -->
<!-- govResIDE := a4*b4 -->
<!-- indivEffIDE := a5*b5 -->
<!-- studyPolEffIDE := a6*b6 -->
<!-- compassionIDE := a7*b7 -->
<!-- donatingMoralIDE := a8*b8 -->
<!-- manufacturerMoralIDE := a9*b9 -->
<!-- # total effect -->
<!-- total := c + (a1*b1) + (a2*b2) + (a3*b3) + (a4*b4) + (a5*b5) + (a6*b6) + (a7*b7) + -->
<!-- (a8*b8) + (a9*b9) -->
<!-- ' -->
<!-- fit <- sem(model, data = gjg_noCombined) -->
<!-- summary(fit, fit.measures = TRUE, standardized = TRUE, rsquare = TRUE) -->
<!-- summary(lm(phoneYN ~ structuralNarrative, gjg_noCombined)) -->
<!-- summary(lm(phoneYN ~ structuralNarrative + youResponsibility + indivResponsibility + -->
<!-- manufacturerResponsibility + indivEfficacy + studyPolicyEfficacy + compassion -->
<!-- + donatingMoral + manufacturerMoral, gjg_noCombined)) -->
<!-- library(lavaanPlot) -->
<!-- lavaanPlot(model=fit, node_options = list(shape = "box", fontname = "Helvetica"), coefs = TRUE) -->
<!-- lavaanPlot(model=fit, node_options = list(shape = "box", fontname = "Helvetica"), coefs = TRUE, sig = .05) -->
<!-- ``` -->
<!-- ## C to I Policy DV Mediation -->
<!-- ```{r} -->
<!-- gjg_noStructural <- gjg %>% filter(condition != "populationScope") -->
<!-- gjg_noStructural <- within(gjg_noStructural, { -->
<!-- combinedNarrative <- ifelse(condition == "mergedScope", 1, 0) -->
<!-- }) -->
<!-- model <- ' -->
<!-- # outcome model -->
<!-- policyDV ~ c*combinedNarrative + b1*youResponsibility + b2*indivResponsibility + b3*manufacturerResponsibility + b4*govResponsibility + b5*indivEfficacy + -->
<!-- b6*studyPolicyEfficacy + b7*compassion + b8*donatingMoral + b9*manufacturerMoral -->
<!-- #outcome without other mediators -->
<!-- # mediator models -->
<!-- youResponsibility ~ a1*combinedNarrative -->
<!-- indivResponsibility ~ a2*combinedNarrative -->
<!-- manufacturerResponsibility ~ a3*combinedNarrative -->
<!-- govResponsibility ~ a4*combinedNarrative -->
<!-- indivEfficacy ~ a5*combinedNarrative -->
<!-- studyPolicyEfficacy ~ a6*combinedNarrative -->
<!-- compassion ~ a7*combinedNarrative -->
<!-- donatingMoral ~ a8*combinedNarrative -->
<!-- manufacturerMoral ~ a9*combinedNarrative -->
<!-- # Indirect Effects -->
<!-- youResIDE := a1*b1 -->
<!-- indivResIDE := a2*b2 -->
<!-- manufacturerResIDE := a3*b3 -->
<!-- govResIDE := a4*b4 -->
<!-- indivEffIDE := a5*b5 -->
<!-- studyPolEffIDE := a6*b6 -->
<!-- compassionIDE := a7*b7 -->
<!-- donatingMoralIDE := a8*b8 -->
<!-- manufacturerMoralIDE := a9*b9 -->
<!-- # total effect -->
<!-- total := c + (a1*b1) + (a2*b2) + (a3*b3) + (a4*b4) + (a5*b5) + (a6*b6) + (a7*b7) + -->
<!-- (a8*b8) + (a9*b9) -->
<!-- # total indirect effect -->
<!-- totalIDE := (a1*b1) + (a2*b2) + (a3*b3) + (a4*b4) + (a5*b5) + (a6*b6) + (a7*b7) + -->
<!-- (a8*b8) + (a9*b9) -->
<!-- ' -->
<!-- fit <- sem(model, data = gjg_noStructural) -->
<!-- summary(fit, fit.measures = TRUE, standardized = TRUE, rsquare = TRUE) -->
<!-- summary(lm(policyDV ~ combinedNarrative, gjg_noStructural)) -->
<!-- summary(lm(policyDV ~ combinedNarrative + youResponsibility + indivResponsibility + -->
<!-- manufacturerResponsibility + indivEfficacy + studyPolicyEfficacy + compassion -->
<!-- + donatingMoral + manufacturerMoral, gjg_noStructural)) -->
<!-- library(lavaanPlot) -->
<!-- lavaanPlot(model=fit, node_options = list(shape = "box", fontname = "Helvetica"), coefs = TRUE) -->
<!-- lavaanPlot(model=fit, node_options = list(shape = "box", fontname = "Helvetica"), coefs = TRUE, sig = .05) -->
<!-- ``` -->
<!-- ## C to I Phonebank DV Mediation -->
<!-- ```{r} -->
<!-- gjg_noStructural <- gjg %>% filter(condition != "populationScope") -->
<!-- gjg_noStructural <- within(gjg_noStructural, { -->
<!-- combinedNarrative <- ifelse(condition == "mergedScope", 1, 0) -->
<!-- }) -->
<!-- model <- ' -->
<!-- # outcome model -->
<!-- phoneYN ~ c*combinedNarrative + b1*youResponsibility + b2*indivResponsibility + b3*manufacturerResponsibility + b4*govResponsibility + b5*indivEfficacy + -->
<!-- b6*studyPolicyEfficacy + b7*compassion + b8*donatingMoral + b9*manufacturerMoral -->
<!-- # mediator models -->
<!-- youResponsibility ~ a1*combinedNarrative -->
<!-- indivResponsibility ~ a2*combinedNarrative -->
<!-- manufacturerResponsibility ~ a3*combinedNarrative -->
<!-- govResponsibility ~ a4*combinedNarrative -->
<!-- indivEfficacy ~ a5*combinedNarrative -->
<!-- studyPolicyEfficacy ~ a6*combinedNarrative -->
<!-- compassion ~ a7*combinedNarrative -->
<!-- donatingMoral ~ a8*combinedNarrative -->
<!-- manufacturerMoral ~ a9*combinedNarrative -->
<!-- # Indirect Effects -->
<!-- youResIDE := a1*b1 -->
<!-- indivResIDE := a2*b2 -->
<!-- manufacturerResIDE := a3*b3 -->
<!-- govResIDE := a4*b4 -->
<!-- indivEffIDE := a5*b5 -->
<!-- studyPolEffIDE := a6*b6 -->
<!-- compassionIDE := a7*b7 -->
<!-- donatingMoralIDE := a8*b8 -->
<!-- manufacturerMoralIDE := a9*b9 -->
<!-- # total effect -->
<!-- total := c + (a1*b1) + (a2*b2) + (a3*b3) + (a4*b4) + (a5*b5) + (a6*b6) + (a7*b7) + -->
<!-- (a8*b8) + (a9*b9) -->
<!-- ' -->
<!-- fit <- sem(model, data = gjg_noStructural) -->
<!-- summary(fit, fit.measures = TRUE, standardized = TRUE, rsquare = TRUE) -->
<!-- summary(lm(phoneYN ~ combinedNarrative, gjg_noStructural)) -->
<!-- summary(lm(phoneYN ~ combinedNarrative + youResponsibility + indivResponsibility + -->
<!-- manufacturerResponsibility + indivEfficacy + studyPolicyEfficacy + compassion -->
<!-- + donatingMoral + manufacturerMoral, gjg_noStructural)) -->
<!-- library(lavaanPlot) -->
<!-- lavaanPlot(model=fit, node_options = list(shape = "box", fontname = "Helvetica"), coefs = TRUE) -->
<!-- lavaanPlot(model=fit, node_options = list(shape = "box", fontname = "Helvetica"), coefs = TRUE, sig = .05) -->
<!-- library(rstatix) -->
<!-- gjg %>% -->
<!-- group_by(condition) %>% -->
<!-- cor_test(policyDV, youResponsibility, manufacturerResponsibility, studyPolicyEfficacy, manufacturerMoral) -->
<!-- corr.test(gjg[gjg$condition == "individualScope", c(46, 50, 86, 87)], gjg [gjg$condition == "individualScope", 23]) -->
<!-- corr.test(gjg[gjg$condition == "populationScope", c(46, 50, 86, 87)], gjg [gjg$condition == "populationScope", 23]) -->
<!-- summary(lm(policyDV ~ condition + youResponsibility + indivResponsibility + -->
<!-- manufacturerResponsibility + indivEfficacy + studyPolicyEfficacy + compassion -->
<!-- + donatingMoral + manufacturerMoral + pol, gjg_noCombined)) -->
<!-- names(gjg) -->
<!-- gjg$condition -->
<!-- cor_test(iris, "Sepal.Length", "Sepal.Width", partial = TRUE) -->
<!-- cor(youResponsibility, manufacturerResponsibility) -->
<!-- ``` -->
<!-- # SPSP Plot -->
<!-- ```{r} -->
<!-- # First, let's gather the standardized variables into a long format -->
<!-- gjg_z_long <- gjg_z %>% -->
<!-- gather(key = "measure", value = "value", indivEfficacy, govResponsibility, indivResponsibility, manufacturerResponsibility, youResponsibility, compassion, studyPolicyEfficacy) -->
<!-- library(forcats) # for fct_recode -->
<!-- gjg_z_long <- gjg_z_long %>% -->
<!-- mutate(measure = fct_recode(measure, -->
<!-- "Companies" = "manufacturerResponsibility", -->
<!-- "Self" = "youResponsibility", -->
<!-- "US Gov." = "govResponsibility", -->
<!-- "Individuals" = "indivResponsibility", -->
<!-- "Donations" = "indivEfficacy", -->
<!-- "Compassion" = "compassion", -->
<!-- "Policy" = "studyPolicyEfficacy" -->
<!-- )) -->
<!-- gjg_z_long <- gjg_z_long %>% -->
<!-- mutate(measure = factor(measure, levels = rev(c( -->
<!-- "Compassion", -->
<!-- "Self", -->
<!-- "Individuals", -->
<!-- "Companies", -->
<!-- "US Gov.", -->
<!-- "Donations", -->
<!-- "Policy" -->
<!-- )))) -->
<!-- # Update the condition factor with new labels -->
<!-- gjg_z_long$condition <- factor(gjg_z_long$condition, -->
<!-- levels = rev(c("individualScope", "populationScope", "mergedScope")), -->
<!-- labels = rev(c("Individual", "Structural", "Combined"))) -->
<!-- # Custom colors -->
<!-- library(RColorBrewer) -->
<!-- set1_palette <- brewer.pal(n = 3, name = 'Set1') -->
<!-- custom_colors <- c("Individual" = set1_palette[1], -->
<!-- "Structural" = set1_palette[2], -->
<!-- "Combined" = "#800080") -->
<!-- # Custom shapes -->
<!-- custom_shapes <- c("Individual" = 16, "Structural" = 15, "Combined" = 17) -->
<!-- zplot <- ggplot(gjg_z_long, aes(x = measure, y = value, color = condition, shape = condition)) + -->
<!-- stat_summary(fun = mean, geom = "point", position = position_dodge(width = 0.5), size = 3) + -->
<!-- stat_summary(fun.data = mean_cl_normal, geom = "errorbar", -->
<!-- position = position_dodge(width = 0.5), width = 0.2) + -->
<!-- scale_color_manual(values = custom_colors) + -->
<!-- scale_shape_manual(values = custom_shapes) + -->
<!-- coord_flip() + # Use coord_flip to make the measures appear on the y-axis -->
<!-- theme_minimal() + -->
<!-- labs(x = "Measure", y = "Z-Score", title = "", -->
<!-- color = "Narrative Frame", shape = "Narrative Frame") + -->
<!-- theme( -->
<!-- legend.position = "bottom", -->
<!-- legend.text = element_text(size = 20), -->
<!-- legend.title = element_text(size = 20), -->
<!-- plot.title = element_text(size = 35, hjust = 0.5, face = "bold"), -->
<!-- axis.title.y = element_text(face = "plain", size = 25, color = "black"), -->
<!-- axis.title.x = element_text(face = "plain", size = 25, color = "black"), -->
<!-- axis.text.x = element_text(face = "plain", size = 30), -->
<!-- axis.text.y = element_text(face = "plain", size = 30), -->
<!-- panel.border = element_rect(color = "black", fill = NA, size = 1), -->
<!-- legend.key.size = unit(3, "lines") -->
<!-- ) + -->
<!-- theme(panel.spacing = unit(2, "lines")) -->
<!-- # Print the plot -->
<!-- print(zplot) -->
<!-- ggsave("obesitys_mechs.png", plot = zplot, width = 17, height = 10) -->
<!-- ``` -->
<!-- ## Inferential Stats -->
<!-- - Individual & Merged donate more than Structural -->
<!-- ```{r} -->
<!-- variables_to_standardize <- c("usGovHelp", "manufacturerHelp", "individualHelp", "youHelp", "usGovPrevent", "manufacturerPrevent", "individualPrevent", "youPrevent", "upset", "sympathetic", "touched", "donatingMoral", "manufacturerMoral", "manufacturerBlame", "individualBlame", "studyDonationEfficacy", "studyPolicyEfficacy", "donationEfficacy") -->
<!-- gjg$condition <- relevel(gjg$condition, ref = "mergedScope") -->
<!-- gjg_I <- gjg -->
<!-- gjg_I$condition <- relevel(gjg_I$condition, ref = "individualScope") -->
<!-- mod_donation<- lm(donation ~ condition, data = gjg) -->
<!-- summary(mod_donation) -->
<!-- confint(mod_punishingIndividualsEfficacy) -->
<!-- confint(mod_punishingIndividualsEfficacy) -->
<!-- confint(mod_punishingIndividualsEfficacy) -->
<!-- confint(mod_punishingIndividualsEfficacy) -->
<!-- mod_donationI <- lm(donation ~ condition, data = gjg_I) -->
<!-- summary(mod_donationI) -->
<!-- mod_policy<- lm(policyDV ~ condition, data = gjg) -->
<!-- summary(mod_policy) -->
<!-- mod_policyI <- lm(policyDV ~ condition, data = gjg_I) -->
<!-- summary(mod_policyI) -->
<!-- mod_phone <- lm(phoneYN ~ condition, data = gjg) -->
<!-- summary(mod_phone) -->
<!-- mod_phoneI <- lm(phoneYN ~ condition, data = gjg_I) -->
<!-- summary(mod_phoneI) -->
<!-- ``` -->
<!-- # Bonus -->
<!-- ```{r} -->
<!-- bonus_gjg <- gjg_raw %>% filter(attentionCheck == 3, Finished == 1, consent == 8) -->
<!-- bonus_gjg <- bonus_gjg %>% -->
<!-- dplyr::select(PROLIFIC_PID, donation) -->
<!-- view(bonus_gjg) -->
<!-- winners_bonus_gjg <- bonus_gjg[seq(20, nrow(bonus_gjg), 20), ] -->
<!-- # write.csv(winners_bonus_gjg, "BONUS_IS_obesitys2.csv", row.names = FALSE) -->
<!-- ``` -->