Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

figure_1_S6.Rmd 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. ---
  2. title: "Spacek et al., 2021, Figure 1-Supplement 6"
  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_pupil_diam, include=FALSE}
  13. # Read data
  14. tib_pupil = get_data("../csv/ipos_opto.csv")
  15. ```
  16. ```{r tidy_pupil_diam, include = FALSE}
  17. # Turn booleans for 'optogenetic manipulation' into a binary predictor
  18. tb_pupil <- tib_pupil %>% mutate(light_on = ifelse(opto == TRUE, 1, 0)) %>% drop_na(area_trialmean)
  19. ```
  20. ```{r do_stats_pupil_diam, include=FALSE}
  21. # On each data set (i.e., experiment) we run a 2-sample Kolmogorov-Smirnov test
  22. allds = unique(tb_pupil$mse)
  23. allstatistics = rep(NA, length(allds)) # KS statistic D
  24. allps = rep(NA, length(allds)) # p-values
  25. i = 1
  26. for (ids in allds) {
  27. df = tb_pupil %>% filter(mse == ids)
  28. res = ks.test(df$area_trialmean[df$light_on == 0], df$area_trialmean[df$light_on == 1])
  29. if (res$p.value >= 0.05) {
  30. print(paste(ids, ': p =', format(res$p.value, digits=2, nsmall=2)), quote = FALSE)
  31. }
  32. allps[i] = res$p.value
  33. allstatistics[i] = res$statistic
  34. i = i + 1
  35. }
  36. # Put together an array of those experiments that have comparable pupil diameters (valid experiments)
  37. validExps = allds[allps >= 0.05]
  38. ```
  39. For each experiment, we tested whether V1 suppression (i.e., turning on blue light) would affect pupil diameter.
  40. To do this, we performed a 2-sample Kolmogorov-Smirnov Test, comparing distributions of pupil diamter from trials with versus without V1 suppression.
  41. These are the experiments (n = `r length(validExps)` out of `r length(allds)`) with comparable distributions, across trials, of pupil diameter:
  42. ```{r print_results, echo=FALSE}
  43. writeLines(sprintf("%s, D = %1.2f, p = %1.3f", validExps, allstatistics[allps >= 0.05], allps[allps >= 0.05]))
  44. # save to file
  45. validExps_df = data.frame("selected_datasets" = validExps)
  46. write_csv(validExps_df, "_stats/datasets_figure_1_S6.csv")
  47. ```
  48. ```{r read_neural_data, include=FALSE}
  49. # Read data
  50. tib = get_data("../csv/fig1.csv")
  51. ```
  52. ```{r tidy_neural_data, include = FALSE}
  53. # Turn booleans for 'optogenetic manipulation' into a binary predictor
  54. tb <- tib %>% mutate(feedback = ifelse(opto == TRUE, 0, 1))
  55. ```
  56. \newpage
  57. # Figure 1-Supplement 6c
  58. ## Feedback effects on firing rate
  59. ```{r extract_valid_experiments, include=FALSE}
  60. tb_matched = filter(tb, grepl(paste(validExps, collapse="|"), mseu))
  61. ```
  62. ```{r fit_model_1_S6c}
  63. # We cannot simply repeat the identical analysis as for Figure 1f,
  64. # because with this reduced data set, that model doesn't converge.
  65. #
  66. # Without the random intercept for mice, however, the model converges - so here we fit:
  67. # Random intercept, random slope for neurons,
  68. # random intercept for experiments, nested in series
  69. lmer.1_S6c = lmer(rates ~ feedback + (1 + feedback | uid) + (1 | sid/eid),
  70. data = tb_matched %>% drop_na(rates))
  71. display(lmer.1_S6c)
  72. anova(lmer.1_S6c)
  73. ```
  74. ```{r get_predicted_average_effect_1f, include=F}
  75. mSuppr = fixef(lmer.1_S6c)[1]
  76. diffMeans = fixef(lmer.1_S6c)[2]
  77. mFeedbk = fixef(lmer.1_S6c)[1] + diffMeans
  78. ```
  79. Feedback: mean firing rate of `r format(mFeedbk, digits=2, nsmall=1)` spikes/s \newline
  80. Suppression: mean firing rate of `r format(mSuppr, digits=2, nsmall=1)` spikes/s \newline
  81. n = `r nrow(tb_matched %>% drop_na(rates) %>% count(uid))` neurons from `r nrow(tb_matched %>% drop_na(rates) %>% count(mid))` mice
  82. \newpage
  83. # Figure 1-Supplement 6d
  84. ## Feedback effects on burst ratio
  85. ```{r fit_model_1_S6d}
  86. # Random-intercept, random-slope for single neurons,
  87. # random intercept for experiments
  88. lmer.1_S6d = lmer(burstratios ~ feedback + (1 + feedback | uid) + (1 | eid),
  89. data = tb_matched %>% drop_na(burstratios))
  90. display(lmer.1_S6d)
  91. anova(lmer.1_S6d)
  92. ```
  93. ```{r get_predicted_average_effect_1_S6d, include=F}
  94. mSuppr = fixef(lmer.1_S6d)[1]
  95. diffMeans = fixef(lmer.1_S6d)[2]
  96. mFeedbk = fixef(lmer.1_S6d)[1] + diffMeans
  97. ```
  98. Feedback: mean burst ratio of `r format(mFeedbk, digits=1, nsmall=1)` \newline
  99. Suppression: mean burst ratio of `r format(mSuppr, digits=1, nsmall=1)` \newline
  100. n = `r nrow(tb_matched %>% drop_na(burstratios) %>% count(uid))` neurons from `r nrow(tb_matched %>% drop_na(burstratios) %>% count(mid))` mice
  101. \newpage
  102. # Figure 1-Supplement 6e
  103. ## Feedback effects on sparseness
  104. ```{r tidy_for_1_S6ef, include=FALSE}
  105. # 'Sparseness', and 'reliability' are not computed on a trial-by-trial basis. In the csv-file,
  106. # these two measures are therefore identical across trials, so we simply pull out the first trial of each neuron
  107. tb_matched_ef = tb_matched %>% select(mid, sid, eid, uid, mseu, feedback, spars, rel) %>% distinct(mseu, feedback, .keep_all = TRUE)
  108. ```
  109. ```{r fit_model_1_S6e}
  110. # Random-intercept, random-slope for single neurons,
  111. # random intercept for experiments, nested within series
  112. lmer.1_S6e = lmer(spars ~ feedback + (1 + feedback | uid) + (1 | sid/eid),
  113. data = tb_matched_ef %>% drop_na(spars))
  114. display(lmer.1_S6e)
  115. anova(lmer.1_S6e)
  116. ```
  117. ```{r get_predicted_average_effect_1_S6e, include=F}
  118. mSuppr = fixef(lmer.1_S6e)[1]
  119. diffMeans = fixef(lmer.1_S6e)[2]
  120. mFeedbk = fixef(lmer.1_S6e)[1] + diffMeans
  121. ```
  122. Feedback: `r format(mFeedbk, digits=2, nsmall=2)` \newline
  123. Suppression: `r format(mSuppr, digits=2, nsmall=2)` \newline
  124. n = `r nrow(tb_matched_ef %>% drop_na(spars) %>% count(uid))` neurons from `r nrow(tb_matched_ef %>% drop_na(spars) %>% count(mid))` mice
  125. \newpage
  126. # Figure 1-Supplement 6f
  127. ## Feedback effects on reliability
  128. ```{r fit_model_1S6_f}
  129. # Random-intercept, random-slope for single neurons,
  130. # random intercept for experiments, nested within series
  131. lmer.1_S6f = lmer(rel ~ feedback + (1 + feedback | uid) + (1 | sid/eid),
  132. data = tb_matched_ef %>% drop_na(rel))
  133. display(lmer.1_S6f)
  134. anova(lmer.1_S6f)
  135. ```
  136. ```{r get_predicted_average_effect_1i, include=F}
  137. mSuppr = fixef(lmer.1_S6f)[1]
  138. diffMeans = fixef(lmer.1_S6f)[2]
  139. mFeedbk = fixef(lmer.1_S6f)[1] + diffMeans
  140. ```
  141. Feedback: `r format(mFeedbk, digits=2, nsmall=2)` \newline
  142. Suppression: `r format(mSuppr, digits=2, nsmall=2)` \newline
  143. n = `r nrow(tb_matched_ef %>% drop_na(rel) %>% count(uid))` neurons from `r nrow(tb_matched_ef %>% drop_na(rel) %>% count(mid))` mice
  144. \newpage
  145. # Figure 1-Supplement 6g
  146. ## Relation between pupil area FMI and firing rate FMI
  147. ```{r read_data_1_S6_gi, include=FALSE}
  148. # Read data
  149. tib = get_data("../csv/iposmi.csv")
  150. ```
  151. ```{r fit_model_1_S6g}
  152. # Random intercept for neurons,
  153. # random intercept for experiments
  154. lmer.1_S6g = lmer(meanratefmi ~ areafmi + (1 | uid) + (1 | eid),
  155. data = tib %>% drop_na(meanratefmi, areafmi))
  156. display(lmer.1_S6g)
  157. anova(lmer.1_S6g)
  158. ```
  159. ```{r, store_coefficients_1_S6g, include=FALSE}
  160. coef_df = data.frame("intercept" = fixef(lmer.1_S6g)[1], "slope" = fixef(lmer.1_S6g)[2], row.names = "")
  161. write_csv(coef_df, "_stats/figure_1_S6g_coefs.csv")
  162. ```
  163. Slope of `r format(fixef(lmer.1_S6g)[2], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.1_S6g)[2], digits=2, nsmall=2)` \newline
  164. n = `r nrow(tib %>% drop_na(areafmi, meanratefmi) %>% count(uid))` neurons from `r nrow(tib %>% drop_na(areafmi, meanratefmi) %>% count(mid))` mice
  165. \newpage
  166. # Figure 1-Supplement 6i
  167. ## Relation between pupil area FMI and burst ratio FMI
  168. ```{r fit_model_1_S6i}
  169. # Random intercept for neurons,
  170. # random intercept for experiments, nested in series, nested in mice
  171. lmer.1_S6i = lmer(meanburstratiofmi ~ areafmi + (1 | uid) + (1 | mid/sid/eid),
  172. data = tib %>% drop_na(meanburstratiofmi, areafmi))
  173. display(lmer.1_S6i)
  174. anova(lmer.1_S6i)
  175. ```
  176. ```{r, store_coefficients_1_S6i, include=FALSE}
  177. coef_df = data.frame("intercept" = fixef(lmer.1_S6i)[1], "slope" = fixef(lmer.1_S6i)[2], row.names = "")
  178. write_csv(coef_df, "_stats/figure_1_S6i_coefs.csv")
  179. ```
  180. Slope of `r format(fixef(lmer.1_S6i)[2], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.1_S6i)[2], digits=2, nsmall=2)` \newline
  181. n = `r nrow(tib %>% drop_na(areafmi, meanburstratiofmi) %>% count(uid))` neurons from `r nrow(tib %>% drop_na(areafmi, meanburstratiofmi) %>% count(mid))` mice
  182. \newpage
  183. # Figure 1-Supplement 6h
  184. ## Relation between pupil area FMI and firing rate FMI (Ntsr1-Cre)
  185. ```{r read_data_1_S6_hj, include=FALSE}
  186. # Read data
  187. tib = get_data("../csv/ntsrmvis/iposmi.csv")
  188. ```
  189. ```{r fit_model_1_S6h}
  190. # Random intercept for neurons,
  191. # random intercept for experiments
  192. lmer.1_S6h = lmer(meanratefmi ~ areafmi + (1 | uid),
  193. data = tib %>% drop_na(meanratefmi, areafmi))
  194. display(lmer.1_S6h)
  195. anova(lmer.1_S6h)
  196. ```
  197. ```{r, store_coefficients_1_S6h, include=FALSE}
  198. coef_df = data.frame("intercept" = fixef(lmer.1_S6h)[1], "slope" = fixef(lmer.1_S6h)[2], row.names = "")
  199. write_csv(coef_df, "_stats/figure_1_S6h_coefs.csv")
  200. ```
  201. Slope of `r format(fixef(lmer.1_S6h)[2], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.1_S6h)[2], digits=2, nsmall=2)` \newline
  202. n = `r nrow(tib %>% drop_na(areafmi, meanratefmi) %>% count(uid))` neurons from `r nrow(tib %>% drop_na(areafmi, meanratefmi) %>% count(mid))` mice
  203. \newpage
  204. # Figure 1-Supplement 6j
  205. ## Relation between pupil area FMI and burst ratio FMI (Ntsr1-Cre)
  206. ```{r fit_model_1_S6j}
  207. # Random intercept for neurons,
  208. # random intercept for experiments, nested in series, nested in mice
  209. lmer.1_S6j = lmer(meanburstratiofmi ~ areafmi + (1 | uid) + (1 | sid/eid),
  210. data = tib %>% drop_na(meanburstratiofmi, areafmi))
  211. display(lmer.1_S6j)
  212. anova(lmer.1_S6j)
  213. ```
  214. ```{r, store_coefficients_1_S6j, include=FALSE}
  215. coef_df = data.frame("intercept" = fixef(lmer.1_S6j)[1], "slope" = fixef(lmer.1_S6j)[2], row.names = "")
  216. write_csv(coef_df, "_stats/figure_1_S6j_coefs.csv")
  217. ```
  218. Slope of `r format(fixef(lmer.1_S6j)[2], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.1_S6j)[2], digits=2, nsmall=2)` \newline
  219. n = `r nrow(tib %>% drop_na(areafmi, meanburstratiofmi) %>% count(uid))` neurons from `r nrow(tib %>% drop_na(areafmi, meanburstratiofmi) %>% count(mid))` mice