#### Libraries
library(stargazer)
library("psych")
library("tidyr")
library(lmerTest)
library(lme4)
library(optimx)
#install.packages("optimx")
library(sjstats)
library(psycho)
library(dplyr)
library(foreign)
library(nlme)
library(sjPlot)
#install.packages("sjPlot")
library(ggplot2)
library(ggeffects)
library("mlVAR")
library("graphicalVAR")
library("qgraph")
library("scales")
library("PerformanceAnalytics")
library("tidyverse")
library("ppcor")
library("igraph")
library("mediation")
library("lavaan")
library("gridExtra")
library("ggcorrplot")
require(plyr)
library(magrittr)
library(kableExtra)
library(viridis)
#• 'Category' is a variable that codes whether the phrase is a 1 = Generalized anxiety phrase, 2 = depressive phrase, or 3 = social anxiety phrase (there are substantially fewer SAD phrases)
#• 'Response.RESP' refers to whether the subject said the word and the sentence either 1 = matched or 3 = did not match
#• 'Type' is a variable that codes whether the word displayed was 1 = non-negative or 2 = negative
wsap <- read.csv("/Users/nikki/Desktop/Research/WSAP/WSAP_uncleaned.csv")
wsap_l <- read.csv("/Users/nikki/Desktop/Research/WSAP/wsap_long_cleaned_outs_72221.csv")
wsap_l <- wsap_l[-c(1)]
wsap_w <- read.csv("/Users/nikki/Desktop/Research/WSAP/wsap_wide_cleaned_outs_72221.csv")
wsap_w <- wsap_w[-c(1)]
trait <- read.csv("/Users/nikki/Desktop/Research/HealthyU_Scanning_Local/Emily_HUresources/WRG Survey/HealthyU_Questionnaires_Masterdata_Wide.csv", header=T)
trait <- trait[c(2,13:18,25:30)]
#EMA and GPS variables
ema <- read.csv("/Users/nikki/Desktop/Research/EMA/HealthyU_EMA_andGPS_onlyEMAdays_AllData.csv")
ema <- ema[c(1,3,8,9,10:19,32,33,46,40,42)]
##Practice Trials
wsap$Response1.RESP <- factor(wsap$Response1.RESP,
labels = c("related","unrelated"),
levels = c(1,3))
prac_wsap <- subset(wsap, wsap$Block ==1)
prac_wsap$Category <- as.factor(as.character(prac_wsap$Category))
#calculate accuracy
prac_wsap$correct <- prac_wsap$Category == prac_wsap$Response1.RESP
#merge back into main data frame
acc <-aggregate(prac_wsap$correct,list(prac_wsap$Subject),mean,na.rm=TRUE)
names(acc)<-c("Subject","prac_acc")
prac_wsap <-merge(prac_wsap,acc,by="Subject")
##Task Trials
#merge practice accuracy scores for exclusion
wsap <- subset(wsap, wsap$Block ==2)
wsap <- merge(wsap,acc,by="Subject")
wsap_lowacc <- subset(wsap, wsap$prac_acc < 0.83) #length(unique(wsap_lowacc$Subject)) = 6 people
#exclude subjects with more than 1/6 incorrect practice trials
wsap <- subset(wsap, wsap$prac_acc >= 0.83) #length(unique(wsap$Subject)) = 71 people
#factorize the responses
wsap$response <- factor(wsap$Response.RESP,
labels = c("related","unrelated"),
levels = c(1,3))
wsap$wordvalence <- factor(wsap$Type_1p_2n,
labels = c("not negative","negative"),
levels = c(1,2))
wsap$Category <- as.numeric(as.character(wsap$Category))
wsap$trialtype <- factor(wsap$Category,
labels = c("gad","dep","sad"),
levels = c(1,2,3))
#reduce dataframe
wsap_longer <- wsap
wsap <- wsap[c(1,2,4,13,18,21,22,20,19)]
# Check and exclude RTs > 3SD: first WITHIN SUBs
grprts <-aggregate(wsap$Response.RT,list(wsap$Subject),mean,na.rm=TRUE)
grprtsds <-aggregate(wsap$Response.RT,list(wsap$Subject),sd,na.rm=TRUE)
names(grprts)<-c("Subject","subrt") #rename variables
names(grprtsds)<-c("Subject","subrtsds") #rename variables
wsap<-merge(wsap,grprts,by="Subject") #merge group means into original data
wsap<-merge(wsap,grprtsds,by="Subject")
wsap$cent_RT<- (wsap$Response.RT-wsap$subrt) # group mean center
wsap$norm_RT<- wsap$cent_RT/wsap$subrtsds # group mean center
length(which(wsap$norm_RT >= 3 | wsap$norm_RT <= -3))
exclude <- which(wsap$norm_RT > 3 | wsap$norm_RT < -3)
wsap_allRTs <- wsap
wsap <- wsap[-c(exclude),]
grprts2 <-aggregate(wsap$Response.RT,list(wsap$Subject),mean,na.rm=TRUE)
names(grprts2)<-c("Subject","subrt2") #rename variables
wsap<-merge(wsap,grprts2,by="Subject") #merge group means into original data
wsap$norm_subrt2 <- (wsap$subrt2- (mean(grprts2$subrt2)))/sd(grprts2$subrt2)
#wsap$Subject[which(wsap$norm_subrt2 > 3)]
wsap_noRTsubjectexl <- wsap
wsap <- wsap[-c(which(wsap$norm_subrt2 > 3)),]
#unique(wsap$Subject) #69 total
#calc outcome of interest
wsap$Threat_end <- ifelse(wsap$wordvalence == "negative" & wsap$response == "related", 1, 0)
wsap$Threat_rej <- ifelse(wsap$wordvalence == "negative" & wsap$response == "unrelated", 1, 0)
wsap$Benign_end <- ifelse(wsap$wordvalence == "not negative" & wsap$response == "related", 1, 0)
wsap$Benign_rej <- ifelse(wsap$wordvalence == "not negative" & wsap$response == "unrelated", 1, 0)
wsap$RT_Threat_end <- ifelse(wsap$wordvalence == "negative" & wsap$response == "related", wsap$Response.RT, NA)
wsap$RT_Threat_rej <- ifelse(wsap$wordvalence == "negative" & wsap$response == "unrelated", wsap$Response.RT, NA)
wsap$RT_Benign_end<- ifelse(wsap$wordvalence == "not negative" & wsap$response == "related", wsap$Response.RT, NA)
wsap$RT_Benign_rej <- ifelse(wsap$wordvalence == "not negative" & wsap$response == "unrelated", wsap$Response.RT, NA)
#subject choice averages and rates
subcount_TE <- as.data.frame(with(wsap, tapply(Threat_end, Subject, sum, na.rm = T)))
subcount_trials <- as.data.frame(with(wsap, tapply(Trial, Subject, length)))
colnames(subcount_TE) <- c("subcount_TE")
colnames(subcount_trials) <- c("subcount_trials")
subcount_TE$subcount_TE_rate <- subcount_TE$subcount_TE/subcount_trials$subcount_trials
subcount_TR <- as.data.frame(with(wsap, tapply(Threat_rej, Subject, sum, na.rm = T)))
colnames(subcount_TR) <- c("subcount_TR")
subcount_TR$subcount_TR_rate <- subcount_TR$subcount_TR/subcount_trials$subcount_trials
subcount_BE <- as.data.frame(with(wsap, tapply(Benign_end, Subject, sum, na.rm = T)))
colnames(subcount_BE) <- c("subcount_BE")
subcount_BE$subcount_BE_rate <- subcount_BE$subcount_BE/subcount_trials$subcount_trials
subcount_BR <- as.data.frame(with(wsap, tapply(Benign_rej, Subject, sum, na.rm = T)))
colnames(subcount_BR) <- c("subcount_BR")
subcount_BR$subcount_BR_rate <- subcount_BR$subcount_BR/subcount_trials$subcount_trials
wsap_rates <- cbind(subcount_TE,subcount_TR,subcount_BE,subcount_BR)
wsap_rates$Subjects <- row.names(wsap_rates)
# d'?
wsap_rates$threat_d <- qnorm(wsap_rates$subcount_BE_rate) - qnorm(wsap_rates$subcount_TE_rate)
subRT_TE <- as.data.frame(with(wsap, tapply(RT_Threat_end, Subject, mean, na.rm = T)))
colnames(subRT_TE) <- c("subRT_TE")
subRT_TR <- as.data.frame(with(wsap, tapply(RT_Threat_rej, Subject, mean, na.rm = T)))
colnames(subRT_TR) <- c("subRT_TR")
subRT_BE <- as.data.frame(with(wsap, tapply(RT_Benign_end, Subject, mean, na.rm = T)))
colnames(subRT_BE) <- c("subRT_BE")
subRT_BR <- as.data.frame(with(wsap, tapply(RT_Benign_rej, Subject, mean, na.rm = T)))
colnames(subRT_BR) <- c("subRT_BR")
wsap_rates2 <- cbind(subRT_TE,subRT_TR,subRT_BE,subRT_BR)
wsap_rates2$Subjects <- row.names(wsap_rates2)
wsap_rates <- merge(wsap_rates, wsap_rates2, by = "Subjects")
#write.csv(wsap, "/Users/nikki/Desktop/Research/WSAP/wsap_long_cleaned_outs_72221.csv")
#write.csv(wsap_rates, "/Users/nikki/Desktop/Research/WSAP/wsap_wide_cleaned_outs_72221.csv")
wsap_spr1 <- spread(wsap_l, trialtype, Threat_end)
wsap_spr2 <- spread(wsap_l, trialtype, Benign_end)
wsap_spr3 <- spread(wsap_l, trialtype, RT_Threat_end)
wsap_spr4 <- spread(wsap_l, trialtype, RT_Benign_end)
wsap_spread <- cbind(wsap_spr1[c(22:24)],wsap_spr2[c(22:24)],wsap_spr3[c(22:24)],wsap_spr4[c(22:24)])
colnames(wsap_spread) <- c("dep_TE", "gad_TE", "sad_TE","dep_BE", "gad_BE", "sad_BE","dep_TE_RT", "gad_TE_RT", "sad_TE_RT","dep_BE_RT", "gad_BE_RT", "sad_BE_RT")
wsap_spread$Subject <- wsap_l$Subject
wsap_spread$trialtype <- wsap_l$trialtype
#subject choice averages and rates
subcount_dep_TE <- as.data.frame(with(wsap_spread, tapply(dep_TE, Subject, sum, na.rm = T)))
colnames(subcount_dep_TE) <- c("subcount_dep_TE")
subcount_gad_TE <- as.data.frame(with(wsap_spread, tapply(gad_TE, Subject, sum, na.rm = T)))
colnames(subcount_gad_TE) <- c("subcount_gad_TE")
subcount_sad_TE <- as.data.frame(with(wsap_spread, tapply(sad_TE, Subject, sum, na.rm = T)))
colnames(subcount_sad_TE) <- c("subcount_sad_TE")
subcount_dep_BE <- as.data.frame(with(wsap_spread, tapply(dep_BE, Subject, sum, na.rm = T)))
colnames(subcount_dep_BE) <- c("subcount_dep_BE")
subcount_gad_BE <- as.data.frame(with(wsap_spread, tapply(gad_BE, Subject, sum, na.rm = T)))
colnames(subcount_gad_BE) <- c("subcount_gad_BE")
subcount_sad_BE <- as.data.frame(with(wsap_spread, tapply(sad_BE, Subject, sum, na.rm = T)))
colnames(subcount_sad_BE) <- c("subcount_sad_BE")
subcount_dep_TE_RT <- as.data.frame(with(wsap_spread, tapply(dep_TE_RT, Subject, mean, na.rm = T)))
colnames(subcount_dep_TE_RT) <- c("subcount_dep_TE_RT")
subcount_gad_TE_RT <- as.data.frame(with(wsap_spread, tapply(gad_TE_RT, Subject, mean, na.rm = T)))
colnames(subcount_gad_TE_RT) <- c("subcount_gad_TE_RT")
subcount_sad_TE_RT <- as.data.frame(with(wsap_spread, tapply(sad_TE_RT, Subject, mean, na.rm = T)))
colnames(subcount_sad_TE_RT) <- c("subcount_sad_TE_RT")
subcount_dep_BE_RT <- as.data.frame(with(wsap_spread, tapply(dep_BE_RT, Subject, mean, na.rm = T)))
colnames(subcount_dep_BE_RT) <- c("subcount_dep_BE_RT")
subcount_gad_BE_RT <- as.data.frame(with(wsap_spread, tapply(gad_BE_RT, Subject, mean, na.rm = T)))
colnames(subcount_gad_BE_RT) <- c("subcount_gad_BE_RT")
subcount_sad_BE_RT <- as.data.frame(with(wsap_spread, tapply(sad_BE_RT, Subject, mean, na.rm = T)))
colnames(subcount_sad_BE_RT) <- c("subcount_sad_BE_RT")
wsap_specific <- cbind(subcount_dep_TE, subcount_gad_TE, subcount_sad_TE, subcount_dep_BE, subcount_gad_BE, subcount_sad_BE, subcount_dep_TE_RT, subcount_gad_TE_RT, subcount_sad_TE_RT, subcount_dep_BE_RT, subcount_gad_BE_RT, subcount_sad_BE_RT)
wsap_specific$Subjects <- wsap_w$Subjects
#wsap_outcomes <- merge(wsap_w, wsap_specific, by = "Subjects")
#subcount_trials <- as.data.frame(with(wsap_l, tapply(Trial, Subject, length)))
#wsap_outcomes$numTrials <- subcount_trials$`with(wsap_l, tapply(Trial, Subject, length))`
#write.csv(wsap_outcomes, "/Users/nikki/Desktop/Research/WSAP/wsap_wide_cleaned_outs_72221.csv")
Subjects see a word for 500ms then they see a sentence and must decide whether the word is “related” or “unrelated” to the sentence
There are 140 trials: 80 depression, 40 general anxiety, 20 social anxiety*
Subjects see every sentence twice, once with a negative/threat word and once with a benign word
“Offline” = choice rates, or the number of times they endorse or reject divided by the possible # of times “Online” = choice reaction time
Thus, choices fall into 1 of 4 categories: Threat Endorse, Threat Reject, Benign Endorse, Benign Reject
wsap_outcomes <- wsap_w
colors <- c("Threat Endorsed" = "lightpink2", "Threat Rejected" = "plum3", "Benign Endorsed" = "lightblue3", "Benign Rejected" = "wheat2")
ggplot(data = wsap_outcomes) +
geom_density(aes(x = subcount_TE_rate, fill = "Threat Endorsed"), alpha = .3) +
geom_density(aes(x = subcount_TR_rate, fill = "Threat Rejected"), alpha = .3) +
geom_density(aes(x = subcount_BE_rate, fill = "Benign Endorsed"), alpha = .3) +
geom_density(aes(x = subcount_BR_rate, fill = "Benign Rejected"), alpha = .3) +
labs(title = "Density of Choice Rates across Sample",
x = "Rate",
y = "Density",
color = "Legend") +
scale_color_manual(values = colors) +
scale_fill_discrete(name = "Type of Choice") +
theme_gray()
ggplot(data = wsap_outcomes) +
geom_histogram(aes(x = threat_d), color = "black", fill = "gold3", binwidth = .10, alpha = .75) +
labs(title = "Distribution of d' for threat detection",
x = "d' (larger + values reflect less sensitivity to threat)",
y = "Count") +
theme_minimal()
colors <- c("Threat Endorsed" = "lightpink2", "Threat Rejected" = "plum3", "Benign Endorsed" = "lightblue3", "Benign Rejected" = "wheat2")
ggplot(data = wsap_outcomes) +
geom_density(aes(x = subRT_TE, fill = "Threat Endorsed"), alpha = .5) +
geom_density(aes(x = subRT_TR, fill = "Threat Rejected"), alpha = .5) +
geom_density(aes(x = subRT_BE, fill = "Benign Endorsed"), alpha = .5) +
geom_density(aes(x = subRT_BR, fill = "Benign Rejected"), alpha = .5) +
labs(title = "Density of Reaction Times for Specific Choices across Sample",
x = "Reaction Time",
y = "Density",
color = "Legend") +
scale_color_manual(values = colors) +
scale_fill_discrete(name = "Type of Choice") +
theme_gray()
wsap_outcomes$subcount_dep_TE_sc <- as.vector(scale(wsap_outcomes$subcount_dep_TE))
wsap_outcomes$subcount_dep_BE_sc <- as.vector(scale(wsap_outcomes$subcount_dep_BE))
wsap_outcomes$subcount_gad_TE_sc <- as.vector(scale(wsap_outcomes$subcount_gad_TE))
wsap_outcomes$subcount_gad_BE_sc <- as.vector(scale(wsap_outcomes$subcount_gad_BE))
wsap_outcomes$subcount_sad_TE_sc <- as.vector(scale(wsap_outcomes$subcount_sad_TE))
wsap_outcomes$subcount_sad_BE_sc <- as.vector(scale(wsap_outcomes$subcount_sad_BE))
keycol <- "trialtype"
valuecol <- "rate"
gathercols <- c("subcount_dep_TE_sc","subcount_gad_TE_sc","subcount_sad_TE_sc","subcount_dep_BE_sc","subcount_gad_BE_sc","subcount_sad_BE_sc")
wsap_outcomes_long <- gather_(wsap_outcomes, keycol, valuecol, gathercols)
wsap_outcomes_long$trialtype <- as.factor(wsap_outcomes_long$trialtype)
ggplot(data = wsap_outcomes_long, aes(x = trialtype, y = rate, fill = trialtype)) +
geom_violin(alpha = .85) +
labs(title = "Distribution of Normalized Endorsement Rates across Trial types",
x = "Types of choices across Trial types",
y = "") +
scale_fill_manual(name="Endorsement x Trial type",
labels=c("Benign/Dep", "Threat/Dep", "Benign/Gad","Threat/Gad","Benign/Sad","Threat/Sad"),
values = c("coral3","lightsalmon1","palegreen4", "palegreen", "skyblue4","skyblue")) +
theme(axis.text.x=element_blank(), axis.ticks.x=element_blank())
var_of_int <- wsap_w[c(27,10,3,5,7,9,15:20,11:14,21:26)]
var_sum <- describe(var_of_int)
var_sum <- round(var_sum , digits=2)
#Knit a lil table
var_sum %>%
kbl() %>%
kable_styling()
vars | n | mean | sd | median | trimmed | mad | min | max | range | skew | kurtosis | se | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
numTrials | 1 | 69 | 137.67 | 1.13 | 138.00 | 137.70 | 1.48 | 135.00 | 140.00 | 5.00 | -0.23 | -0.11 | 0.14 |
threat_d | 2 | 69 | 0.37 | 0.27 | 0.36 | 0.38 | 0.23 | -0.43 | 1.02 | 1.45 | -0.33 | 0.69 | 0.03 |
subcount_TE_rate | 3 | 69 | 0.24 | 0.08 | 0.23 | 0.24 | 0.08 | 0.09 | 0.44 | 0.34 | 0.43 | -0.44 | 0.01 |
subcount_TR_rate | 4 | 69 | 0.26 | 0.08 | 0.27 | 0.26 | 0.08 | 0.06 | 0.41 | 0.35 | -0.40 | -0.36 | 0.01 |
subcount_BE_rate | 5 | 69 | 0.36 | 0.06 | 0.37 | 0.36 | 0.05 | 0.20 | 0.46 | 0.27 | -0.64 | 0.06 | 0.01 |
subcount_BR_rate | 6 | 69 | 0.14 | 0.06 | 0.13 | 0.14 | 0.05 | 0.04 | 0.30 | 0.26 | 0.66 | -0.05 | 0.01 |
subcount_dep_TE | 7 | 69 | 17.19 | 6.40 | 16.00 | 16.82 | 5.93 | 2.00 | 35.00 | 33.00 | 0.52 | 0.30 | 0.77 |
subcount_gad_TE | 8 | 69 | 8.80 | 3.06 | 9.00 | 8.75 | 2.97 | 3.00 | 15.00 | 12.00 | 0.14 | -0.86 | 0.37 |
subcount_sad_TE | 9 | 69 | 6.97 | 2.64 | 7.00 | 6.95 | 2.97 | 2.00 | 12.00 | 10.00 | 0.01 | -1.02 | 0.32 |
subcount_dep_BE | 10 | 69 | 28.07 | 4.52 | 28.00 | 28.30 | 4.45 | 15.00 | 36.00 | 21.00 | -0.39 | -0.20 | 0.54 |
subcount_gad_BE | 11 | 69 | 10.35 | 2.30 | 11.00 | 10.54 | 1.48 | 3.00 | 15.00 | 12.00 | -0.87 | 1.04 | 0.28 |
subcount_sad_BE | 12 | 69 | 11.07 | 2.61 | 12.00 | 11.28 | 1.48 | 4.00 | 15.00 | 11.00 | -0.71 | -0.47 | 0.31 |
subRT_TE | 13 | 69 | 887.67 | 334.60 | 885.50 | 868.66 | 323.15 | 340.53 | 1739.53 | 1399.00 | 0.52 | -0.37 | 40.28 |
subRT_TR | 14 | 69 | 947.81 | 413.32 | 953.63 | 919.19 | 386.56 | 306.03 | 2584.54 | 2278.52 | 1.27 | 3.29 | 49.76 |
subRT_BE | 15 | 69 | 829.35 | 321.64 | 793.26 | 808.99 | 289.35 | 308.45 | 1751.59 | 1443.13 | 0.58 | 0.00 | 38.72 |
subRT_BR | 16 | 69 | 1060.50 | 464.95 | 984.50 | 1023.89 | 432.18 | 360.25 | 2351.47 | 1991.22 | 0.75 | 0.07 | 55.97 |
subcount_dep_TE_RT | 17 | 69 | 913.35 | 379.47 | 880.92 | 887.37 | 395.98 | 321.47 | 1999.89 | 1678.42 | 0.66 | -0.16 | 45.68 |
subcount_gad_TE_RT | 18 | 69 | 831.77 | 354.67 | 774.25 | 797.70 | 338.90 | 334.79 | 2272.40 | 1937.61 | 1.25 | 2.54 | 42.70 |
subcount_sad_TE_RT | 19 | 69 | 897.93 | 420.85 | 811.75 | 855.92 | 391.96 | 283.00 | 2264.50 | 1981.50 | 0.98 | 0.82 | 50.66 |
subcount_dep_BE_RT | 20 | 69 | 843.74 | 331.15 | 848.71 | 819.15 | 318.72 | 303.35 | 1744.47 | 1441.13 | 0.70 | 0.23 | 39.87 |
subcount_gad_BE_RT | 21 | 69 | 830.92 | 374.97 | 802.80 | 810.55 | 393.33 | 271.08 | 1758.82 | 1487.73 | 0.44 | -0.72 | 45.14 |
subcount_sad_BE_RT | 22 | 69 | 791.70 | 322.54 | 746.80 | 769.31 | 323.82 | 278.25 | 1872.43 | 1594.18 | 0.76 | 0.47 | 38.83 |
cordat1 <- wsap_outcomes[c(10,3,5,7,9)]
colnames(cordat1) <- c("d'","Overall Threat Endorse","Overall Threat Reject", "Overall Benign Endorse","Overall Benign Reject")
cormat1 <- correlation(cordat1)
r1 <- as.data.frame(cormat1$values$r)
p1 <- as.data.frame(cormat1$values$p)
p.mat1 <- cor_pmat(cordat1)
ggcorrplot(r1, method = "square", ggtheme = ggplot2::theme_minimal, title = "Correlations between broad, general Choice Rates", show.legend = TRUE, legend.title = "Corr", show.diag = FALSE,
colors = c("skyblue4","white", "palevioletred4"), outline.color = "black",
hc.order = F, hc.method = "pairwise", lab = T,
lab_col = "black", lab_size = 3, p.mat = p.mat1, sig.level = 0.05,
insig = c("pch"), pch = 7, pch.col = "black",
pch.cex = 16, tl.cex = 11, tl.col = "black", tl.srt = 45,
digits = 2)
cordat2 <- wsap_outcomes[c(3,15:26)]
colnames(cordat2) <- c("Overall Threat Endorse","Dep: Threat Endorse","Gad: Threat Endorse","Sad: Threat Endorse","Dep: Benign Endorse", "Gad: Benign Endorse","Sad: Benign Endorse","RT for Dep Threat Endorse","RT for Gad Threat Endorse", "RT for Sad Threat Endorse","RT for Dep Benign Endorse","RT for Gad Benign Endorse", "RT for Sad Benign Endorse")
cormat2 <- correlation(cordat2)
r2 <- as.data.frame(cormat2$values$r)
p2 <- as.data.frame(cormat2$values$p)
p.mat2 <- cor_pmat(cordat2)
ggcorrplot(r2, method = "square", ggtheme = ggplot2::theme_minimal, title = "Correlations between Dx-specific Choice Rates and RTs", show.legend = TRUE, legend.title = "Corr", show.diag = FALSE,
colors = c("skyblue4","white", "palevioletred4"), outline.color = "black",
hc.order = F, hc.method = "pairwise", lab = T,
lab_col = "black", lab_size = 2, p.mat = p.mat2, sig.level = 0.05,
insig = c("pch"), pch = 7, pch.col = "black",
pch.cex = 4, tl.cex = 11, tl.col = "black", tl.srt = 45,
digits = 2)
###Basic Task MLMs CONT.
#Implicit/Online RT
RT_model1 <- lmer(Response.RT ~ wordvalence + trialtype + (1|Subject), data = wsap)
#summary(RT_model1)
tab_model(RT_model1)
Response.RT | |||
---|---|---|---|
Predictors | Estimates | CI | p |
(Intercept) | 916.87 | 836.36 – 997.39 | <0.001 |
wordvalence [not negative] |
-8.66 | -34.57 – 17.24 | 0.512 |
trialtype [gad] | -39.16 | -71.97 – -6.34 | 0.019 |
trialtype [sad] | -65.72 | -98.47 – -32.97 | <0.001 |
Random Effects | |||
σ2 | 414773.13 | ||
τ00 Subject | 108136.13 | ||
ICC | 0.21 | ||
N Subject | 69 | ||
Observations | 9499 | ||
Marginal R2 / Conditional R2 | 0.001 / 0.208 |
#only main effect is depression trials show SLOWER choices
#Adding in more random effects
RT_model2 <- (lmer(Response.RT ~ wordvalence + trialtype + (1 + wordvalence|Subject), data = wsap))
#summary(model2)
#not sig improvement
#anova(RT_model1, RT_model2)
healthyu <- merge(trait, wsap_w, by.x = "id", by.y = "Subjects")
healthyu$threat_d <- qnorm(healthyu$subcount_TE_rate) - qnorm(healthyu$subcount_BE_rate)
healthyu$GADtot_T3_sc <- scale(healthyu$GADtot_T3)
healthyu$PHQ9_tot_T3_sc <- scale(healthyu$PHQ9_tot_T3)
healthyu$SIAS_tot_T3_sc <- scale(healthyu$SIAS_tot_T3)
healthyu$OCIR_tot_T3_sc <- scale(healthyu$OCIR_tot_T3)
healthyu$SIR_tot_T3_sc <- scale(healthyu$SIR_tot_T3)
healthyu$EPSI_tot_T3_sc <- scale(healthyu$EPSI_tot_T3)
a <- ggplot(data = healthyu, aes(x = PHQ9_tot_T3_sc)) +
#geom_histogram(aes(x = PHQ9_tot_T3_sc), binwidth = .25) +
geom_density(fill = "palevioletred2", alpha = .35) +
labs(title = "Density of Depression Symptoms",
x = "Depression Symptoms (PHQ9)",
y = "Density") +
theme_gray() +
theme(plot.title = element_text(size = 8),
axis.title.x = element_text(size = 6))
b <- ggplot(data = healthyu, aes(x = GADtot_T3_sc)) +
#geom_histogram(aes(x = PHQ9_tot_T3_sc), binwidth = .25) +
geom_density(fill = "darkorange2", alpha = .35) +
labs(title = "Density of GAD Symptoms",
x = "General Anxiety Symptoms (GAD7)",
y = "Density") +
theme_gray() +
theme(plot.title = element_text(size = 8),
axis.title.x = element_text(size = 6))
c <- ggplot(data = healthyu, aes(x = SIAS_tot_T3_sc)) +
#geom_histogram(aes(x = PHQ9_tot_T3_sc), binwidth = .25) +
geom_density(fill = "darkgoldenrod2", alpha = .35) +
labs(title = "Density of SAD Symptoms",
x = "Social Anxiety Symptoms (SIAS)",
y = "Density") +
theme_gray() +
theme(plot.title = element_text(size = 8),
axis.title.x = element_text(size = 6))
d <- ggplot(data = healthyu, aes(x = OCIR_tot_T3_sc)) +
#geom_histogram(aes(x = PHQ9_tot_T3_sc), binwidth = .25) +
geom_density(fill = "palegreen2", alpha = .35) +
labs(title = "Density of OC Symptoms",
x = "Obsessive Compulsive Symptoms (OCIR)",
y = "Density") +
theme_gray() +
theme(plot.title = element_text(size = 8),
axis.title.x = element_text(size = 6))
e <- ggplot(data = healthyu, aes(x = SIR_tot_T3_sc)) +
#geom_histogram(aes(x = PHQ9_tot_T3_sc), binwidth = .25) +
geom_density(fill = "deepskyblue2", alpha = .35) +
labs(title = "Density of Hoarding Symptoms",
x = "Hoarding Symptoms (SIR)",
y = "Density") +
theme_gray() +
theme(plot.title = element_text(size = 8),
axis.title.x = element_text(size = 6))
f <- ggplot(data = healthyu, aes(x = EPSI_tot_T3_sc)) +
#geom_histogram(aes(x = PHQ9_tot_T3_sc), binwidth = .25) +
geom_density(fill = "mediumpurple3", alpha = .35) +
labs(title = "Density of Eating Disorder Symptoms",
x = "Eating Disorder Symptoms (EPSI)",
y = "Density") +
theme_gray() +
theme(plot.title = element_text(size = 8),
axis.title.x = element_text(size = 6))
grid.arrange(a,b,c,d,e,f, nrow = 2)
# a <- ggplot(data = healthyu, aes(x = PHQ9_tot_T3_sc)) +
# #geom_histogram(aes(x = PHQ9_tot_T3_sc), binwidth = .25) +
# geom_density(fill = "dodgerblue2", alpha = .35) +
# labs(title = "Density of Despression Symptoms",
# x = "Depression Symptoms (PHQ9)",
# y = "Density") +
# theme_gray() +
# theme(plot.title = element_text(size = 8),
# axis.title.x = element_text(size = 6))
#
# b <- ggplot(data = healthyu, aes(x = GADtot_T3_sc)) +
# #geom_histogram(aes(x = PHQ9_tot_T3_sc), binwidth = .25) +
# geom_density(fill = "skyblue3", alpha = .35) +
# labs(title = "Density of GAD Symptoms",
# x = "General Anxiety Symptoms (GAD7)",
# y = "Density") +
# theme_gray() +
# theme(plot.title = element_text(size = 8),
# axis.title.x = element_text(size = 6))
#
# c <- ggplot(data = healthyu, aes(x = SIAS_tot_T3_sc)) +
# #geom_histogram(aes(x = PHQ9_tot_T3_sc), binwidth = .25) +
# geom_density(fill = "lightblue1", alpha = .35) +
# labs(title = "Density of SAD Symptoms",
# x = "Social Anxiety Symptoms (SIAS)",
# y = "Density") +
# theme_gray() +
# theme(plot.title = element_text(size = 8),
# axis.title.x = element_text(size = 6))
#
# d <- ggplot(data = healthyu, aes(x = OCIR_tot_T3_sc)) +
# #geom_histogram(aes(x = PHQ9_tot_T3_sc), binwidth = .25) +
# geom_density(fill = "mediumseagreen", alpha = .35) +
# labs(title = "Density of OC Symptoms",
# x = "Obsessive Compulsive Symptoms (OCIR)",
# y = "Density") +
# theme_gray() +
# theme(plot.title = element_text(size = 8),
# axis.title.x = element_text(size = 6))
#
# e <- ggplot(data = healthyu, aes(x = SIR_tot_T3_sc)) +
# #geom_histogram(aes(x = PHQ9_tot_T3_sc), binwidth = .25) +
# geom_density(fill = "palegreen3", alpha = .35) +
# labs(title = "Density of Hoarding Symptoms",
# x = "Hoarding Symptoms (SIR)",
# y = "Density") +
# theme_gray() +
# theme(plot.title = element_text(size = 8),
# axis.title.x = element_text(size = 6))
#
# f <- ggplot(data = healthyu, aes(x = EPSI_tot_T3_sc)) +
# #geom_histogram(aes(x = PHQ9_tot_T3_sc), binwidth = .25) +
# geom_density(fill = "darkolivegreen3", alpha = .35) +
# labs(title = "Density of Eating Disorder Symptoms",
# x = "Eating Disorder Symptoms (EPSI)",
# y = "Density") +
# theme_gray() +
# theme(plot.title = element_text(size = 8),
# axis.title.x = element_text(size = 6))
#
# grid.arrange(a,b,c,d,e,f, nrow = 2)
healthyu <- merge(trait, wsap_w, by.x = "id", by.y = "Subjects")
healthyu$threat_d <- qnorm(healthyu$subcount_TE_rate) - qnorm(healthyu$subcount_BE_rate)
healthyu$GADtot_T3_sc <- scale(healthyu$GADtot_T3)
healthyu$PHQ9_tot_T3_sc <- scale(healthyu$PHQ9_tot_T3)
healthyu$SIAS_tot_T3_sc <- scale(healthyu$SIAS_tot_T3)
healthyu$OCIR_tot_T3_sc <- scale(healthyu$OCIR_tot_T3)
healthyu$SIR_tot_T3_sc <- scale(healthyu$SIR_tot_T3)
healthyu$EPSI_tot_T3_sc <- scale(healthyu$EPSI_tot_T3)
gen.wsap.sx <- healthyu[c(40:45,22,15,23,19,25)]
# gen.wsap.sx.fdr <- gen.wsap.sx %>%
# correlation(adjust = "fdr", i_am_cheating = T)
# summary(gen.wsap.sx.fdr)
colnames(gen.wsap.sx) <- c("GAD sx","Dep sx","SAD sx","OC sx","Hoarding sx","Eating sx","d'","Overall Threat Endorse","RT for Threat Endorse", "Overall Benign Endorse","RT for Benign Endorse")
cormat1 <- correlation(gen.wsap.sx)
r1 <- as.data.frame(cormat1$values$r)
p1 <- as.data.frame(cormat1$values$p)
p.mat1 <- cor_pmat(gen.wsap.sx)
ggcorrplot(r1, method = "square", ggtheme = ggplot2::theme_minimal, title = "Correlations b/w Symptoms & General WSAP bias", show.legend = TRUE, legend.title = "Corr", show.diag = FALSE,
colors = c("skyblue4","white", "palevioletred4"), outline.color = "black",
hc.order = F, hc.method = "pairwise", lab = T,
lab_col = "black", lab_size = 2, p.mat = p.mat1, sig.level = 0.05,
insig = c("pch"), pch = 7, pch.col = "black",
pch.cex = 8, tl.cex = 10, tl.col = "black", tl.srt = 45,
digits = 2)
#"dodgerblue2","skyblue3","lightblue1","mediumseagreen","palegreen3","darkolivegreen3"
#TE <- ggplot(data = healthyu) +
# geom_point(aes(x = threat_d, y = GADtot_T3_sc), color = "skyblue3", alpha=0.35,) +
# geom_point(aes(x = threat_d, y = PHQ9_tot_T3_sc), color = "dodgerblue2",alpha=0.35,) +
# geom_point(aes(x = threat_d, y = OCIR_tot_T3_sc), color = "mediumseagreen",alpha=0.35,) +
# geom_point(aes(x = threat_d, y = SIR_tot_T3_sc), color = "palegreen3",alpha=0.35,) +
# geom_point(aes(x = threat_d, y = EPSI_tot_T3_sc), color = "darkolivegreen3",alpha=0.35,) +
# geom_point(aes(x = threat_d, y = SIAS_tot_T3_sc), color = "lightblue1",alpha=0.35,) +
# geom_smooth(aes(x = threat_d, y = GADtot_T3_sc), color = "skyblue3", size = 1, alpha=0.25, method = "lm", se = F) +
# geom_smooth(aes(x = threat_d, y = PHQ9_tot_T3_sc), color = "dodgerblue2", size = 1, alpha=0.25, method = "lm", se = F) +
# geom_smooth(aes(x = threat_d, y = OCIR_tot_T3_sc), color = "mediumseagreen", size = 1, alpha=0.25, method = "lm", se = F) +
# geom_smooth(aes(x = threat_d, y = SIR_tot_T3_sc), color = "palegreen3", size = 1, alpha=0.25, method = "lm", se = F) +
# geom_smooth(aes(x = threat_d, y = EPSI_tot_T3_sc), color = "darkolivegreen3", size = 1, alpha=0.25, method = "lm", se = F) +
# geom_smooth(aes(x = threat_d, y = SIAS_tot_T3_sc), color = "lightblue1", size = 1, alpha=0.25, method = "lm", se = F) +
# labs(title= "Significant associations between threat endorsement and all symptom measures", x = "Sensitivity to Threat Words", y = "Symptom Measures")+
# theme_minimal()
#
# TE
TE <- ggplot(data = healthyu) +
geom_point(aes(x = threat_d, y = GADtot_T3_sc), color = "darkorange2", alpha=0.35,) +
geom_point(aes(x = threat_d, y = PHQ9_tot_T3_sc), color = "palevioletred2",alpha=0.35,) +
geom_point(aes(x = threat_d, y = OCIR_tot_T3_sc), color = "palegreen2",alpha=0.35,) +
geom_point(aes(x = threat_d, y = SIR_tot_T3_sc), color = "deepskyblue2",alpha=0.35,) +
geom_point(aes(x = threat_d, y = EPSI_tot_T3_sc), color = "mediumpurple3",alpha=0.35,) +
geom_point(aes(x = threat_d, y = SIAS_tot_T3_sc), color = "darkgoldenrod2",alpha=0.35,) +
geom_smooth(aes(x = threat_d, y = GADtot_T3_sc), color = "darkorange2", size = 1, alpha=0.25, method = "lm", se = F) +
geom_smooth(aes(x = threat_d, y = PHQ9_tot_T3_sc), color = "palevioletred2", size = 1, alpha=0.25, method = "lm", se = F) +
geom_smooth(aes(x = threat_d, y = OCIR_tot_T3_sc), color = "palegreen2", size = 1, alpha=0.25, method = "lm", se = F) +
geom_smooth(aes(x = threat_d, y = SIR_tot_T3_sc), color = "deepskyblue2", size = 1, alpha=0.25, method = "lm", se = F) +
geom_smooth(aes(x = threat_d, y = EPSI_tot_T3_sc), color = "mediumpurple3", size = 1, alpha=0.25, method = "lm", se = F) +
geom_smooth(aes(x = threat_d, y = SIAS_tot_T3_sc), color = "darkgoldenrod2", size = 1, alpha=0.25, method = "lm", se = F) +
labs(title= "Significant associations between threat endorsement and all symptom measures", x = "Sensitivity to Threat Words", y = "Symptom Measures")+
theme_minimal()
TE
#cor.test(healthyu$GADtot_T3,healthyu$threat_d)
#cor.test(healthyu$PHQ9_tot_T3,healthyu$threat_d)
#cor.test(healthyu$OCIR_tot_T3,healthyu$threat_d)
#cor.test(healthyu$SIAS_T3,healthyu$threat_d)
#cor.test(healthyu$EPSI_tot_T3,healthyu$threat_d)
#cor.test(healthyu$SIAS_tot_T3,healthyu$threat_d)
TE_RT <- ggplot(data = healthyu) +
geom_point(aes(x = subRT_TE, y = GADtot_T3_sc), color = "darkorange2", alpha=0.35,) +
geom_point(aes(x = subRT_TE, y = PHQ9_tot_T3_sc), color = "palevioletred2",alpha=0.35,) +
geom_point(aes(x = subRT_TE, y = OCIR_tot_T3_sc), color = "palegreen2",alpha=0.35,) +
geom_point(aes(x = subRT_TE, y = SIR_tot_T3_sc), color = "deepskyblue2",alpha=0.35,) +
geom_point(aes(x = subRT_TE, y = EPSI_tot_T3_sc), color = "mediumpurple3",alpha=0.35,) +
geom_point(aes(x = subRT_TE, y = SIAS_tot_T3_sc), color = "darkgoldenrod2",alpha=0.35,) +
geom_smooth(aes(x = subRT_TE, y = GADtot_T3_sc), color = "darkorange2", size = 1, alpha=0.25, method = "lm", se = F) +
geom_smooth(aes(x = subRT_TE, y = PHQ9_tot_T3_sc), color = "palevioletred2", size = 1, alpha=0.25, method = "lm", se = F) +
geom_smooth(aes(x = subRT_TE, y = OCIR_tot_T3_sc), color = "palegreen2", size = 2, alpha=0.25, method = "lm", se = F) +
geom_smooth(aes(x = subRT_TE, y = SIR_tot_T3_sc), color = "deepskyblue2", size = 1, alpha=0.25, method = "lm", se = F) +
geom_smooth(aes(x = subRT_TE, y = EPSI_tot_T3_sc), color = "mediumpurple3", size = 1, alpha=0.25, method = "lm", se = F) +
geom_smooth(aes(x = subRT_TE, y = SIAS_tot_T3_sc), color = "darkgoldenrod2", size = 1, alpha=0.25, method = "lm", se = F) +
labs(title= "No significant associations b/w RT for threat endorsement and symptoms",
x = "RT for Threat Words Endorsed", y = "Symptom Measures")+
theme_minimal()
TE_RT
# task <- healthyu[c(1,22,15,19,23,25)]
# sx <- healthyu[c(1,40:45)]
# keycol <- "sx_type"
# valuecol <- "sx_score"
# gathercols <- c("GADtot_T3_sc","PHQ9_tot_T3_sc","SIAS_tot_T3_sc","OCIR_tot_T3_sc",
# "SIR_tot_T3_sc","EPSI_tot_T3_sc")
# sx_l <- gather_(sx, keycol, valuecol, gathercols)
#
# wsap_sx <- merge(sx_l,task,by = "id")
#
# model1 <- (lmer(sx_score ~ sx_type + subcount_TE_rate + (1 | id), data = wsap_sx))
# summary(model1)
#
# model4 <- (lmer(threat_d ~ wordvalence + trialtype + (1 + wordvalence|Subject), data = wsap))
# prep EMA data
grpmeans<-aggregate(ema$NA_Mean_new,list(ema$subid),mean,na.rm=TRUE)
names(grpmeans)<-c("Subject","ema_avg_na") #rename variables
grpmeans_pa<-aggregate(ema$PA_Mean_tri,list(ema$subid),mean,na.rm=TRUE)
names(grpmeans_pa)<-c("Subject","ema_avg_pa") #rename variables
ema_means <-merge(grpmeans,grpmeans_pa,by="Subject") #merge group means into original data
grpmeans_str<-aggregate(ema$allstress,list(ema$subid),mean,na.rm=TRUE)
names(grpmeans_str)<-c("Subject","ema_all_str") #rename variables
ema_means <-merge(ema_means,grpmeans_str,by="Subject") #merge group means into original data
grpmeans_ent<-aggregate(ema$entropy_sameday,list(ema$subid),mean,na.rm=TRUE)
names(grpmeans_ent)<-c("Subject","ema_entropy") #rename variables
ema_means <-merge(ema_means,grpmeans_ent,by="Subject") #merge group means into original data
grpmeans_soc<-aggregate(ema$SocConnect ,list(ema$subid),mean,na.rm=TRUE)
names(grpmeans_soc)<-c("Subject","ema_soc") #rename variables
ema_means <-merge(ema_means,grpmeans_soc,by="Subject") #merge group means into original data
## now suppose we want to extract the coefficients by group
func <- function(ema)
{
return(data.frame(nastress = cor(ema$NA_Mean_new, ema$allstress, use = "pairwise.complete.obs")))
}
nastress2 <- ddply(ema, .(subid), func)
ema_means <- merge(ema_means,nastress2,by.x = "Subject", by.y = "subid", all.x = T)
ema_wsap <- merge(healthyu, ema_means, by.x = "id", by.y = "Subject", all = T)
ema_wsap$ema_all_str_resc <- scales::rescale(ema_wsap$ema_all_str, to = c(0,100), from = c(6,42))
ggplot(data = ema_wsap) +
geom_density(aes(x = ema_all_str_resc),fill = "darkolivegreen3", alpha = .5) +
geom_density(aes(x = ema_avg_na),fill = "mediumpurple3", alpha = .5) +
geom_density(aes(x = ema_avg_pa),fill = "gold3", alpha = .5) +
labs(title = "Density of EMA Metrics",
x = "Stress (green) Negative Affect (purple) Positive Affect (gold)",
y = "Density") +
theme_classic()
#Does the WSAP bias predict daily affect and stress in daily life?
cordata <- ema_wsap[,c(22,15,49:51,54)]
cormat1 <- correlation(cordata, adjust = "fdr")
p.mat1 <- cor_pmat(cordata)
r1 <- as.data.frame(cormat1$values$r)
p1 <- as.data.frame(cormat1$values$p)
p.mat1 <- cor_pmat(cordata)
ggcorrplot(r1, method = "square", ggtheme = ggplot2::theme_minimal, title = "Correlations b/w EMA & Broad WSAP bias", show.legend = TRUE, legend.title = "Corr", show.diag = FALSE,
colors = c("skyblue4","white", "palevioletred4"), outline.color = "black",
hc.order = F, hc.method = "pairwise", lab = T,
lab_col = "black", lab_size = 2, p.mat = p.mat1, sig.level = 0.05,
insig = c("pch"), pch = 7, pch.col = "black",
pch.cex = 14, tl.cex = 10, tl.col = "black", tl.srt = 45,
digits = 2)
#stargazer(correlation.matrix,type = "html", p.auto = T, title="Correlation Matrix")
- Social Anx.-related Benign Endorsement is related to MORE average daily Positive Affect & LESS stress