Behavioral_analysis.Rmd 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. ---
  2. title: "Electrophysiological signatures of temporal context in the bisection task"
  3. author: "Cemre Baykan, Xiuna Zhu, Artyom Zinchenko, Hermann Mueller, Zhuanghua Shi"
  4. date: "February 2023"
  5. ---
  6. ```{r setup, include=FALSE}
  7. knitr::opts_chunk$set(echo = TRUE, eval = TRUE)
  8. source('dataana.R')
  9. options(mc.cores = parallel::detectCores())
  10. # flag for save figures
  11. saveFigure = TRUE
  12. ```
  13. # Experiment 1- Spacing Effect
  14. ## Fit psychometric functions
  15. ```{r}
  16. fits_EEG_exp1 = quickpsy(dat_EEG_exp1, x = targetDur, k =RP, prob = .5,
  17. grouping = .(cond, SubName),
  18. fun = logistic_fun,
  19. thresholds = FALSE,bootstrap='none')
  20. ```
  21. ```{r, fig.cap= 'PSE: Bisection task performance in Experiment 1'}
  22. # plot fitted function
  23. plot(fits_EEG_exp1)+ mytheme
  24. ```
  25. ```{r}
  26. par_EEG_exp1 <-fits_EEG_exp1$par %>% dplyr::select(cond, SubName, parn, par) %>%
  27. pivot_wider(names_from = parn, values_from = par) %>%
  28. mutate(jnd = log(3)/p2)
  29. par_EEG_exp1$pse <- par_EEG_exp1$p1
  30. par_EEG_exp1$p2 <- NULL
  31. par_EEG_exp1$p1 <- NULL
  32. head(par_EEG_exp1)
  33. ```
  34. ```{r}
  35. dat_EEG_exp1$cond= factor(dat_EEG_exp1$cond, levels=c("PS","NS"))
  36. fits_EEG_exp1_all = quickpsy(dat_EEG_exp1, x = targetDur, k =RP,
  37. grouping = .(cond),
  38. fun = logistic_fun,
  39. thresholds = FALSE,bootstrap='none')
  40. fits_EEG_exp1_all
  41. ```
  42. ## plot averaged
  43. ```{r, fig.cap= 'PSE: Bisection task performance in Experiment 1'}
  44. # plot fitted function
  45. plot_fit_EEG_exp1 <- plot(fits_EEG_exp1_all) + mytheme+
  46. labs(x = "Target interval (ms)", y = "Proportion of 'long' responses") +
  47. scale_color_manual(values = colors_plot) +
  48. scale_fill_manual(values = colors_plot) +
  49. theme(legend.position = "top", legend.title = element_blank())
  50. plot_fit_EEG_exp1
  51. ```
  52. ```{r}
  53. plot_pse_EEG_exp1_box <- ggplot(par_EEG_exp1%>% mutate(cond = factor(cond, levels = c("PS", "NS"))),aes(x=cond, y=pse, color = cond))+
  54. geom_boxplot(outlier.shape = NA) +
  55. geom_jitter(position=position_jitter(0.2))+
  56. geom_signif(comparisons=list(c("PS", "NS")), annotations="*", y_position = 1350, tip_length = 0, vjust=0.4, color = 'black') +
  57. labs(x = "Context", y = "PSE (ms)") +
  58. coord_cartesian(ylim = c(450,1500)) +
  59. scale_color_manual(values = colors_plot) +
  60. scale_fill_manual(values = colors_plot) +
  61. mytheme + theme(legend.position = "none")
  62. plot_pse_EEG_exp1_box
  63. ```
  64. ```{r}
  65. plot_jnd_EEG_exp1_box <- ggplot(par_EEG_exp1%>% mutate(cond = factor(cond, levels = c("PS", "NS"))),aes(x=cond, y=jnd, color = cond))+
  66. geom_boxplot(outlier.shape = NA) +
  67. geom_jitter(position=position_jitter(0.2))+
  68. labs(x = "Context", y = "JND (ms)") +
  69. coord_cartesian(ylim = c(0,250))+
  70. scale_color_manual(values = colors_plot) +
  71. scale_fill_manual(values = colors_plot) + mytheme + theme(legend.position = "none")
  72. plot_jnd_EEG_exp1_box
  73. ```
  74. ##figure2
  75. ```{r}
  76. figure1 <- cowplot::plot_grid(plot_fit_EEG_exp1, plot_pse_EEG_exp1_box, plot_jnd_EEG_exp1_box, nrow = 1, labels = c("a", "b", "c"), rel_widths = c(4,3,3))
  77. if (saveFigure == TRUE){
  78. ggsave("figures/figure2.png", figure1, width = 9, height = 4)
  79. }
  80. figure1
  81. ```
  82. ## Average fitted paramters and plot
  83. ```{r}
  84. mpse_EEG_exp1 = par_EEG_exp1%>%
  85. group_by(cond) %>%
  86. dplyr::summarise(m_pse = mean(pse), m_jnd = mean(jnd), n = n(),
  87. pse_se = sd(pse)/sqrt(n-1),
  88. jnd_se = sd(jnd)/sqrt(n-1))
  89. mpse_EEG_exp1
  90. ```
  91. ## ANOVA
  92. ```{r}
  93. Anova_EEG_exp1_pse <- ezANOVA(data = par_EEG_exp1, dv= pse, wid=SubName, within=.(cond))
  94. Anova_EEG_exp1_pse
  95. ```
  96. ```{r}
  97. Anova_EEG_exp1_jnd <- ezANOVA(data = par_EEG_exp1, dv= jnd, wid=SubName, within=.(cond))
  98. Anova_EEG_exp1_jnd
  99. ```
  100. # Experiment 2- Frequency Effect
  101. ## Fit psychometric functions
  102. ```{r}
  103. fits_EEG_exp2_v2 = quickpsy(dat_EEG_exp2, x = targetDur, k =RP, prob = .5,
  104. grouping = .(cond, SubName),
  105. fun = logistic_fun,
  106. thresholds = FALSE, bootstrap = 'none')
  107. ```
  108. ```{r, fig.cap= 'PSE: Bisection task performance in Experiment 2_v2'}
  109. # plot fitted function
  110. plot(fits_EEG_exp2_v2)+ mytheme
  111. ```
  112. ```{r}
  113. par_EEG_exp2_v2 <-fits_EEG_exp2_v2$par %>% dplyr::select(cond, SubName, parn, par) %>%
  114. pivot_wider(names_from = parn, values_from = par) %>%
  115. mutate(jnd = log(3)/p2)
  116. par_EEG_exp2_v2$pse <- par_EEG_exp2_v2$p1
  117. par_EEG_exp2_v2$p2 <- NULL
  118. par_EEG_exp2_v2$p1 <- NULL
  119. head(par_EEG_exp2_v2)
  120. ```
  121. ```{r}
  122. dat_EEG_exp2$cond= factor(dat_EEG_exp2$cond, levels=c("DF","AF"))
  123. fits_EEG_exp2_v2_all = quickpsy(dat_EEG_exp2, x = targetDur, k =RP,
  124. grouping = .(cond),
  125. fun = logistic_fun,
  126. thresholds = FALSE, bootstrap = 'none')
  127. fits_EEG_exp2_v2_all
  128. ```
  129. ## plot averaged
  130. ```{r, fig.cap= 'PSE: Bisection task performance in Experiment 2_v2'}
  131. # plot fitted function
  132. plot_fit_EEG_exp2_v2 <- plot(fits_EEG_exp2_v2_all) + mytheme+
  133. labs(x = "Target interval (ms)", y = "Proportion of 'long' responses") +
  134. scale_color_manual(values = colors_plot) +
  135. scale_fill_manual(values = colors_plot) +
  136. theme(legend.position = "top", legend.title = element_blank())
  137. plot_fit_EEG_exp2_v2
  138. ```
  139. ```{r}
  140. plot_pse_EEG_exp2_v2_box <- ggplot(par_EEG_exp2_v2%>% mutate(cond = factor(cond, levels = c("DF", "AF"))),aes(x=cond, y=pse, color = cond))+
  141. geom_boxplot() +
  142. geom_jitter(position=position_jitter(0.2))+
  143. geom_signif(comparisons=list(c("DF", "AF")), annotations="***", y_position = 1350, tip_length = 0, vjust=0.4, color = 'black') +
  144. labs(x = "Context", y = "PSE (ms)") +
  145. coord_cartesian(ylim = c(400,1500)) +
  146. scale_color_manual(values = colors_plot) +
  147. scale_fill_manual(values = colors_plot) +mytheme+theme(legend.position = "none")
  148. plot_pse_EEG_exp2_v2_box
  149. ```
  150. ```{r}
  151. plot_jnd_EEG_exp2_v2_box <- ggplot(par_EEG_exp2_v2%>% mutate(cond = factor(cond, levels = c("DF", "AF"))),aes(x=cond, y=jnd, color = cond))+
  152. geom_boxplot() +
  153. geom_jitter(position=position_jitter(0.2))+
  154. geom_signif(comparisons=list(c("DF", "AF")), annotations="**", y_position = 215, tip_length = 0, vjust=0.4, color = 'black')+mytheme+
  155. labs(x = "Context", y = "JND (ms)") +
  156. coord_cartesian(ylim = c(0,250))+
  157. scale_color_manual(values = colors_plot) +
  158. scale_fill_manual(values = colors_plot) + theme(legend.position = "none")
  159. plot_jnd_EEG_exp2_v2_box
  160. ```
  161. ##figure 4
  162. ```{r}
  163. figure4 <- cowplot::plot_grid(plot_fit_EEG_exp2_v2, plot_pse_EEG_exp2_v2_box, plot_jnd_EEG_exp2_v2_box, nrow = 1, labels = c("a", "b", "c"), rel_widths = c(4,3,3))
  164. if (saveFigure == TRUE){
  165. ggsave("figures/figure6.png", figure4, width = 9, height = 4)
  166. }
  167. figure4
  168. ```
  169. ## Average fitted parameters and plot
  170. ```{r}
  171. mpse_EEG_exp2_v2 = par_EEG_exp2_v2%>%
  172. group_by(cond) %>%
  173. dplyr::summarise(m_pse = mean(pse), m_jnd = mean(jnd), n = n(),
  174. pse_se = sd(pse)/sqrt(n-1),
  175. jnd_se = sd(jnd)/sqrt(n-1))
  176. mpse_EEG_exp2_v2
  177. ```
  178. ## ANOVA
  179. ```{r}
  180. Anova_EEG_exp2_v2_pse <- ezANOVA(data = par_EEG_exp2_v2, dv= pse, wid=SubName, within=.(cond))
  181. Anova_EEG_exp2_v2_pse
  182. ```
  183. ```{r}
  184. Anova_EEG_exp2_v2_jnd <- ezANOVA(data = par_EEG_exp2_v2, dv= jnd, wid=SubName, within=.(cond))
  185. Anova_EEG_exp2_v2_jnd
  186. ```