figure_4.Rmd 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. ---
  2. title: "Spacek et al., 2021, Figure 4"
  3. output: pdf_document
  4. ---
  5. ```{r setup, include=FALSE}
  6. knitr::opts_chunk$set(echo = TRUE)
  7. library(arm)
  8. library(lmerTest)
  9. library(tidyverse)
  10. source('get_data.R')
  11. ```
  12. ```{r read_data, include=FALSE}
  13. tib = get_data("../csv/fig4.csv")
  14. ```
  15. # Figure 4a
  16. ## Modulation of firing rate by feedback during movie or grating presentations
  17. ```{r tidy_4a, include=F}
  18. # Grab conditions, in which a stimulus is shown
  19. t4a = tib %>% filter(blank == "False" & meanrate != "NA")
  20. # Turn stimtype into factor for dummy coding
  21. t4a$stimtype = as.factor(t4a$stimtype)
  22. ```
  23. ```{r fit_model_4a}
  24. # Random intercept for neurons
  25. lmer.4a = lmer(meanrate ~ stimtype + (1 | uid),
  26. data = t4a %>% drop_na(meanrate))
  27. display(lmer.4a)
  28. anova(lmer.4a)
  29. ```
  30. ```{r get_predicted_average_effect_4a, include=F}
  31. m_grt = fixef(lmer.4a)[1]
  32. m_mvi = fixef(lmer.4a)[1] + fixef(lmer.4a)[2]
  33. # Store coefficients in file
  34. pred_means_df = data.frame("grt" = m_grt, "mvi" = m_mvi, row.names = "")
  35. write_csv(pred_means_df, "_stats/figure_4a_pred_means.csv")
  36. ```
  37. Grating: FMI = `r format(m_grt, digits=2, nsmall=2)` \newline
  38. Movie: FMI = `r format(m_mvi, digits=2, nsmall=2)` \newline
  39. n = `r nrow(t4a %>% drop_na(meanrate) %>% count(uid))` neurons from `r nrow(t4a %>% drop_na(meanrate) %>% count(mid))` mice
  40. \newpage
  41. # Figure 4b
  42. ## Modulation of firing rate by feedback during gray screen conditions
  43. ```{r tidy_4b, include=FALSE}
  44. # We code the 'blank condition' as integers 1, 2, 3
  45. t4b = tib %>% mutate(blank_condition = case_when(
  46. stimtype == 'mvi' & blank == 'prestim' ~ 'mvi',
  47. stimtype == 'grt' & blank == 'prestim' ~ 'grt',
  48. stimtype == 'grt' & blank == 'cond' ~ 'grt0c'
  49. ))
  50. # Remove NAs
  51. t4b = t4b %>% filter(meanrate != "Na" & blank_condition != "Na")
  52. # And turn blank_condition into a factor for dummy coding
  53. t4b$blank_condition = as.factor(t4b$blank_condition)
  54. ```
  55. ```{r fit_model_4b}
  56. # Random intercept for neurons
  57. lmer.4b = lmer(meanrate ~ blank_condition + (1 | uid),
  58. data = t4b %>% drop_na(meanrate))
  59. display(lmer.4b)
  60. anova(lmer.4b)
  61. ```
  62. ```{r get_predicted_average_effect_4b, include=F}
  63. # Get predicted average burst ratios
  64. m_grt = fixef(lmer.4b)[1]
  65. m_grt0c = fixef(lmer.4b)[1] + fixef(lmer.4b)[2]
  66. m_mvi = fixef(lmer.4b)[1]+ fixef(lmer.4b)[3]
  67. # store results in file
  68. pred_means_df = data.frame("grt" = m_grt, "grt0c" = m_grt0c, "mvi" = m_mvi, row.names = "")
  69. write_csv(pred_means_df, "_stats/figure_4b_pred_means.csv")
  70. ```
  71. Blank before movie: FMI = `r format(m_mvi, digits=2, nsmall=2)` \newline
  72. Blank before grating: FMI = `r format(m_grt, digits=2, nsmall=2)` \newline
  73. Zero contrast grating: FMI = `r format(m_grt0c, digits=2, nsmall=2)` \newline
  74. n = `r nrow(t4b %>% drop_na(meanrate) %>% count(uid))` neurons from `r nrow(t4b %>% drop_na(meanrate) %>% count(mid))` mice
  75. ```{r tidy_for_I, include = F}
  76. t4_p = tib %>% filter(meanrate != "Na")
  77. t4_p = t4_p %>% mutate(stim_condition = case_when(
  78. stimtype == 'mvi' & blank == 'False' ~ 'mvi',
  79. stimtype == 'grt' & blank == 'False' ~ 'grt',
  80. (stimtype == 'mvi' | stimtype == 'grt') & blank != 'False' ~ 'blank'
  81. ))
  82. t4_p$stim_condition = as.factor(t4_p$stim_condition)
  83. # Is mean rate FMI for blanks different from the one for movies?
  84. t4_p1 = t4_p %>% filter(stim_condition != 'grt')
  85. ```
  86. \newpage
  87. ## (I) Pooling across blank conditions, and comparing against the FMI for movies
  88. ```{r fit_model_I}
  89. # Random intercept for neurons
  90. lmer.I = lmer(meanrate ~ stim_condition + (1 | uid),
  91. data = t4_p1 %>% drop_na(meanrate))
  92. display(lmer.I)
  93. anova(lmer.I)
  94. ```
  95. n = `r nrow(t4_p1 %>% drop_na(meanrate) %>% count(uid))` neurons from `r nrow(t4_p1 %>% drop_na(meanrate) %>% count(mid))` mice
  96. \newpage
  97. ## (II) Pooling across blank conditions, and comparing against the FMI for gratings
  98. ```{r tidy_for_II, include=F}
  99. # Is mean rate FMI for blanks different from the one for gratings?
  100. t4_p2 = t4_p %>% filter(stim_condition != 'mvi')
  101. ```
  102. ```{r fit_model_II}
  103. # Random intercept for neurons
  104. lmer.II = lmer(meanrate ~ stim_condition + (1 | uid), t4_p2)
  105. display(lmer.II)
  106. anova(lmer.II)
  107. ```
  108. n = `r nrow(t4_p2 %>% drop_na(meanrate) %>% count(uid))` neurons from `r nrow(t4_p2 %>% drop_na(meanrate) %>% count(mid))` mice