targets::tar_load(sync_inter_intra)
summary_sync <- sync_inter_intra |>
summarise(
broom::tidy(t.test(sync)),
.by = c(cca_id, type)
) |>
rstatix::adjust_pvalue() |>
rstatix::add_significance(
cutpoints = c(0, 0.001, 0.01, 0.05, 1),
symbols = c("***", "**", "*", "")
)
compare_sync_p <- sync_inter_intra |>
pivot_wider(
id_cols = c(subj_id, cca_id),
names_from = type,
values_from = sync
) |>
summarise(
broom::tidy(t.test(intra, inter_ahead, paired = TRUE)),
.by = cca_id
) |>
rstatix::adjust_pvalue() |>
rstatix::add_significance(
cutpoints = c(0, 0.001, 0.01, 0.05, 1),
symbols = c("***", "**", "*", "")
) |>
mutate(
start = "intra",
end = "inter_ahead",
y_position = max(summary_sync$conf.high) * 1.1
)
p_sync_compare <- summary_sync |>
ggplot(aes(type, estimate)) +
geom_col(
aes(color = cca_id, fill = cca_id, alpha = type),
width = 0.75
) +
geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.1) +
geom_text(
aes(y = conf.high, label = p.value.adj.signif),
vjust = 0,
size = SIZE_LABEL
) +
ggsignif::geom_signif(
data = compare_sync_p,
aes(
xmin = start,
xmax = end,
annotations = p.value.adj.signif,
y_position = y_position
),
textsize = SIZE_LABEL,
inherit.aes = FALSE,
manual = TRUE
) +
facet_grid(cols = vars(cca_id)) +
scale_x_discrete(name = NULL, labels = c("Intra", "Inter")) +
scale_y_continuous(
name = "Neural Sync",
expand = expansion(c(0, 0.1))
) +
scale_color_components(aesthetics = c("fill", "color")) +
scale_alpha_manual(
name = NULL,
values = c(1, 0),
guide = "none"
) +
theme(strip.text = element_blank())
sync_mem <- sync_inter_intra |>
left_join(targets::tar_read(mem_perf), by = "subj_id") |>
mutate(cca_id = factor(cca_id))
stats_sync_mem <- sync_mem |>
summarise(
broom::tidy(cor.test(sync, dprime)),
.by = c(cca_id, type)
) |>
rstatix::adjust_pvalue() |>
rstatix::add_significance(
cutpoints = c(0, 0.001, 0.01, 0.05, 1),
symbols = c("***", "**", "*", "")
) |>
prepare_corr_plotmath() |>
mutate(
x = min(sync_mem$sync),
y = max(sync_mem$dprime) * 1.2 * (1 - 0.1 * as.integer(type))
)
p_pred_mem <- sync_mem |>
ggplot(aes(x = sync, y = dprime, alpha = type)) +
geom_point(aes(color = cca_id, shape = type)) +
geom_line(
aes(color = cca_id),
stat = "smooth",
method = "lm",
formula = y ~ x
# linewidth = 2,
# fullrange = TRUE
) +
geom_text(
aes(x, y, label = label),
stats_sync_mem,
hjust = 0,
vjust = 1,
parse = TRUE,
) +
facet_grid(cols = vars(cca_id)) +
scale_x_continuous(name = "Neural Sync") +
scale_y_continuous(name = "Memory (d')") +
scale_alpha_manual(
name = NULL,
values = c(1, 0.5),
guide = "none"
) +
scale_shape_manual(
name = NULL,
values = c(16, 1),
labels = c("Intra", "Inter")
# guide = "none"
) +
scale_color_components(guide = "none") +
theme(strip.text = element_blank())
p_sync_smc <- visualize_mantel_dist(
targets::tar_read(sync_smc_whole),
targets::tar_read(stats_sync_smc_whole),
expression(italic(r)[Sync - SMC])
)
p_sync_smc_dynamic <- visualize_dynamic(
targets::tar_read(stats_sync_smc_dynamic),
targets::tar_read(clusters_stats_sync_smc_dynamic),
col_stat = "statistic",
lab_stat = expression(italic(r)[Sync - SMC])
)
p_sync_compare +
p_pred_mem +
p_sync_smc +
p_sync_smc_dynamic +
plot_layout(guides = "collect") +
plot_annotation(tag_levels = "A") &
theme(legend.position = "bottom")