1 Study 1
Create a dataset with data from Study 1
<-Data_Study1_Raw %>% filter(CCA==1 & Attention_check==1) Data_Study1_Wide
Transform the data in long format to run GEE
<-Data_Study1_Wide %>%
Data_Study1_Longpivot_longer(
c(
"Submarine_1",
"Trespassers_1",
"Hostages_1",
"Liferaft_1",
"PlaneCrash_1",
"PrisWar_1",
"Spelunkers_1",
"Soldier_1",
"Surgery_1",
"Footbridge_1",
"Cryingbaby_1"),
names_to = "Scenario", values_to = "Moral")
$Trial<-rep(1:11, times=length(Data_Study1_Wide$Age)) Data_Study1_Long
1.1 Data analysis
Run Generalized Estimating Equations (GEE) for each sleep variable (IV) on moral judgments (DV)
<-geeglm(Moral~SleepQualCro, family=gaussian, id=ResponseId, corstr="exchangeable", Data_Study1_Long)
GEE_SleepQualCroS1<-geeglm(Moral~SleepQualAcu, family=gaussian, id=ResponseId, corstr="exchangeable", Data_Study1_Long)
GEE_SleepQualAcuS1<-geeglm(Moral~SleepQuantCro, family=gaussian, id=ResponseId, corstr="exchangeable", Data_Study1_Long)
GEE_SleepQuantCroS1<-geeglm(Moral~SleepQuantAcu, family=gaussian, id=ResponseId, corstr="exchangeable", Data_Study1_Long) GEE_SleepQuantAcuS1
Extract coefficients (unstandardized slopes, standard errors and p-values) from GEE models
#Chronic Sleep Quality
<-round(summary(GEE_SleepQualCroS1)$coefficients[2,1], digit=2)
bGEEQualCroS1<- round(summary(GEE_SleepQualCroS1)$coefficients[2,2] , digit=2)
SEGEEQualCroS1<- round(ifelse(summary(GEE_SleepQualCroS1)$coefficients[2,4]*4<.99, summary(GEE_SleepQualCroS1)$coefficients[2,4]*4, .99), digit=2)
pGEEQualCroS1
#Acute Sleep Quality
<- round(summary(GEE_SleepQualAcuS1)$coefficients[2,1] , digit=2)
bGEEQualAcuS1<- round(summary(GEE_SleepQualAcuS1)$coefficients[2,2] , digit=2)
SEGEEQualAcuS1 <- round(ifelse(summary(GEE_SleepQualAcuS1)$coefficients[2,4]*4<.99, summary(GEE_SleepQualAcuS1)$coefficients[2,4]*4, .99), digit=2)
pGEEQualAcuS1
#Chronic Sleep Quantity
<- round(summary(GEE_SleepQuantCroS1)$coefficients[2,1] , digit=2)
bGEEQuantCroS1<- round(summary(GEE_SleepQuantCroS1)$coefficients[2,2] , digit=2)
SEGEEQuantCroS1 <- round(ifelse(summary(GEE_SleepQuantCroS1)$coefficients[2,4]*4<.99, summary(GEE_SleepQuantCroS1)$coefficients[2,4]*4, .99), digit=2)
pGEEQuantCroS1
#Acute Sleep Quantity
<- round(summary(GEE_SleepQuantAcuS1)$coefficients[2,1] , digit=2)
bGEEQuantAcuS1<- round(summary(GEE_SleepQuantAcuS1)$coefficients[2,2] , digit=2)
SEGEEQuantAcuS1 <- round(ifelse(summary(GEE_SleepQuantAcuS1)$coefficients[2,4]*4<.99, summary(GEE_SleepQuantAcuS1)$coefficients[2,4]*4, .99), digit=2) pGEEQuantAcuS1
Create datasets to display GEE summary in plots
<- paste0("b=",bGEEQualCroS1,", ", "SE=",SEGEEQualCroS1,", ","p=",pGEEQualCroS1)
ResumGEEQualCroS1<- paste0("b=",bGEEQualAcuS1,", ", "SE=",SEGEEQualAcuS1,", ","p=",pGEEQualAcuS1)
ResumGEEQualAcuS1<- paste0("b=",bGEEQuantCroS1,", ", "SE=",SEGEEQuantCroS1,", ","p=",pGEEQuantCroS1)
ResumGEEQuantCroS1<- paste0("b=",bGEEQuantAcuS1,", ", "SE=",SEGEEQuantAcuS1,", ","p=",pGEEQuantAcuS1)
ResumGEEQuantAcuS1
<- data.frame(x = 5.5, y = 100, label = ResumGEEQualCroS1)
annotationQualCroS1 <- data.frame(x = 5.5, y = 100, label = ResumGEEQualAcuS1)
annotationQualAcuS1 <- data.frame(x = 5.5, y = 100, label = ResumGEEQuantCroS1)
annotationQuantCroS1 <- data.frame(x = 5.5, y = 100, label = ResumGEEQuantAcuS1)
annotationQuantAcuS1 <-cbind(
annotationS1rbind(annotationQualCroS1,
annotationQualAcuS1,
annotationQuantCroS1,
annotationQuantAcuS1),SleepType=c(
"Quality of Chronic Sleep",
"Quality of Acute Sleep",
"Quantity of Chronic Sleep",
"Quantity of Acute Sleep"))
Prepare data for plots
<- Data_Study1_Wide %>%
Data_PlotS1pivot_longer(
cols=c(SleepQualCro, SleepQualAcu, SleepQuantCro, SleepQuantAcu),
names_to="SleepType") %>%
rename("SleepValue"=value) %>%
mutate(
SleepLength=case_when(
=="SleepQualCro" | SleepType=="SleepQuantCro"~"Chronic",
SleepType=="SleepQualAcu" | SleepType=="SleepQuantAcu"~"Acute"),
SleepTypeSleepQuanthist=case_when(
=="SleepQualCro" | SleepType=="SleepQualAcu"~"Sleep Quality",
SleepType=="SleepQuantCro" | SleepType=="SleepQuantAcu"~"Sleep Quantity"))
SleepType
$SleepType<-dplyr::recode(Data_PlotS1$SleepType,
Data_PlotS1"SleepQualCro" = "Quality of Chronic Sleep",
"SleepQualAcu" = "Quality of Acute Sleep",
"SleepQuantCro" = "Quantity of Chronic Sleep",
"SleepQuantAcu" = "Quantity of Acute Sleep")
1.2 Summary of Study 1 results
Put results in a table
<-c("Quality Chronic","Quality Acute","Quantity Chronic","Quantity Acute")
SleepMarker<-c(bGEEQualCroS1,bGEEQualAcuS1,bGEEQuantCroS1,bGEEQuantAcuS1)
bGEES1<-c(SEGEEQualCroS1,SEGEEQualAcuS1,SEGEEQuantCroS1,SEGEEQuantAcuS1)
SEGEES1<-c(pGEEQualCroS1,pGEEQualAcuS1,pGEEQuantCroS1,pGEEQuantAcuS1)
pvalGEES1<-c(length(GEE_SleepQualCroS1$fitted.values)/11,
NS1length(GEE_SleepQualAcuS1$fitted.values)/11,
length(GEE_SleepQuantCroS1$fitted.values)/11,
length(GEE_SleepQuantAcuS1$fitted.values)/11)
<-data.frame("Sleep Indicator"=SleepMarker, "Unstandardized Slope"=bGEES1, "Standard Errors"=SEGEES1, "p values"=pvalGEES1, "N"=NS1)
ResultsStudy1gt(ResultsStudy1)
Sleep.Indicator | Unstandardized.Slope | Standard.Errors | p.values | N |
---|---|---|---|---|
Quality Chronic | 0.03 | 0.11 | 0.99 | 122 |
Quality Acute | 0.11 | 0.10 | 0.99 | 122 |
Quantity Chronic | 0.00 | 0.19 | 0.99 | 122 |
Quantity Acute | 0.14 | 0.17 | 0.99 | 122 |
1.3 Plot Study 1 results
Plot distribution for each sleep indicator
<-ggplot(Data_PlotS1, aes(x=SleepValue, fill=SleepLength)) +
DistQualityS1geom_density(alpha=0.5, size=0.5,adjust = 2) +
scale_fill_manual(values=c("#193B94", "#BDCAEE", "#193B94", "#BDCAEE")) +
theme_bw() +
ylab("Density") + xlab("") +
facet_wrap(~SleepQuanthist, scale="free_x") +
guides(fill=guide_legend("Sleep Length")) +
theme(
axis.title.y = element_text(size = 11, hjust = 0.5, face="bold"),
axis.title.x = element_text(face="bold", size = 11, hjust = 0.5),
legend.position="top",
legend.title = element_text(colour="black", size=10, face="bold"))
DistQualityS1
Plot distribution of the scores to the sacrificial dilemmas
<-ggplot(Data_Study1_Raw, aes(x=Moral_DIL, fill="#193B94")) +
DistMoralS1geom_density(alpha=0.5, size=0.5,adjust = 2) +
theme_bw() +
ylab("Density") + xlab("Sacrificial Dilemmas") +
guides(fill="none") +
theme(
axis.title.y = element_text(size = 11, hjust = 0.5, face="bold"),
axis.title.x = element_text(face="bold", size = 11, hjust = 0.5))
DistMoralS1
Scatterplots
ggplot(Data_PlotS1, aes(x=SleepValue, y=Moral_DIL)) +
geom_jitter(alpha=0.6, color="#545454", size=1.2) +
geom_smooth(method="lm") +
facet_wrap(~SleepType, nrow = 2, ncol = 2, scales="free_x") +
theme_bw() + ylab("Utilitirianism") + xlab("") +
theme(axis.title.y = element_text(size = 11, hjust = 0.5, face="bold"),
axis.title.x = element_text(face="bold", size = 11, hjust = 0.5)) +
guides(size=FALSE, colour=FALSE, fill=FALSE) +
geom_label(data=annotationS1, aes( x=x, y=y, label=label),
color="black", size=3.5 , angle=45, alpha=7/10, inherit.aes = FALSE)
## `geom_smooth()` using formula 'y ~ x'