behavioral_analysis.Rmd 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ---
  2. title: "Blocked vs. Interleaved: How range contexts modulate time perception and its EEG signatures"
  3. author: "Cemre Baykan, Xiuna Zhu, Artyom Zinchenko, Zhuanghua Shi"
  4. date: "August 2023"
  5. ---
  6. ```{r setup, include=FALSE}
  7. knitr::opts_chunk$set(echo = TRUE)
  8. source('preproc_data.R')
  9. ```
  10. ```{r}
  11. m_dat= data_beh %>% dplyr::group_by(SubName,targetDur, cond, group) %>%
  12. dplyr::summarise(n = n(),m_err = mean(rep_err), se_err = sd(rep_err)/ sqrt(n))
  13. mm_dat= m_dat %>% dplyr::group_by(targetDur, cond, group) %>%
  14. dplyr::summarise(n = n(),mm_err = mean(m_err), mse_err = sd(m_err)/ sqrt(n))
  15. ```
  16. ```{r}
  17. m_dat_sub= m_dat %>% dplyr::group_by(SubName, cond, group) %>%
  18. dplyr::summarise(n = n(),mm_err = mean(m_err), mse_err = sd(m_err)/ sqrt(n))
  19. m_dat_sub %>% dplyr::group_by(cond, group) %>%
  20. dplyr::summarise(n = n(),mmm_err = mean(mm_err), mse_err = sd(mm_err)/ sqrt(n))
  21. ```
  22. ###plot
  23. ```{r}
  24. fig_mRep_exp1 = ggplot(mm_dat,
  25. aes(targetDur, mm_err, group = interaction(cond, group), color = cond)) +
  26. geom_point(size = 0.8) + geom_hline(yintercept = 0, linetype="dashed")+
  27. geom_line(data = mm_dat, size=0.8) +
  28. geom_errorbar(aes(ymin = mm_err- mse_err , ymax = mm_err + mse_err), width = 0.02) +
  29. theme_new + scale_color_manual(values = colors_plot) +
  30. theme(strip.background = element_blank()) +
  31. scale_x_continuous(breaks= c(400, 570, 800,1200,1700,2400), labels=c("400","566","800","1200","1700","2400"))+
  32. scale_y_continuous(breaks= c(-200, -100, 0,100,200), labels=c("-200","-100","0","100","200"))+
  33. labs(x = 'Target interval (ms)', y = 'Reproduction error (ms)', shape= '', color='')+ theme(legend.position=c(0.9,0.95))+ggtitle("")+
  34. theme(plot.title =element_text(size=12,face='bold'))
  35. #ggsave(file.path('figures','fig_beh.png'), fig_mRep_exp1, width = 4.3, height = 2.7)
  36. fig_mRep_exp1
  37. ```
  38. # LMM
  39. ```{r}
  40. m_dat$targetDur_n= m_dat$targetDur-1200
  41. m_dat$cond = as.factor(m_dat$cond)
  42. m_dat$group = as.factor(m_dat$group)
  43. m_dat= m_dat%>% dplyr::mutate(group= factor(group,levels=c("Upper","Lower")))
  44. contrasts(m_dat$cond) = contr.Sum(levels(m_dat$cond))
  45. contrasts(m_dat$group) = contr.Sum(levels(m_dat$group))
  46. ```
  47. ```{r}
  48. # fit the linear mixed model
  49. lmm2 = lmer(m_err ~ targetDur_n+ cond+ group+
  50. targetDur_n:cond + cond:group + # fixed effect and interaction
  51. (1|SubName), # random effect
  52. data = m_dat)
  53. #output as table
  54. tab_model(lmm2, p.val = 'kr') # Kenward-Roger approximation, alternative 'satterthwaite' approxmiation
  55. ```