Skip to content

Commit

Permalink
Added cluster based windowed results
Browse files Browse the repository at this point in the history
Signed-off-by: Liang Zhang <[email protected]>
  • Loading branch information
psychelzh committed Dec 14, 2023
1 parent a29e2e7 commit 8197f00
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
4 changes: 2 additions & 2 deletions _freeze/index/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"hash": "51935b8e0e661ece00adbb0fe44203fd",
"hash": "51c2aac198871db998f1c1f348997a29",
"result": {
"markdown": "---\ntitle: Representation Analysis\nauthor:\n - name: Liang Zhang\n - name: Jintao Sheng\nformat:\n html:\n code-fold: true\n toc: true\nexecute:\n warning: false\nbibliography: references.bib\n---\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(tidyverse)\n```\n:::\n\n\n# Inter-subject representation similarity\n\n## Abstract vs Concrete\n\n\n::: {#fig-inter-abs-con .cell}\n\n```{.r .cell-code}\ntargets::tar_read(rsa_inter_common_trials) |>\n summarise(\n mean_se(fisher_z),\n .by = c(region_id, word_category)\n ) |>\n ggplot(aes(region_id, y, ymax = ymax, ymin = ymin)) +\n geom_col(aes(fill = word_category), position = position_dodge(width = 0.4), width = 0.4) +\n geom_errorbar(aes(group = word_category), position = position_dodge(width = 0.4), width = 0) +\n scale_x_continuous(name = \"Region\", breaks = scales::breaks_width(1)) +\n scale_y_continuous(name = \"Intersubject Correlation\") +\n ggsci::scale_fill_d3(name = \"Word Type\") +\n ggpubr::theme_pubclean()\n\ntargets::tar_read(summary_word_cat_rsa_inter_common_trials_window) |>\n ggplot(aes(window_id, mean_fisher_z)) +\n geom_line(aes(color = word_category, group = word_category)) +\n scale_x_continuous(name = \"Time (ms)\", labels = \\(x) x * 20) +\n scale_y_continuous(name = \"Intersubject Correlation\") +\n ggsci::scale_color_d3(name = \"Word Type\") +\n facet_wrap(vars(region_id)) +\n ggpubr::theme_pubclean()\n```\n\n::: {.cell-output-display}\n![Without window](index_files/figure-html/fig-inter-abs-con-1.png){#fig-inter-abs-con-1 width=672}\n:::\n\n::: {.cell-output-display}\n![Dynamic of a trial](index_files/figure-html/fig-inter-abs-con-2.png){#fig-inter-abs-con-2 width=672}\n:::\n\nVerify if intersubject similarity of concrete is larger than that of abstract.\n:::\n\n\n## Subsequent memory effect\n\n\n::: {#fig-inter-mem-eff .cell}\n\n```{.r .cell-code}\ntargets::tar_read(rsa_inter_common_trials) |>\n summarise(\n mean_se(fisher_z),\n .by = c(region_id, response_type_shared)\n ) |>\n ggplot(aes(region_id, y, ymax = ymax, ymin = ymin)) +\n geom_col(aes(fill = response_type_shared), position = position_dodge(width = 0.4), width = 0.4) +\n geom_errorbar(aes(group = response_type_shared), position = position_dodge(width = 0.4), width = 0) +\n scale_x_continuous(name = \"Region\", breaks = scales::breaks_width(1)) +\n scale_y_continuous(name = \"Intersubject Correlation\") +\n scale_fill_brewer(name = \"Mem Type Common\", palette = \"Oranges\", direction = -1) +\n ggpubr::theme_pubclean()\n\ntargets::tar_read(summary_word_mem_rsa_inter_common_trials_window) |>\n ggplot(aes(window_id, mean_fisher_z)) +\n geom_line(aes(color = response_type_shared, group = response_type_shared)) +\n scale_x_continuous(name = \"Time (ms)\", labels = \\(x) x * 20) +\n scale_y_continuous(name = \"Intersubject Correlation\") +\n scale_color_brewer(name = \"Mem Type Common\", palette = \"Oranges\", direction = -1) +\n facet_wrap(vars(region_id)) +\n ggpubr::theme_pubclean()\n```\n\n::: {.cell-output-display}\n![Without window](index_files/figure-html/fig-inter-mem-eff-1.png){#fig-inter-mem-eff-1 width=672}\n:::\n\n::: {.cell-output-display}\n![Dynamic of a trial](index_files/figure-html/fig-inter-mem-eff-2.png){#fig-inter-mem-eff-2 width=672}\n:::\n\nAverage inter-subject representation similarity among different memory conditions\n:::\n\n\n# Predict Memory ability\n\nThe indicator calculation is based on [@manns2003].\n\n## Individual-to-group synchronization predicts memory performance\n\n\n::: {#fig-predict-performance .cell .column-page}\n\n```{.r .cell-code}\ntargets::tar_load(mem_perf)\narrow::read_parquet(targets::tar_read(file_rs_group_whole)) |>\n inner_join(mem_perf, by = \"subj_id\", relationship = \"many-to-many\") |>\n filter(mem_type %in% c(\"knowadj\", \"remember\")) |>\n ggplot(aes(fisher_z, dprime, color = mem_type)) +\n geom_point() +\n stat_smooth(method = \"lm\", formula = y ~ x) +\n ggpmisc::stat_correlation(\n ggpmisc::use_label(c(\"r\", \"p.value\")),\n small.r = TRUE,\n small.p = TRUE\n ) +\n scale_color_brewer(palette = \"Dark2\", guide = \"none\") +\n scale_x_continuous(\n name = \"Individual-to-Group Similarity\",\n breaks = scales::breaks_pretty(n = 4)\n ) +\n scale_y_continuous(name = \"d'\") +\n facet_grid(\n rows = vars(mem_type),\n cols = vars(region_id),\n labeller = labeller(\n mem_type = c(\n knowadj = \"Familiarity\",\n remember = \"Recollection\"\n )\n ),\n scales = \"free_x\",\n ) +\n ggpubr::theme_pubr()\n\narrow::read_parquet(targets::tar_read(file_rs_group_trial)) |>\n summarise(\n mean_fisher_z = mean(fisher_z, na.rm = TRUE),\n .by = c(region_id, subj_id)\n ) |>\n inner_join(mem_perf, by = \"subj_id\", relationship = \"many-to-many\") |>\n filter(mem_type %in% c(\"knowadj\", \"remember\")) |>\n ggplot(aes(mean_fisher_z, dprime, color = mem_type)) +\n geom_point() +\n stat_smooth(method = \"lm\", formula = y ~ x) +\n ggpmisc::stat_correlation(\n ggpmisc::use_label(c(\"r\", \"p.value\")),\n small.r = TRUE,\n small.p = TRUE\n ) +\n scale_color_brewer(palette = \"Dark2\", guide = \"none\") +\n scale_x_continuous(\n name = \"Average Individual-to-Group Similarity\",\n breaks = scales::breaks_pretty(n = 4)\n ) +\n scale_y_continuous(name = \"d'\") +\n facet_grid(\n rows = vars(mem_type),\n cols = vars(region_id),\n labeller = labeller(\n mem_type = c(\n knowadj = \"Familiarity\",\n remember = \"Recollection\"\n )\n ),\n scales = \"free_x\",\n ) +\n ggpubr::theme_pubr()\n```\n\n::: {.cell-output-display}\n![Concatenate all trials into one time series](index_files/figure-html/fig-predict-performance-1.png){#fig-predict-performance-1 width=1152}\n:::\n\n::: {.cell-output-display}\n![Average all trial-level synchronization](index_files/figure-html/fig-predict-performance-2.png){#fig-predict-performance-2 width=1152}\n:::\n\nPredict memory performance from individual-to-group synchronization\n:::\n\n\n# References\n",
"markdown": "---\ntitle: Representation Analysis\nauthor:\n - name: Liang Zhang\n - name: Jintao Sheng\nformat:\n html:\n code-fold: true\n toc: true\nexecute:\n warning: false\nbibliography: references.bib\n---\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(tidyverse)\n```\n:::\n\n\n# Inter-subject representation similarity\n\n## Abstract vs Concrete\n\n\n::: {#fig-inter-abs-con .cell}\n\n```{.r .cell-code}\ntargets::tar_read(rsa_inter_common_trials) |>\n summarise(\n mean_se(fisher_z),\n .by = c(region_id, word_category)\n ) |>\n ggplot(aes(region_id, y, ymax = ymax, ymin = ymin)) +\n geom_col(aes(fill = word_category), position = position_dodge(width = 0.4), width = 0.4) +\n geom_errorbar(aes(group = word_category), position = position_dodge(width = 0.4), width = 0) +\n scale_x_continuous(name = \"Region\", breaks = scales::breaks_width(1)) +\n scale_y_continuous(name = \"Intersubject Correlation\") +\n ggsci::scale_fill_d3(name = \"Word Type\") +\n ggpubr::theme_pubclean()\n\ntargets::tar_read(summary_word_cat_rsa_inter_common_trials_window) |>\n ggplot(aes(window_id, mean_fisher_z)) +\n geom_line(aes(color = word_category, group = word_category)) +\n scale_x_continuous(name = \"Time (ms)\", labels = \\(x) x * 20) +\n scale_y_continuous(name = \"Intersubject Correlation\") +\n ggsci::scale_color_d3(name = \"Word Type\") +\n facet_wrap(vars(region_id)) +\n ggpubr::theme_pubclean()\n```\n\n::: {.cell-output-display}\n![Without window](index_files/figure-html/fig-inter-abs-con-1.png){#fig-inter-abs-con-1 width=672}\n:::\n\n::: {.cell-output-display}\n![Dynamic of a trial](index_files/figure-html/fig-inter-abs-con-2.png){#fig-inter-abs-con-2 width=672}\n:::\n\nVerify if intersubject similarity of concrete is larger than that of abstract.\n:::\n\n\n## Subsequent memory effect\n\n\n::: {#fig-inter-mem-eff .cell}\n\n```{.r .cell-code}\ntargets::tar_read(rsa_inter_common_trials) |>\n summarise(\n mean_se(fisher_z),\n .by = c(region_id, response_type_shared)\n ) |>\n ggplot(aes(region_id, y, ymax = ymax, ymin = ymin)) +\n geom_col(aes(fill = response_type_shared), position = position_dodge(width = 0.4), width = 0.4) +\n geom_errorbar(aes(group = response_type_shared), position = position_dodge(width = 0.4), width = 0) +\n scale_x_continuous(name = \"Region\", breaks = scales::breaks_width(1)) +\n scale_y_continuous(name = \"Intersubject Correlation\") +\n scale_fill_brewer(name = \"Mem Type Common\", palette = \"Oranges\", direction = -1) +\n ggpubr::theme_pubclean()\n\ntargets::tar_read(summary_word_mem_rsa_inter_common_trials_window) |>\n ggplot(aes(window_id, mean_fisher_z)) +\n geom_line(aes(color = response_type_shared, group = response_type_shared)) +\n scale_x_continuous(name = \"Time (ms)\", labels = \\(x) x * 20) +\n scale_y_continuous(name = \"Intersubject Correlation\") +\n scale_color_brewer(name = \"Mem Type Common\", palette = \"Oranges\", direction = -1) +\n facet_wrap(vars(region_id)) +\n ggpubr::theme_pubclean()\n```\n\n::: {.cell-output-display}\n![Without window](index_files/figure-html/fig-inter-mem-eff-1.png){#fig-inter-mem-eff-1 width=672}\n:::\n\n::: {.cell-output-display}\n![Dynamic of a trial](index_files/figure-html/fig-inter-mem-eff-2.png){#fig-inter-mem-eff-2 width=672}\n:::\n\nAverage inter-subject representation similarity among different memory conditions\n:::\n\n\n# Predict Memory ability\n\nThe indicator calculation is based on [@manns2003].\n\n## Individual-to-group synchronization predicts memory performance\n\n\n::: {#fig-predict-performance .cell .column-page}\n\n```{.r .cell-code}\nmem_types_report <- c(\"knowadj\" = \"Familiarity\", \"remember\" = \"Recollection\")\ntargets::tar_load(mem_perf)\narrow::read_parquet(targets::tar_read(file_rs_group_whole)) |>\n inner_join(mem_perf, by = \"subj_id\", relationship = \"many-to-many\") |>\n filter(mem_type %in% names(mem_types_report)) |>\n ggplot(aes(fisher_z, dprime, color = mem_type)) +\n geom_point() +\n stat_smooth(method = \"lm\", formula = y ~ x) +\n ggpmisc::stat_correlation(\n ggpmisc::use_label(c(\"r\", \"p.value\")),\n small.r = TRUE,\n small.p = TRUE\n ) +\n scale_color_brewer(palette = \"Dark2\", guide = \"none\") +\n scale_x_continuous(\n name = \"Individual-to-Group Similarity\",\n breaks = scales::breaks_pretty(n = 4)\n ) +\n scale_y_continuous(name = \"d'\") +\n facet_grid(\n rows = vars(mem_type),\n cols = vars(region_id),\n labeller = labeller(mem_type = mem_types_report),\n scales = \"free_x\",\n ) +\n ggpubr::theme_pubr()\n\narrow::read_parquet(targets::tar_read(file_rs_group_trial)) |>\n summarise(\n mean_fisher_z = mean(fisher_z, na.rm = TRUE),\n .by = c(region_id, subj_id)\n ) |>\n inner_join(mem_perf, by = \"subj_id\", relationship = \"many-to-many\") |>\n filter(mem_type %in% names(mem_types_report)) |>\n ggplot(aes(mean_fisher_z, dprime, color = mem_type)) +\n geom_point() +\n stat_smooth(method = \"lm\", formula = y ~ x) +\n ggpmisc::stat_correlation(\n ggpmisc::use_label(c(\"r\", \"p.value\")),\n small.r = TRUE,\n small.p = TRUE\n ) +\n scale_color_brewer(palette = \"Dark2\", guide = \"none\") +\n scale_x_continuous(\n name = \"Average Individual-to-Group Similarity\",\n breaks = scales::breaks_pretty(n = 4)\n ) +\n scale_y_continuous(name = \"d'\") +\n facet_grid(\n rows = vars(mem_type),\n cols = vars(region_id),\n labeller = labeller(mem_type = mem_types_report),\n scales = \"free_x\",\n ) +\n ggpubr::theme_pubr()\n\nclusters_p_greater <- targets::tar_read(clusters_p_greater_group_window) |> \n filter(mem_type %in% names(mem_types_report))\nstats <- targets::tar_read(stats_group_window) |> \n filter(mem_type %in% names(mem_types_report))\nstats |> \n ggplot(aes(window_id, estimate)) +\n geom_area(\n data = stats |> \n inner_join(\n clusters_p_greater, \n by = join_by(region_id, mem_type, window_id >= start, window_id <= end)\n ),\n alpha = 0.5\n ) +\n geom_line() +\n facet_grid(\n rows = vars(mem_type),\n cols = vars(region_id), \n labeller = labeller(mem_type = mem_types_report)\n ) +\n geom_text(\n aes(mid, estimate / 2, label = label),\n data = clusters_p_greater |> \n mutate(mid = round((start + end) / 2)) |> \n inner_join(\n stats,\n by = join_by(region_id, mem_type, mid == window_id)\n ) |> \n mutate(\n label = str_glue(\n \"italic('p')=='{rstatix::p_mark_significant(p_perm)}'\"\n )\n ),\n parse = TRUE\n ) +\n scale_x_continuous(name = \"Time (s)\", labels = \\(x) x * 0.02) +\n scale_y_continuous(name = \"Pearson's Correlation\") +\n ggh4x::coord_axes_inside(labels_inside = TRUE, expand = FALSE) +\n ggpubr::theme_pubr() +\n theme(\n axis.title.y.left = element_text(\n margin = margin(r = 30)\n ),\n panel.spacing.x = unit(1.5, \"lines\")\n )\n```\n\n::: {.cell-output-display}\n![Concatenate all trials into one time series](index_files/figure-html/fig-predict-performance-1.png){#fig-predict-performance-1 width=1152}\n:::\n\n::: {.cell-output-display}\n![Average all trial-level synchronization](index_files/figure-html/fig-predict-performance-2.png){#fig-predict-performance-2 width=1152}\n:::\n\n::: {.cell-output-display}\n![Time-windowed Cluster Results](index_files/figure-html/fig-predict-performance-3.png){#fig-predict-performance-3 width=1152}\n:::\n\nPredict memory performance from individual-to-group synchronization\n:::\n\n\n# References\n",
"supporting": [
"index_files"
],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 52 additions & 14 deletions index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ The indicator calculation is based on [@manns2003].
#| fig-subcap:
#| - Concatenate all trials into one time series
#| - Average all trial-level synchronization
#| - Time-windowed Cluster Results
mem_types_report <- c("knowadj" = "Familiarity", "remember" = "Recollection")
targets::tar_load(mem_perf)
arrow::read_parquet(targets::tar_read(file_rs_group_whole)) |>
inner_join(mem_perf, by = "subj_id", relationship = "many-to-many") |>
filter(mem_type %in% c("knowadj", "remember")) |>
filter(mem_type %in% names(mem_types_report)) |>
ggplot(aes(fisher_z, dprime, color = mem_type)) +
geom_point() +
stat_smooth(method = "lm", formula = y ~ x) +
Expand All @@ -121,12 +123,7 @@ arrow::read_parquet(targets::tar_read(file_rs_group_whole)) |>
facet_grid(
rows = vars(mem_type),
cols = vars(region_id),
labeller = labeller(
mem_type = c(
knowadj = "Familiarity",
remember = "Recollection"
)
),
labeller = labeller(mem_type = mem_types_report),
scales = "free_x",
) +
ggpubr::theme_pubr()
Expand All @@ -137,7 +134,7 @@ arrow::read_parquet(targets::tar_read(file_rs_group_trial)) |>
.by = c(region_id, subj_id)
) |>
inner_join(mem_perf, by = "subj_id", relationship = "many-to-many") |>
filter(mem_type %in% c("knowadj", "remember")) |>
filter(mem_type %in% names(mem_types_report)) |>
ggplot(aes(mean_fisher_z, dprime, color = mem_type)) +
geom_point() +
stat_smooth(method = "lm", formula = y ~ x) +
Expand All @@ -155,15 +152,56 @@ arrow::read_parquet(targets::tar_read(file_rs_group_trial)) |>
facet_grid(
rows = vars(mem_type),
cols = vars(region_id),
labeller = labeller(
mem_type = c(
knowadj = "Familiarity",
remember = "Recollection"
)
),
labeller = labeller(mem_type = mem_types_report),
scales = "free_x",
) +
ggpubr::theme_pubr()
clusters_p_greater <- targets::tar_read(clusters_p_greater_group_window) |>
filter(mem_type %in% names(mem_types_report))
stats <- targets::tar_read(stats_group_window) |>
filter(mem_type %in% names(mem_types_report))
stats |>
ggplot(aes(window_id, estimate)) +
geom_area(
data = stats |>
inner_join(
clusters_p_greater,
by = join_by(region_id, mem_type, window_id >= start, window_id <= end)
),
alpha = 0.5
) +
geom_line() +
facet_grid(
rows = vars(mem_type),
cols = vars(region_id),
labeller = labeller(mem_type = mem_types_report)
) +
geom_text(
aes(mid, estimate / 2, label = label),
data = clusters_p_greater |>
mutate(mid = round((start + end) / 2)) |>
inner_join(
stats,
by = join_by(region_id, mem_type, mid == window_id)
) |>
mutate(
label = str_glue(
"italic('p')=='{rstatix::p_mark_significant(p_perm)}'"
)
),
parse = TRUE
) +
scale_x_continuous(name = "Time (s)", labels = \(x) x * 0.02) +
scale_y_continuous(name = "Pearson's Correlation") +
ggh4x::coord_axes_inside(labels_inside = TRUE, expand = FALSE) +
ggpubr::theme_pubr() +
theme(
axis.title.y.left = element_text(
margin = margin(r = 30)
),
panel.spacing.x = unit(1.5, "lines")
)
```

# References

0 comments on commit 8197f00

Please sign in to comment.