Chapter 6 outcome_rating ~ cue * stim
6.1 What is the purpose of this notebook?
Here, I plot the outcome ratings as a function of cue and stimulus intensity.
* Main model: lmer(outcome_rating ~ cue * stim)
* Main question: do outcome ratings differ as a function of cue type and stimulus intensity?
* If there is a main effect of cue on outcome ratings, does this cue effect differ depending on task type?
* Is there an interaction between the two factors?
* IV:
- cue (high / low)
- stim (high / med / low)
* DV: outcome rating
6.2 model 03 iv-cuecontrast dv-actual
## common dir for saving plots and model outputs
<- file.path(
analysis_dir "analysis",
main_dir, "mixedeffect", "model04_iv-cuecontrast_dv-outcome", as.character(Sys.Date()))
dir.create(analysis_dir, recursive = TRUE, showWarnings = FALSE)
for (taskname in c("pain", "vicarious", "cognitive")) {
<- "src_subject_id"
subject_varkey <- "param_cue_type"; iv_keyword <- "cue"
iv <- "event04_actual_angle"
dv <- "actual"
dv_keyword <- "subject"
subject <- ""
xlab <- "ratings (degree)"
ylab <- "sub-0001|sub-0003|sub-0004|sub-0005|sub-0025|sub-0999"
exclude <- 10
w <- 6
h <- file.path(
model_savefname
analysis_dir,paste("lmer_task-", taskname, "_cue_on_rating-", dv_keyword, "_",
as.character(Sys.Date()), ".txt",
sep = ""
)
)# ___ 1) load data _______________________________________________________________ # nolint
<- load_task_social_df(datadir, taskname, subject_varkey, iv, dv, exclude)
data unique(data$src_subject_id)
$subject <- factor(data$src_subject_id)
data
# ___ 2) mixed effects model _____________________________________________________ # nolint
<- lmer_onefactor_cooksd(
cooksd df = data, taskname, iv, dv, subject_keyword = subject, dv_keyword, model_savefname, print_lmer_output=FALSE
)<- as.numeric(names(cooksd)[
influential > (4 / as.numeric(length(unique(data$subject)))))
(cooksd
])<- data[-influential, ]
data_screen
# ___ 3) calculate difference scores and summarize _______________________________ # nolint
# TODO: within param_run_num
$run_order[data$param_run_num > 3] <- "a"
data$run_order[data$param_run_num <= 3] <- "b"
data<- subset(data, select = c(
sub_diff "subject", "session_id", "run_order",
"param_task_name", "param_cue_type",
"param_stimulus_type", dv
))<- meanSummary(sub_diff, c(
subjectwise "subject", "session_id", "run_order",
"param_task_name", "param_cue_type",
"param_stimulus_type"
), dv)<- subjectwise[1:(length(subjectwise) - 1)]
mean_actual <- mean_actual %>%
wide spread(param_cue_type, mean_per_sub)
$diff <- wide$high_cue - wide$low_cue
wide$stim_name[wide$param_stimulus_type == "high_stim"] <- "high"
wide$stim_name[wide$param_stimulus_type == "med_stim"] <- "med"
wide$stim_name[wide$param_stimulus_type == "low_stim"] <- "low"
wide$stim_ordered <- factor(wide$stim_name,
widelevels = c("low", "med", "high")
)
<- meanSummary(wide, c("subject", "stim_ordered"), "diff")
subjectwise_diff $stim_ordered <- factor(subjectwise_diff$stim_ordered,
subjectwise_difflevels = c("low", "med", "high")
)<- summarySEwithin(
groupwise_diff data = subjectwise_diff,
measurevar = "mean_per_sub", # variable created from above
withinvars = c("stim_ordered"), # iv
idvar = "subject"
)
# ___ 4) plot ____________________________________________________________________ # nolint
# 4-1. parameters ______________________________________________________________ # nolint
<- subjectwise_diff
subjectwise <- groupwise_diff
groupwise <- "stim_ordered"
iv <- "mean_per_sub"
subject_mean <- "mean_per_sub_norm_mean"
group_mean <- "se"
p1.se <- "subject"
subject if (any(startsWith(taskname, c("pain", "Pain")))) { # red
<- c("#B7021E", "#B7021E", "#B7021E")
color else if (any(startsWith(taskname, c("vicarious", "Vicarious")))) { # green
} <- c("#22834A", "#22834A", "#22834A")
color else if (any(startsWith(taskname, c("cognitive", "Cognitive")))) { # blue
} <- c("#0237C9", "#0237C9", "#0237C9")
color
}
# 4-2. plot rain cloud plots ____________________________________________________ # nolint
<- ""
p1.xlab <- "Cue effect \n(actual ratings of high > low cue)"
p1.ylab <- c()
ylim <- paste(taskname, " - actual judgment (degree)")
p1.ggtitle <- paste(taskname, " - actual")
p1.title <- file.path(
p1.save_fname
analysis_dir,paste("raincloud_task-", taskname, "_rating-",
"-cuecontrast_", as.character(Sys.Date()), ".png",
dv_keyword, sep = ""
)
)= "cuecontrast"
dv_keyword = c(-75,75)
ylim <- plot_rainclouds_onefactor(
g
subjectwise, groupwise, iv, subject_mean, group_mean, p1.se,
subject, p1.ggtitle, p1.title, p1.xlab, p1.ylab, taskname, ylim,
w, h, dv_keyword, color, p1.save_fname
)<- g + geom_hline(yintercept = 0, size = 0.5, linetype = "dashed")
g ggsave(p1.save_fname, plot = g)
# 4-3. plot geom range _________________________________________________________ # nolint
<- "sd" # se, sd, ci
p2.se <- "stimulus intensity"
p2.xlab <- "Cue effect \n(actual ratings of high > low cue)"
p2.ylab <- paste(taskname, " - cue effect per stimulus intensity", sep = "")
p2.ggtitle <- 5
w <- 5
h <- file.path(
p2.save_fname
analysis_dir,paste("cueeffect_task-", taskname, "_rating-", dv_keyword, "_",
as.character(Sys.Date()), ".png",
sep = ""
)
)<- plot_geompointrange_onefactor(
r
subjectwise, groupwise, iv,
subject_mean, group_mean, p2.se,
p2.xlab, p2.ylab, color, p2.ggtitle, w, h, p2.save_fname
)<- r + geom_hline(yintercept = 0, size = 1, linetype = "dashed")
r ggsave(p2.save_fname, plot = r)
}
## Warning in geom_line(data = subjectwise, aes(group = .data[[subject]], y
## = .data[[subjectwise_mean]], : Ignoring unknown aesthetics: fill
## Warning: Removed 1 rows containing non-finite values (`stat_ydensity()`).
## Warning: Removed 1 rows containing non-finite values (`stat_boxplot()`).
## Warning: Using the `size` aesthietic with geom_polygon was deprecated in ggplot2 3.4.0.
## ℹ Please use the `linewidth` aesthetic instead.
## Warning: Removed 1 row containing missing values (`geom_line()`).
## Warning: Removed 1 rows containing missing values (`geom_point()`).
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## Saving 7 x 5 in image
## Warning: Removed 1 rows containing non-finite values (`stat_ydensity()`).
## Warning: Removed 1 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 1 row containing missing values (`geom_line()`).
## Warning: Removed 1 rows containing missing values (`geom_point()`).
## Warning: The `<scale>` argument of `guides()` cannot be `FALSE`. Use "none" instead as
## of ggplot2 3.3.4.
## Saving 7 x 5 in image
## Warning: Removed 1 rows containing missing values (`geom_point()`).
## Warning: Removed 3 rows containing missing values (`geom_pointrange()`).
## Warning in geom_line(data = subjectwise, aes(group = .data[[subject]], y
## = .data[[subjectwise_mean]], : Ignoring unknown aesthetics: fill
## Warning: Removed 1 rows containing non-finite values (`stat_ydensity()`).
## Warning: Removed 1 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 1 rows containing missing values (`geom_point()`).
## Saving 7 x 5 in image
## Warning: Removed 1 rows containing non-finite values (`stat_ydensity()`).
## Warning: Removed 1 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 1 rows containing missing values (`geom_point()`).
## Saving 7 x 5 in image
## Warning: Removed 1 rows containing missing values (`geom_point()`).
## Warning: Removed 3 rows containing missing values (`geom_pointrange()`).
## Warning in geom_line(data = subjectwise, aes(group = .data[[subject]], y
## = .data[[subjectwise_mean]], : Ignoring unknown aesthetics: fill
## Saving 7 x 5 in image
## Saving 7 x 5 in image
r
6.2.2 model 04 iv-cue-stim dv-actual
<- data.frame()
combined_se_calc_cooksd <- file.path(
analysis_dir
main_dir,"analysis", "mixedeffect", "model05_iv-cue-stim_dv-actual",as.character(Sys.Date())
)dir.create(analysis_dir, showWarnings = FALSE, recursive = TRUE)
# 1. [ PARAMETERS ] __________________________________________________ # nolint
<- "actual"
dv_keyword <- ""
xlab <- "judgment (degree)"
ylab for (taskname in c("pain", "vicarious", "cognitive")) {
<- paste(taskname, " - actual judgment (degree)")
ggtitle <- paste(taskname, " - actual")
title <- "subject"
subject
<- load_task_social_df(datadir,
data taskname = taskname,
subject_varkey = "src_subject_id",
iv = "param_cue_type",
dv = "event04_actual_angle",
exclude = "sub-0001|sub-0003|sub-0004|sub-0005|sub-0025|sub-0999"
)
<- 10
w <- 6
h
# [ CONTRASTS ] ________________________________________________________________________________ # nolint
# contrast code ________________________________________
$stim[data$event03_stimulus_type == "low_stim"] <- -0.5 # social influence task
data$stim[data$event03_stimulus_type == "med_stim"] <- 0 # no influence task
data$stim[data$event03_stimulus_type == "high_stim"] <- 0.5 # no influence task
data
$stim_factor <- factor(data$event03_stimulus_type)
data
# contrast code 1 linear
$stim_con_linear[data$event03_stimulus_type == "low_stim"] <- -0.5
data$stim_con_linear[data$event03_stimulus_type == "med_stim"] <- 0
data$stim_con_linear[data$event03_stimulus_type == "high_stim"] <- 0.5
data
# contrast code 2 quadratic
$stim_con_quad[data$event03_stimulus_type == "low_stim"] <- -0.33
data$stim_con_quad[data$event03_stimulus_type == "med_stim"] <- 0.66
data$stim_con_quad[data$event03_stimulus_type == "high_stim"] <- -0.33
data
# social cude contrast
$social_cue[data$param_cue_type == "low_cue"] <- -0.5 # social influence task
data$social_cue[data$param_cue_type == "high_cue"] <- 0.5 # no influence task
data
<- "stim_con_linear"
stim_con1 <- "stim_con_quad"
stim_con2 <- "social_cue"
iv1 <- "event04_actual_angle"
dv
# [ MODEL ] _________________________________________________ # nolint
<- file.path(
model_savefname
analysis_dir,paste("lmer_task-", taskname,
"_rating-", dv_keyword,
"_", as.character(Sys.Date()), "_cooksd.txt",
sep = ""
)
)<- lmer_twofactor_cooksd_fix(
cooksd
data, taskname, iv1, stim_con1, stim_con2, dv,'random_slopes', print_lmer_output = FALSE
subject, dv_keyword, model_savefname,
)<- as.numeric(names(cooksd)[
influential > (4 / as.numeric(length(unique(data$src_subject_id)))))
(cooksd
])<- data[-influential, ]
data_screen # [ PLOT ] reordering for plots _________________________ # nolint
$cue_name[data_screen$param_cue_type == "high_cue"] <- "high cue"
data_screen$cue_name[data_screen$param_cue_type == "low_cue"] <- "low cue"
data_screen
$stim_name[data_screen$param_stimulus_type == "high_stim"] <- "high"
data_screen$stim_name[data_screen$param_stimulus_type == "med_stim"] <- "med"
data_screen$stim_name[data_screen$param_stimulus_type == "low_stim"] <- "low"
data_screen
# DATA$levels_ordered <- factor(DATA$param_stimulus_type, levels=c("low", "med", "high"))
$stim_ordered <- factor(
data_screen$stim_name,
data_screenlevels = c("low", "med", "high")
)$cue_ordered <- factor(
data_screen$cue_name,
data_screenlevels = c("low cue", "high cue")
)<- "stim_ordered"
model_iv1 <- "cue_ordered"
model_iv2
# [ PLOT ] calculate mean and se _________________________
<- meanSummary(
actual_subjectwise
data_screen,c(subject, model_iv1, model_iv2), dv
)<- summarySEwithin(
actual_groupwise data = actual_subjectwise,
measurevar = "mean_per_sub",
withinvars = c(model_iv1, model_iv2), idvar = subject
)$task <- taskname
actual_groupwise# https://stackoverflow.com/questions/29402528/append-data-frames-together-in-a-for-loop/29419402
<- rbind(combined_se_calc_cooksd, actual_groupwise)
combined_se_calc_cooksd # if(any(startsWith(dv_keyword, c("expect", "Expect")))){color = c( "#1B9E77", "#D95F02")}else{color=c( "#4575B4", "#D73027")} # if keyword starts with
# print("groupwisemean")
# [ PLOT ] calculate mean and se ----------------------------------------------------------------------------
<- "mean_per_sub"
sub_mean <- "mean_per_sub_norm_mean"
group_mean <- "se"
se <- "subject"
subject <- paste(taskname, " - Actual Rating (degree) Cooksd removed")
ggtitle <- paste(taskname, " - Actual")
title <- ""
xlab <- "ratings (degree)"
ylab <- c(-10,190)
ylim <- "actual"
dv_keyword if (any(startsWith(dv_keyword, c("expect", "Expect")))) {
<- c("#1B9E77", "#D95F02")
color else {
} <- c("#4575B4", "#D73027")
color # if keyword starts with
} <- file.path(
plot_savefname
analysis_dir,paste("raincloud_task-", taskname,
"_rating-", dv_keyword,
"_", as.character(Sys.Date()), "_cooksd.png",
sep = ""
)
)<- plot_rainclouds_twofactor(
g
actual_subjectwise, actual_groupwise, model_iv1, model_iv2,
sub_mean, group_mean, se, subject,
ggtitle, title, xlab, ylab, taskname,ylim,
w, h, dv_keyword, color, plot_savefname
)<- g +
g geom_hline(yintercept = 0, size = 0.1, linetype = "dashed") +
geom_label(x = 3.5, y = 0, label = c("no sensation"), hjust = 0, nudge_x = 0.1, size = 3) +
geom_hline(yintercept = 3, size = 0.1, linetype = "dashed") +
geom_label(x = 3.5, y = 3, label = c("barely detectable"), hjust = 0, nudge_x = 0.1, size = 3) +
geom_hline(yintercept = 10, size = 0.1, linetype = "dashed") +
geom_label(x = 3.5, y = 10, label = c("weak"), hjust = 0, nudge_x = 0.1, size = 3) +
geom_hline(yintercept = 30, size = 0.1, linetype = "dashed") +
geom_label(x = 3.5, y = 30, label = c("moderate"), hjust = 0, nudge_x = 0.1, size = 3) +
geom_hline(yintercept = 65, size = 0.1, linetype = "dashed") +
geom_label(x = 3.5, y = 65, label = c("strong"), hjust = 0, nudge_x = 0.1, size = 3) +
geom_hline(yintercept = 95, size = 0.1, linetype = "dashed") +
geom_label(x = 3.5, y = 95, label = c("very strong"), hjust = 0, nudge_x = 0.1, size = 3) +
geom_hline(yintercept = 180, size = 0.1, linetype = "dashed") +
geom_label(x = 3.5, y = 180, label = c("strongest imaginable"), hjust = 0, nudge_x = 0.1, size = 3) +
coord_cartesian(clip = 'off')+
theme_classic() +
theme(legend.position = "none")
ggsave(plot_savefname, width = w, height = h)
g
# save fixed random effects _______________________________
$newcoef <- mapvalues(randEffect$term,
randEffectfrom = c("(Intercept)", "data[, iv]",
"data[, stim_con1]", "data[, stim_con2]",
"data[, iv]:data[, stim_con1]",
"data[, iv]:data[, stim_con2]"),
to = c("rand_intercept", "rand_cue", "rand_stimlin",
"rand_stimquad", "rand_int_cue_stimlin", "rand_int_cue_stimquad")
)
#
# # The arguments to spread():
# # - data: Data object
# # - key: Name of column containing the new column names
# # - value: Name of column containing values
#
# # TODO: add fixed effects
#
<- subset(randEffect, select = -c(grpvar, term, condsd))
rand_subset <- spread(rand_subset, key = newcoef, value = condval)
wide_rand <- do.call(
wide_fix "rbind",
replicate(nrow(wide_rand), as.data.frame(t(as.matrix(fixEffect))),
simplify = FALSE
)
)rownames(wide_fix) <- NULL
<- dplyr::rename(wide_fix,
new_wide_fix fix_intercept = `(Intercept)`,
fix_cue = `social_cue`, # `data[, iv]`,
fix_stimulus_linear = `stim_con_linear`, # `data[, stim_con1]`,
fix_stimulus_quad = `stim_con_quad`, #`data[, stim_con2]`,
fix_int_cue_stimlin = `social_cue:stim_con_linear`, #`data[, iv]:data[, stim_con1]`,
fix_int_cue_stimquad = `social_cue:stim_con_quad` #`data[, iv]:data[, stim_con2]`
)
<- cbind(wide_rand, new_wide_fix)
total $task <- taskname
total<- total %>% dplyr::select(task, everything())
new_total <- dplyr::rename(total, subj = grp)
new_total
<- file.path(analysis_dir,
plot_savefname paste("randeffect_task-", taskname,
"_", as.character(Sys.Date()), "_outlier-cooksd.csv", sep = ""))
write.csv(new_total, plot_savefname, row.names = FALSE)
}
##
## Attaching package: 'equatiomatic'
## The following object is masked from 'package:merTools':
##
## hsb
## boundary (singular) fit: see help('isSingular')
## $$
## \begin{aligned}
## \operatorname{event04\_actual\_angle}_{i} &\sim N \left(\mu, \sigma^2 \right) \\
## \mu &=\alpha_{j[i]} + \beta_{1j[i]}(\operatorname{social\_cue}) + \beta_{2j[i]}(\operatorname{stim\_con\_linear}) + \beta_{3j[i]}(\operatorname{stim\_con\_quad}) + \beta_{4j[i]}(\operatorname{social\_cue} \times \operatorname{stim\_con\_linear}) + \beta_{5j[i]}(\operatorname{social\_cue} \times \operatorname{stim\_con\_quad}) \\
## \left(
## \begin{array}{c}
## \begin{aligned}
## &\alpha_{j} \\
## &\beta_{1j} \\
## &\beta_{2j} \\
## &\beta_{3j} \\
## &\beta_{4j} \\
## &\beta_{5j}
## \end{aligned}
## \end{array}
## \right)
## &\sim N \left(
## \left(
## \begin{array}{c}
## \begin{aligned}
## &\mu_{\alpha_{j}} \\
## &\mu_{\beta_{1j}} \\
## &\mu_{\beta_{2j}} \\
## &\mu_{\beta_{3j}} \\
## &\mu_{\beta_{4j}} \\
## &\mu_{\beta_{5j}}
## \end{aligned}
## \end{array}
## \right)
## ,
## \left(
## \begin{array}{cccccc}
## \sigma^2_{\alpha_{j}} & \rho_{\alpha_{j}\beta_{1j}} & \rho_{\alpha_{j}\beta_{2j}} & \rho_{\alpha_{j}\beta_{3j}} & \rho_{\alpha_{j}\beta_{4j}} & \rho_{\alpha_{j}\beta_{5j}} \\
## \rho_{\beta_{1j}\alpha_{j}} & \sigma^2_{\beta_{1j}} & \rho_{\beta_{1j}\beta_{2j}} & \rho_{\beta_{1j}\beta_{3j}} & \rho_{\beta_{1j}\beta_{4j}} & \rho_{\beta_{1j}\beta_{5j}} \\
## \rho_{\beta_{2j}\alpha_{j}} & \rho_{\beta_{2j}\beta_{1j}} & \sigma^2_{\beta_{2j}} & \rho_{\beta_{2j}\beta_{3j}} & \rho_{\beta_{2j}\beta_{4j}} & \rho_{\beta_{2j}\beta_{5j}} \\
## \rho_{\beta_{3j}\alpha_{j}} & \rho_{\beta_{3j}\beta_{1j}} & \rho_{\beta_{3j}\beta_{2j}} & \sigma^2_{\beta_{3j}} & \rho_{\beta_{3j}\beta_{4j}} & \rho_{\beta_{3j}\beta_{5j}} \\
## \rho_{\beta_{4j}\alpha_{j}} & \rho_{\beta_{4j}\beta_{1j}} & \rho_{\beta_{4j}\beta_{2j}} & \rho_{\beta_{4j}\beta_{3j}} & \sigma^2_{\beta_{4j}} & \rho_{\beta_{4j}\beta_{5j}} \\
## \rho_{\beta_{5j}\alpha_{j}} & \rho_{\beta_{5j}\beta_{1j}} & \rho_{\beta_{5j}\beta_{2j}} & \rho_{\beta_{5j}\beta_{3j}} & \rho_{\beta_{5j}\beta_{4j}} & \sigma^2_{\beta_{5j}}
## \end{array}
## \right)
## \right)
## \text{, for subject j = 1,} \dots \text{,J}
## \end{aligned}
## $$
## Warning in geom_line(data = subjectwise, aes(group = .data[[subject]], y
## = .data[[sub_mean]], : Ignoring unknown aesthetics: fill
## Warning: Duplicated aesthetics after name standardisation: width
## Coordinate system already present. Adding new coordinate system, which will
## replace the existing one.
## The following `from` values were not present in `x`: data[, iv], data[, stim_con1], data[, stim_con2], data[, iv]:data[, stim_con1], data[, iv]:data[, stim_con2]
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 1 negative eigenvalue: -8.8e-02
## $$
## \begin{aligned}
## \operatorname{event04\_actual\_angle}_{i} &\sim N \left(\mu, \sigma^2 \right) \\
## \mu &=\alpha_{j[i]} + \beta_{1j[i]}(\operatorname{social\_cue}) + \beta_{2j[i]}(\operatorname{stim\_con\_linear}) + \beta_{3j[i]}(\operatorname{stim\_con\_quad}) + \beta_{4j[i]}(\operatorname{social\_cue} \times \operatorname{stim\_con\_linear}) + \beta_{5j[i]}(\operatorname{social\_cue} \times \operatorname{stim\_con\_quad}) \\
## \left(
## \begin{array}{c}
## \begin{aligned}
## &\alpha_{j} \\
## &\beta_{1j} \\
## &\beta_{2j} \\
## &\beta_{3j} \\
## &\beta_{4j} \\
## &\beta_{5j}
## \end{aligned}
## \end{array}
## \right)
## &\sim N \left(
## \left(
## \begin{array}{c}
## \begin{aligned}
## &\mu_{\alpha_{j}} \\
## &\mu_{\beta_{1j}} \\
## &\mu_{\beta_{2j}} \\
## &\mu_{\beta_{3j}} \\
## &\mu_{\beta_{4j}} \\
## &\mu_{\beta_{5j}}
## \end{aligned}
## \end{array}
## \right)
## ,
## \left(
## \begin{array}{cccccc}
## \sigma^2_{\alpha_{j}} & \rho_{\alpha_{j}\beta_{1j}} & \rho_{\alpha_{j}\beta_{2j}} & \rho_{\alpha_{j}\beta_{3j}} & \rho_{\alpha_{j}\beta_{4j}} & \rho_{\alpha_{j}\beta_{5j}} \\
## \rho_{\beta_{1j}\alpha_{j}} & \sigma^2_{\beta_{1j}} & \rho_{\beta_{1j}\beta_{2j}} & \rho_{\beta_{1j}\beta_{3j}} & \rho_{\beta_{1j}\beta_{4j}} & \rho_{\beta_{1j}\beta_{5j}} \\
## \rho_{\beta_{2j}\alpha_{j}} & \rho_{\beta_{2j}\beta_{1j}} & \sigma^2_{\beta_{2j}} & \rho_{\beta_{2j}\beta_{3j}} & \rho_{\beta_{2j}\beta_{4j}} & \rho_{\beta_{2j}\beta_{5j}} \\
## \rho_{\beta_{3j}\alpha_{j}} & \rho_{\beta_{3j}\beta_{1j}} & \rho_{\beta_{3j}\beta_{2j}} & \sigma^2_{\beta_{3j}} & \rho_{\beta_{3j}\beta_{4j}} & \rho_{\beta_{3j}\beta_{5j}} \\
## \rho_{\beta_{4j}\alpha_{j}} & \rho_{\beta_{4j}\beta_{1j}} & \rho_{\beta_{4j}\beta_{2j}} & \rho_{\beta_{4j}\beta_{3j}} & \sigma^2_{\beta_{4j}} & \rho_{\beta_{4j}\beta_{5j}} \\
## \rho_{\beta_{5j}\alpha_{j}} & \rho_{\beta_{5j}\beta_{1j}} & \rho_{\beta_{5j}\beta_{2j}} & \rho_{\beta_{5j}\beta_{3j}} & \rho_{\beta_{5j}\beta_{4j}} & \sigma^2_{\beta_{5j}}
## \end{array}
## \right)
## \right)
## \text{, for subject j = 1,} \dots \text{,J}
## \end{aligned}
## $$
## Warning in geom_line(data = subjectwise, aes(group = .data[[subject]], y = .data[[sub_mean]], : Ignoring unknown aesthetics: fill
## Duplicated aesthetics after name standardisation: width
## Coordinate system already present. Adding new coordinate system, which will
## replace the existing one.
## The following `from` values were not present in `x`: data[, iv], data[, stim_con1], data[, stim_con2], data[, iv]:data[, stim_con1], data[, iv]:data[, stim_con2]
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 1 negative eigenvalue: -1.3e+01
## $$
## \begin{aligned}
## \operatorname{event04\_actual\_angle}_{i} &\sim N \left(\mu, \sigma^2 \right) \\
## \mu &=\alpha_{j[i]} + \beta_{1j[i]}(\operatorname{social\_cue}) + \beta_{2j[i]}(\operatorname{stim\_con\_linear}) + \beta_{3j[i]}(\operatorname{stim\_con\_quad}) + \beta_{4j[i]}(\operatorname{social\_cue} \times \operatorname{stim\_con\_linear}) + \beta_{5j[i]}(\operatorname{social\_cue} \times \operatorname{stim\_con\_quad}) \\
## \left(
## \begin{array}{c}
## \begin{aligned}
## &\alpha_{j} \\
## &\beta_{1j} \\
## &\beta_{2j} \\
## &\beta_{3j} \\
## &\beta_{4j} \\
## &\beta_{5j}
## \end{aligned}
## \end{array}
## \right)
## &\sim N \left(
## \left(
## \begin{array}{c}
## \begin{aligned}
## &\mu_{\alpha_{j}} \\
## &\mu_{\beta_{1j}} \\
## &\mu_{\beta_{2j}} \\
## &\mu_{\beta_{3j}} \\
## &\mu_{\beta_{4j}} \\
## &\mu_{\beta_{5j}}
## \end{aligned}
## \end{array}
## \right)
## ,
## \left(
## \begin{array}{cccccc}
## \sigma^2_{\alpha_{j}} & \rho_{\alpha_{j}\beta_{1j}} & \rho_{\alpha_{j}\beta_{2j}} & \rho_{\alpha_{j}\beta_{3j}} & \rho_{\alpha_{j}\beta_{4j}} & \rho_{\alpha_{j}\beta_{5j}} \\
## \rho_{\beta_{1j}\alpha_{j}} & \sigma^2_{\beta_{1j}} & \rho_{\beta_{1j}\beta_{2j}} & \rho_{\beta_{1j}\beta_{3j}} & \rho_{\beta_{1j}\beta_{4j}} & \rho_{\beta_{1j}\beta_{5j}} \\
## \rho_{\beta_{2j}\alpha_{j}} & \rho_{\beta_{2j}\beta_{1j}} & \sigma^2_{\beta_{2j}} & \rho_{\beta_{2j}\beta_{3j}} & \rho_{\beta_{2j}\beta_{4j}} & \rho_{\beta_{2j}\beta_{5j}} \\
## \rho_{\beta_{3j}\alpha_{j}} & \rho_{\beta_{3j}\beta_{1j}} & \rho_{\beta_{3j}\beta_{2j}} & \sigma^2_{\beta_{3j}} & \rho_{\beta_{3j}\beta_{4j}} & \rho_{\beta_{3j}\beta_{5j}} \\
## \rho_{\beta_{4j}\alpha_{j}} & \rho_{\beta_{4j}\beta_{1j}} & \rho_{\beta_{4j}\beta_{2j}} & \rho_{\beta_{4j}\beta_{3j}} & \sigma^2_{\beta_{4j}} & \rho_{\beta_{4j}\beta_{5j}} \\
## \rho_{\beta_{5j}\alpha_{j}} & \rho_{\beta_{5j}\beta_{1j}} & \rho_{\beta_{5j}\beta_{2j}} & \rho_{\beta_{5j}\beta_{3j}} & \rho_{\beta_{5j}\beta_{4j}} & \sigma^2_{\beta_{5j}}
## \end{array}
## \right)
## \right)
## \text{, for subject j = 1,} \dots \text{,J}
## \end{aligned}
## $$
## Warning in geom_line(data = subjectwise, aes(group = .data[[subject]], y = .data[[sub_mean]], : Ignoring unknown aesthetics: fill
## Duplicated aesthetics after name standardisation: width
## Coordinate system already present. Adding new coordinate system, which will
## replace the existing one.
## The following `from` values were not present in `x`: data[, iv], data[, stim_con1], data[, stim_con2], data[, iv]:data[, stim_con1], data[, iv]:data[, stim_con2]
6.2.3 model 04 4-2 individual differences in cue effects
# stack task- .csv
= read.csv(file.path(analysis_dir, paste('randeffect_task-pain_',as.character(Sys.Date()),'_outlier-cooksd.csv', sep='') ))
dfP = read.csv(file.path(analysis_dir, paste('randeffect_task-vicarious_',as.character(Sys.Date()),'_outlier-cooksd.csv', sep='') ))
dfV = read.csv(file.path(analysis_dir, paste('randeffect_task-cognitive_',as.character(Sys.Date()),'_outlier-cooksd.csv', sep='') ))
dfC
<- merge_recurse(list(dfP,dfV,dfC))
pvc
= file.path(analysis_dir, paste('randeffect_task-all_',as.character(Sys.Date()),'_outlier-cooksd.csv', sep='') )
save_fname write.csv(pvc, save_fname, row.names = FALSE)
6.2.4 model 04 4-3 scatter plot
# stack
<- subset(pvc, select = c(task, subj, social_cue))
pvc_rand_cue_subset <- spread(pvc_rand_cue_subset, key = task, value = social_cue)
pvc_rand_cue # plot individually
<- plot_ggplot_correlation(data = pvc_rand_cue, x = 'vicarious', y = 'pain', p_acc = 0.001, r_acc = 0.01, limit_min = -20, limit_max = 20, label_position = 18)
pv <- plot_ggplot_correlation(data = pvc_rand_cue, x = 'cognitive', y = 'vicarious', p_acc = 0.001, r_acc = 0.01, limit_min = -20, limit_max = 20, label_position = 18)
vc <- plot_ggplot_correlation(data = pvc_rand_cue, x = 'pain', y = 'cognitive', p_acc = 0.001, r_acc = 0.01, limit_min = -20, limit_max = 20, label_position = 18)
cp # combine plots and add title
<- ggpubr::ggarrange(pv, vc, cp, ncol = 3, nrow = 1, common.legend = FALSE, legend = "bottom") plots
## Warning: Removed 3 rows containing non-finite values (`stat_cor()`).
## Warning: Removed 3 rows containing missing values (`geom_point()`).
## Warning: Removed 1 rows containing non-finite values (`stat_cor()`).
## Warning: Removed 1 rows containing missing values (`geom_point()`).
## Warning: Removed 3 rows containing non-finite values (`stat_cor()`).
## Warning: Removed 3 rows containing missing values (`geom_point()`).
<- annotate_figure(plots,top = text_grob("individual differences\n - cue effects from expectation ratings", color = "black", face = "bold", size = 10 ))
plots_title <- file.path(
save_plotname
analysis_dir,paste("randeffect_scatterplot_task-all_",
as.character(Sys.Date()), ".png",
sep = ""
)
) plots
ggsave(save_plotname, width = 10, height = 3)
6.2.5 model 04 4-4 lineplot
library(ggpubr)
= as.data.frame(combined_se_calc_cooksd)
DATA = c( "#4575B4", "#D73027")
color = "stim_ordered"
LINEIV1 = "cue_ordered"
LINEIV2 = "mean_per_sub_norm_mean"
MEAN = "ci"
ERROR = "actual"
dv_keyword = plot_lineplot_twofactor(DATA, 'pain',
p1 ggtitle = 'pain' )
LINEIV1, LINEIV2, MEAN, ERROR, color, = plot_lineplot_twofactor(DATA,'vicarious',
p2 ggtitle = 'vicarious')
LINEIV1, LINEIV2, MEAN, ERROR, color,= plot_lineplot_twofactor(DATA, 'cognitive',
p3 ggtitle = 'cognitive')
LINEIV1, LINEIV2, MEAN, ERROR, color,#grid.arrange(p1, p2, p3, ncol=3 , common.legend = TRUE)
::ggarrange(p1,p2,p3,ncol = 3, nrow = 1, common.legend = TRUE,legend = "bottom") ggpubr
= file.path(analysis_dir,
plot_filename paste('lineplot_task-all_rating-',dv_keyword,'.png', sep = ""))
ggsave(plot_filename, width = 8, height = 4)