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_6.Rmd 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. ---
  2. title: "Spacek et al., 2021, Figure 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. library(data.table)
  11. source('get_data.R')
  12. ```
  13. ```{r read_data, include=FALSE}
  14. tib = get_data("../csv/fig6.csv")
  15. tib <- tib %>% filter(stimtype == "mvi") %>% select(mid, sid, eid, uid, mseu, mi, meanrate, meanburstratio, spars, rel)
  16. ```
  17. ```{r tidy_for_6a_1, include = FALSE}
  18. # Select relevant columns
  19. tb <- tib %>% filter(mi == "suppressionrmi" | mi == "feedbackrmi")
  20. # Turn long format into wide format, using data.tables and dcast:
  21. foo = dcast(setDT(tb), mid + sid + eid + uid + mseu ~ mi, value.var = "meanrate")
  22. tbw = as_tibble(foo)
  23. ```
  24. # Figure 6a$_1$
  25. ## (1) Comparing RMI during suppression against 0
  26. ```{r, fit_model_6a1_1}
  27. # Fixed effect intercept only,
  28. # random intercept for neurons,
  29. # random intercept for experiments, nested within series
  30. lmer.6a1.1 = lmer(suppressionrmi ~ 1 + (1 | uid) + (1 | sid/eid),
  31. data = tbw %>% drop_na(suppressionrmi))
  32. display(lmer.6a1.1)
  33. ```
  34. ## Mean firing rate RMI
  35. Suppression: RMI = `r format(fixef(lmer.6a1.1)[1], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.6a1.1)[1], digits=1, nsmall=1)` \newline
  36. n = `r nrow(tbw %>% drop_na(suppressionrmi) %>% count(uid))` neurons from `r nrow(tbw %>% drop_na(suppressionrmi) %>% count(mid))` mice
  37. \newpage
  38. # Figure 6a$_1$
  39. ## (2) Slope of regression line
  40. ```{r fit_model_6a1_2}
  41. # Random intercept for neurons,
  42. # random intercept for experiments, nested in series
  43. lmer.6a1.2 = lmer(feedbackrmi ~ suppressionrmi + (1 | uid) + (1 | sid/eid),
  44. data = tbw %>% drop_na(feedbackrmi, suppressionrmi))
  45. display(lmer.6a1.2)
  46. anova(lmer.6a1.2)
  47. ```
  48. ``` {r save_coefficients_6a1_2, include=FALSE}
  49. coef_df = data.frame("intercept" = fixef(lmer.6a1.2)[1], "slope" = fixef(lmer.6a1.2)[2], row.names = "")
  50. write_csv(coef_df, "_stats/figure_6a1_coefs.csv")
  51. ```
  52. Slope = `r format(fixef(lmer.6a1.2)[2], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.6a1.2)[2], digits=2, nsmall=2)` \newline
  53. n = `r nrow(tbw %>% drop_na(feedbackrmi, suppressionrmi) %>% count(uid))` neurons from `r nrow(tbw %>% drop_na(feedbackrmi, suppressionrmi) %>% count(mid))` mice
  54. \newpage
  55. # Figure 6a$_1$
  56. ## (3) Average effect of feedback on firing rate RMI
  57. ```{r, tidy_for_6a1_3, include=F}
  58. # Turn wide format back into long format
  59. foo = melt(setDT(tbw), measure=c("feedbackrmi", "suppressionrmi"), value.name="meanrate", variable.name = "feedback")
  60. tbl = as_tibble(foo)
  61. # Code feedback as binary factor
  62. tbl$feedback = ifelse(tbl$feedback == "feedbackrmi", 1, 0)
  63. ```
  64. ```{r fit_model_6a1_3}
  65. # Random intercept for neurons,
  66. # random intercept for experiments, nested in series
  67. lmer.6a1.3 = lmer(meanrate ~ feedback + (1 | uid) + (1 | sid/eid),
  68. data = tbl %>% drop_na(meanrate))
  69. display(lmer.6a1.3)
  70. anova(lmer.6a1.3)
  71. ```
  72. ```{r get_predicted_average_effect_6a1_3, include=F}
  73. m_suppress = fixef(lmer.6a1.3)[1]
  74. diffMeans = fixef(lmer.6a1.3)[2]
  75. m_feedback = fixef(lmer.6a1.3)[1] + diffMeans
  76. ```
  77. ## Predicted average effect on firing rate RMI
  78. Feedback: RMI = `r format(m_feedback, digits=2, nsmall=2)` \newline
  79. Suppression: RMI = `r format(m_suppress, digits=2, nsmall=2)` \newline
  80. n = `r nrow(tbl %>% drop_na(meanrate) %>% count(uid))` neurons from `r nrow(tbl %>% drop_na(meanrate) %>% count(mid))` mice
  81. \newpage
  82. # Figure 6a$_2$
  83. ```{r tidy_for_6a2, include = FALSE}
  84. # Turn long format into wide format, using data.tables and dcast:
  85. foo = dcast(setDT(tb), mid + sid + eid + uid + mseu ~ mi, value.var = "meanburstratio")
  86. tbw = as_tibble(foo)
  87. # remove outliers
  88. tbw_clean <- tbw %>% filter(suppressionrmi < 0.95 & feedbackrmi < 0.95)
  89. ```
  90. ## (1) Comparing RMI during suppression against 0
  91. ```{r fit_model_6a2_1}
  92. # Fixed effect intercept only,
  93. # random intercept for neurons,
  94. # random intercept for experiments,nested in series
  95. lmer.6a2.1 = lmer(suppressionrmi ~ 1 + (1 | uid) + (1 | sid/eid),
  96. data = tbw_clean %>% drop_na(suppressionrmi))
  97. display(lmer.6a2.1)
  98. ```
  99. ## Mean burst ratio RMI
  100. Suppression: RMI = `r format(fixef(lmer.6a2.1)[1], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.6a2.1)[1], digits=1, nsmall=1)` \newline
  101. n = `r nrow(tbw_clean %>% drop_na(suppressionrmi) %>% count(uid))` neurons from `r nrow(tbw_clean %>% drop_na(suppressionrmi) %>% count(mid))` mice
  102. \newpage
  103. # Figure 6a$_2$
  104. ## (2) Slope of regression line
  105. ```{r fit_model_6a2_2}
  106. # Random intercept for neurons,
  107. # random intercept for experiments, nested in series
  108. lmer.6a2.2 = lmer(feedbackrmi ~ suppressionrmi + (1 | uid) + (1 | sid/eid),
  109. data = tbw_clean %>% drop_na(feedbackrmi, suppressionrmi))
  110. display(lmer.6a2.2)
  111. anova(lmer.6a2.2)
  112. ```
  113. ``` {r save_coefficients_6a2_2, include=F}
  114. coef_df = data.frame("intercept" = fixef(lmer.6a2.2)[1], "slope" = fixef(lmer.6a2.2)[2], row.names = "")
  115. write_csv(coef_df, "_stats/figure_6a2_coefs.csv")
  116. ```
  117. Slope = `r format(fixef(lmer.6a2.2)[2], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.6a2.2)[2], digits=1, nsmall=1)` \newline
  118. n = `r nrow(tbw_clean %>% drop_na(feedbackrmi, suppressionrmi) %>% count(uid))` neurons from
  119. `r nrow(tbw_clean %>% drop_na(feedbackrmi, suppressionrmi) %>% count(mid))` mice
  120. \newpage
  121. # Figure 6a$_2$
  122. ## (3) Average effect of feedback on burst ratio RMI
  123. ```{r, tidy_for_6a2_3, include=F}
  124. # Turn wide format back into long format
  125. foo = melt(setDT(tbw_clean), measure=c("feedbackrmi", "suppressionrmi"), value.name="meanburstratio", variable.name = "feedback")
  126. tbl = as_tibble(foo)
  127. # Code feedback as binary variable
  128. tbl$feedback = ifelse(tbl$feedback == "feedbackrmi", 1, 0)
  129. ```
  130. ```{r fit_model_6a2_3}
  131. # Random intercept for neurons,
  132. # random intercept for experiments, nested in series, nested in mice
  133. lmer.6a2.3 = lmer(meanburstratio ~ feedback + (1 | uid) + (1 | mid/sid/eid),
  134. data = tbl %>% drop_na(meanburstratio))
  135. display(lmer.6a2.3)
  136. anova(lmer.6a2.3)
  137. ```
  138. ```{r get_predicted_average_effect_6a2_3, include=F}
  139. m_suppress = fixef(lmer.6a2.3)[1]
  140. diffMeans = fixef(lmer.6a2.3)[2]
  141. m_feedback = fixef(lmer.6a2.3)[1] + diffMeans
  142. ```
  143. ## Predicted average effect on burst ratio RMI
  144. Feedback: RMI = `r format(m_feedback, digits=2, nsmall=2)` \newline
  145. Suppression: RMI = `r format(m_suppress, digits=2, nsmall=2)`\newline
  146. n = `r nrow(tbl %>% drop_na(meanburstratio) %>% count(uid))` neurons from `r nrow(tbl %>% drop_na(meanburstratio) %>% count(mid))` mice
  147. \newpage
  148. # Figure 6a$_3$
  149. ```{r tidy_for_6a3, include = FALSE}
  150. # Turn long format into wide format, using data.tables and dcast:
  151. foo = dcast(setDT(tb), mid + sid + eid + uid + mseu ~ mi, value.var = "spars")
  152. tbw = as_tibble(foo)
  153. ```
  154. ## (1) Comparing RMI during suppression against 0
  155. ```{r, fit_model_6a3_1}
  156. # Fixed effect intercept only,
  157. # random intercept for neurons,
  158. # random intercept for experiments, nested in series
  159. lmer.6a3.1 = lmer(suppressionrmi ~ 1 + (1 | uid) + (1 | sid/eid),
  160. data = tbw %>% drop_na(suppressionrmi))
  161. display(lmer.6a3.1)
  162. ```
  163. ## Mean sparseness RMI
  164. Suppression: RMI = `r format(fixef(lmer.6a3.1)[1], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.6a3.1)[1], digits=1, nsmall=1)` \newline
  165. n = `r nrow(tbw %>% drop_na(suppressionrmi) %>% count(uid))` neurons from `r nrow(tbw %>% drop_na(suppressionrmi) %>% count(mid))` mice
  166. \newpage
  167. # Figure 6a$_3$
  168. ## (2) Slope of regression line
  169. ```{r fit_model_6a3_2}
  170. # Random intercept for neurons,
  171. # random intercept for experiments, nested in series
  172. lmer.6a3.2 = lmer(feedbackrmi ~ suppressionrmi + (1 | uid) + (1 | sid/eid),
  173. data = tbw %>% drop_na(feedbackrmi, suppressionrmi))
  174. display(lmer.6a3.2)
  175. anova(lmer.6a3.2)
  176. ```
  177. ``` {r save_coefficients_6a3_2, include=F}
  178. coef_df = data.frame("intercept" = fixef(lmer.6a3.2)[1], "slope" = fixef(lmer.6a3.2)[2], row.names = "")
  179. write_csv(coef_df, "_stats/figure_6a3_coefs.csv")
  180. ```
  181. ## Regression line parameters
  182. Slope of `r format(fixef(lmer.6a3.2)[2], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.6a3.2)[2], digits=2, nsmall=2)` \newline
  183. n = `r nrow(tbw %>% drop_na(feedbackrmi, suppressionrmi) %>% count(uid))` neurons from `r nrow(tbw %>% drop_na(feedbackrmi, suppressionrmi) %>% count(mid))` mice
  184. \newpage
  185. # Figure 6a$_3$
  186. ## (3) Average effect of feedback on sparseness RMI
  187. ```{r, tidy_for_6a3_3, include=F}
  188. # Turn wide format back into long format
  189. foo = melt(setDT(tbw), measure=c("feedbackrmi", "suppressionrmi"), value.name="spars", variable.name = "feedback")
  190. tbl = as_tibble(foo)
  191. # Code feedback as binary variable
  192. tbl$feedback = ifelse(tbl$feedback == "feedbackrmi", 1, 0)
  193. ```
  194. ```{r, fit_model_6a3_3}
  195. # Random intercept for neurons,
  196. # random intercept for experiments, nested in series
  197. lmer.6a3.3 = lmer(spars ~ feedback + (1 | uid) + (1 | sid/eid),
  198. data = tbl %>% drop_na(spars))
  199. display(lmer.6a3.3)
  200. anova(lmer.6a3.3)
  201. ```
  202. ```{r get_predicted_average_effect_6a3_3, include=F}
  203. m_suppress = fixef(lmer.6a3.3)[1]
  204. diffMeans = fixef(lmer.6a3.3)[2]
  205. m_feedback = fixef(lmer.6a3.3)[1] + diffMeans
  206. ```
  207. ## Predicted average effect on sparseness RMI
  208. Feedback: Sparseness = `r format(m_feedback, digits=2, nsmall=2)` \newline
  209. Suppression: Sparseness = `r format(m_suppress, digits=2, nsmall=2)` \newline
  210. n = `r nrow(tbl %>% drop_na(spars) %>% count(uid))` neurons from `r nrow(tbl %>% drop_na(spars) %>% count(mid))` mice
  211. \newpage
  212. # Figure 6a$_4$
  213. ```{r, tidy_for_6a4, include=F}
  214. # Turn long format into wide format, using data.tables and dcast:
  215. foo = dcast(setDT(tb), mid + sid + eid + uid + mseu ~ mi, value.var = "rel")
  216. tbw = as_tibble(foo)
  217. # remove outliers
  218. tbw_clean <- tbw %>% filter(suppressionrmi > -0.99 & suppressionrmi < 0.99 & feedbackrmi > -0.99 & feedbackrmi < 0.99 )
  219. ```
  220. ## (1) Comparing RMI during suppression against 0
  221. ```{r, fit_model_6a4_1}
  222. # Fixed effect intercept only,
  223. # random intercept for neurons
  224. # random intercept for experiments
  225. lmer.6a4.1 = lmer(suppressionrmi ~ 1 + (1 | uid) + (1 | eid),
  226. data = tbw_clean %>% drop_na(suppressionrmi))
  227. display(lmer.6a4.1)
  228. ```
  229. ## Mean reliability RMI
  230. Suppression: RMI = `r format(fixef(lmer.6a4.1)[1], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.6a4.1)[1], digits=1, nsmall=1)` \newline
  231. n = `r nrow(tbw_clean %>% drop_na(suppressionrmi) %>% count(uid))` neurons from `r nrow(tbw_clean %>% drop_na(suppressionrmi) %>% count(mid))` mice
  232. \newpage
  233. # Figure 6a$_4$
  234. ## (2) Slope of regression line
  235. ```{r fit_model_6a4_2}
  236. # Random intercept for neurons,
  237. # random intercept for experiments
  238. lmer.6a4.2 = lmer(feedbackrmi ~ suppressionrmi + (1 | uid) + (1 | eid),
  239. data = tbw_clean %>% drop_na(feedbackrmi, suppressionrmi))
  240. display(lmer.6a4.2)
  241. anova(lmer.6a4.2)
  242. ```
  243. ``` {r save_coefficients_6a4_2, include=FALSE}
  244. coef_df = data.frame("intercept" = fixef(lmer.6a4.2)[1], "slope" = fixef(lmer.6a4.2)[2], row.names = "")
  245. write_csv(coef_df, "_stats/figure_6a4_coefs.csv")
  246. ```
  247. Slope of `r format(fixef(lmer.6a4.2)[2], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.6a4.2)[2], digits=2, nsmall=2)` \newline
  248. n = `r nrow(tbw_clean %>% drop_na(feedbackrmi, suppressionrmi) %>% count(uid))` neurons from
  249. `r nrow(tbw_clean %>% drop_na(feedbackrmi, suppressionrmi) %>% count(mid))` mice
  250. \newpage
  251. # Figure 6a$_4$
  252. ## (3) Average effect of feedback on reliability RMI
  253. ```{r, tidy_for_6a4_3, include=F}
  254. # Turn wide format back into long format
  255. foo = melt(setDT(tbw_clean), measure=c("feedbackrmi", "suppressionrmi"), value.name="rel", variable.name = "feedback")
  256. tbl = as_tibble(foo)
  257. # Code feedback as binary variable
  258. tbl$feedback = ifelse(tbl$feedback == "feedbackrmi", 1, 0)
  259. ```
  260. ```{r fit_model_6a4_3}
  261. # Random intercept for neurons,
  262. # random intercept for experiments, nested in series
  263. lmer.6a4.3 = lmer(rel ~ feedback + (1 | uid) + (1 | sid/eid),
  264. data = tbl %>% drop_na(rel))
  265. display(lmer.6a4.3)
  266. anova(lmer.6a4.3)
  267. ```
  268. ```{r get_predicted_average_effect_6a4_4, include=F}
  269. m_suppress = fixef(lmer.6a4.3)[1]
  270. diffMeans = fixef(lmer.6a4.3)[2]
  271. m_feedback = fixef(lmer.6a4.3)[1] + diffMeans
  272. ```
  273. ## Predicted average effect on reliability RMI
  274. Feedback: RMI = `r format(m_feedback, digits=2, nsmall=2)` \newline
  275. Suppression: RMI = `r format(m_suppress, digits=2, nsmall=2)` \newline
  276. n = `r nrow(tbl %>% drop_na(rel) %>% count(uid))` neurons from `r nrow(tbl %>% drop_na(rel) %>% count(mid))` mice
  277. \newpage
  278. # Figure 6b$_1$
  279. ```{r tidy_for_6b1_1, include = FALSE}
  280. tb <- tib %>% filter(mi == "sitfmi" | mi == "runfmi")
  281. # Turn long format into wide format, using data.tables and dcast:
  282. foo = dcast(setDT(tb), mid + sid + eid + uid + mseu ~ mi, value.var = "meanrate")
  283. tbw = as_tibble(foo)
  284. ```
  285. ## (1) Slope of regression line
  286. ```{r fit_model_6b1_1}
  287. # Random intercept for neurons,
  288. # random intercept for experiments, nested in series
  289. lmer.6b1_1 = lmer(runfmi ~ sitfmi + (1 | uid) + (1 | sid/eid),
  290. data = tbw %>% drop_na(runfmi, sitfmi))
  291. display(lmer.6b1_1)
  292. anova(lmer.6b1_1)
  293. ```
  294. ``` {r store_coefficients_6b1_1, include=FALSE}
  295. coef_df = data.frame("intercept" = fixef(lmer.6b1_1)[1], "slope" = fixef(lmer.6b1_1)[2], row.names = "")
  296. write_csv(coef_df, "_stats/figure_6b1_coefs.csv")
  297. ```
  298. Slope of `r format(fixef(lmer.6b1_1)[2], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.6b1_1)[2], digits=2, nsmall=2)` \newline
  299. n = `r nrow(tbw %>% drop_na(runfmi, sitfmi) %>% count(uid))` neurons from `r nrow(tbw %>% drop_na(runfmi, sitfmi) %>% count(mid))` mice
  300. \newpage
  301. # Figure 6b$_1$
  302. ## (2) Average effect of locomotion state on firing rate FMI
  303. ```{r, tidy_for_6b1_2, include=F}
  304. # Turn wide format back into long format
  305. foo = melt(setDT(tbw), measure=c("sitfmi", "runfmi"), value.name="meanrate", variable.name = "run")
  306. tbl = as_tibble(foo)
  307. # Code locomotion state as binary variable
  308. tbl$run = ifelse(tbl$run == "runfmi", 1, 0)
  309. ```
  310. ```{r fit_model_6b1_2}
  311. # Random intercept for neurons,
  312. # random intercept for experiments
  313. lmer.6b1_2 = lmer(meanrate ~ run + (1 | uid) + (1 | eid),
  314. data = tbl %>% drop_na(meanrate))
  315. display(lmer.6b1_2)
  316. anova(lmer.6b1_2)
  317. ```
  318. ```{r get_predicted_average_effect_6b1_2, include=F}
  319. m_sit = fixef(lmer.6b1_2)[1]
  320. diffMeans = fixef(lmer.6b1_2)[2]
  321. m_run = fixef(lmer.6b1_2)[1] + diffMeans
  322. ```
  323. ## Predicted average effect on firing rate FMI
  324. Locomotion: `r format(m_run, digits=2, nsmall=2)` \newline
  325. Quiescence: `r format(m_sit, digits=2, nsmall=2)` \newline
  326. n = `r nrow(tbl %>% drop_na(meanrate) %>% count(uid))` neurons from `r nrow(tbl %>% drop_na(meanrate) %>% count(mid))` mice
  327. \newpage
  328. # Figure 6b$_2$
  329. ```{r tidy_for_6b2_1, include = FALSE}
  330. tb <- tib %>% filter(mi == "sitfmi" | mi == "runfmi")
  331. # Turn long format into wide format, using data.tables and dcast:
  332. foo = dcast(setDT(tb), mid + sid + eid + uid + mseu ~ mi, value.var = "meanburstratio")
  333. tbw = as_tibble(foo)
  334. # Remove NaNs
  335. tbw <- tbw %>% filter(sitfmi != "Na" & runfmi != "Na")
  336. # remove two outliers
  337. tbw_clean <- tbw %>% filter(runfmi < 0.99 & sitfmi < 0.99)
  338. ```
  339. ## (1) Slope of regression line
  340. ```{r fit_model_6b2_1}
  341. # Random intercept for neurons,
  342. # random effect for experiments, nested in series
  343. lmer.6b2_1 = lmer(runfmi ~ sitfmi + (1 | uid) + (1 | sid/eid),
  344. data = tbw_clean %>% drop_na(runfmi, sitfmi))
  345. display(lmer.6b2_1)
  346. anova(lmer.6b2_1)
  347. ```
  348. ```{r store_coefficients_6b2_1, include=FALSE}
  349. # store results in file
  350. coef_df = data.frame("intercept" = fixef(lmer.6b2_1)[1], "slope" = fixef(lmer.6b2_1)[2], row.names = "")
  351. write_csv(coef_df, "_stats/figure_6b2_coefs.csv")
  352. ```
  353. \textbf{Note: the 2 outliers sitting in the top left and bottom right corner have been exluded before fitting the model!}
  354. Slope of `r format(fixef(lmer.6b2_1)[2], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.6b2_1)[2], digits=2, nsmall=2)` \newline
  355. n = `r nrow(tbw_clean %>% drop_na(runfmi, sitfmi) %>% count(uid))` neurons from `r nrow(tbw_clean %>% drop_na(runfmi, sitfmi) %>% count(mid))` mice
  356. \newpage
  357. # Figure 6b$_2$
  358. ## (2) Average effect of locomotion state on burst ratio FMI
  359. ```{r, tidy_for_6b2_2, include=F}
  360. # Turn wide format back into long format
  361. foo = melt(setDT(tbw_clean), measure=c("sitfmi", "runfmi"), value.name="meanburstratio", variable.name = "run")
  362. tbl_clean = as_tibble(foo)
  363. # Code locomotion state as binary variable
  364. tbl_clean$run = ifelse(tbl_clean$run == "runfmi", 1, 0)
  365. ```
  366. ```{r fit_model_6b2_2}
  367. # Random intercept for neurons,
  368. # random intercept for series
  369. lmer.6b2_2 = lmer(meanburstratio ~ run + (1 | uid) + (1 | sid),
  370. data = tbl_clean %>% drop_na(meanburstratio))
  371. display(lmer.6b2_2)
  372. anova(lmer.6b2_2)
  373. ```
  374. ```{r get_predicted_average_effect_6b2_2, include=F}
  375. m_sit = fixef(lmer.6b2_2)[1]
  376. diffMeans = fixef(lmer.6b2_2)[2]
  377. m_run = fixef(lmer.6b2_2)[1] + diffMeans
  378. ```
  379. ## Predicted average effect on burst ratio FMI
  380. \textbf{Note: the 2 outliers sitting in the top left and bottom right corner have been exluded before fitting the model!}
  381. Locomotion: `r format(m_run, digits=2, nsmall=2)` \newline
  382. Quiescence: `r format(m_sit, digits=2, nsmall=2)` \newline
  383. n = `r nrow(tbl_clean %>% drop_na(meanburstratio) %>% count(uid))` neurons from `r nrow(tbl_clean %>% drop_na(meanburstratio) %>% count(mid))` mice
  384. \newpage
  385. # Figure 6b$_3$
  386. ```{r tidy_for_6b3_1, include=FALSE}
  387. tb <- tib %>% filter(mi == "sitfmi" | mi == "runfmi")
  388. # Turn long format into wide format, using data.tables and dcast:
  389. foo = dcast(setDT(tb), mid + sid + eid + uid + mseu ~ mi, value.var = "spars")
  390. tbw = as_tibble(foo)
  391. ```
  392. ## (1) Slope of regression line
  393. ```{r fit_model_6b3_1}
  394. # Random intercept for neurons,
  395. # random intercept for experiments, nested in series
  396. lmer.6b3_1 = lmer(runfmi ~ sitfmi + (1 | uid) + (1 | sid/eid),
  397. data = tbw %>% drop_na(runfmi, sitfmi))
  398. display(lmer.6b3_1)
  399. anova(lmer.6b3_1)
  400. ```
  401. ```{r store_coefficients_6b3_1, include=FALSE}
  402. # store results in file
  403. coef_df = data.frame("intercept" = fixef(lmer.6b3_1)[1], "slope" = fixef(lmer.6b3_1)[2], row.names = "")
  404. write_csv(coef_df, "_stats/figure_6b3_coefs.csv")
  405. ```
  406. Slope of `r format(fixef(lmer.6b3_1)[2], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.6b3_1)[2], digits=2, nsmall=2)` \newline
  407. n = `r nrow(tbw %>% drop_na(runfmi, sitfmi) %>% count(uid))` neurons from `r nrow(tbw %>% drop_na(runfmi, sitfmi) %>% count(mid))` mice
  408. \newpage
  409. # Figure 6b$_3$
  410. ## (2) Average effect of locomotion state on sparseness
  411. ```{r, tidy_for_6b3_2, include=F}
  412. # Turn wide format back into long format
  413. foo = melt(setDT(tbw), measure=c("sitfmi", "runfmi"), value.name="spars", variable.name = "run")
  414. tbl = as_tibble(foo)
  415. # Code locomotion state as binary variable
  416. tbl$run = ifelse(tbl$run == "runfmi", 1, 0)
  417. ```
  418. ```{r fit_model_6b3_2}
  419. # Random intercept for neurons,
  420. # random intercept for experiments, nested in series
  421. lmer.6b3_2 = lmer(spars ~ run + (1 | uid) + (1 | sid/eid),
  422. data = tbl %>% drop_na(spars))
  423. display(lmer.6b3_2)
  424. anova(lmer.6b3_2)
  425. ```
  426. ```{r get_predicted_average_effect_6b3_2, include=F}
  427. m_sit = fixef(lmer.6b3_2)[1]
  428. diffMeans = fixef(lmer.6b3_2)[2]
  429. m_run = fixef(lmer.6b3_2)[1] + diffMeans
  430. ```
  431. ## Predicted average effect sparseness FMI
  432. Quiescence: `r format(m_sit, digits=2, nsmall=2)` \newline
  433. Locomotion: `r format(m_run, digits=2, nsmall=2)` \newline
  434. n = `r nrow(tbl %>% drop_na(spars) %>% count(uid))` neurons from `r nrow(tbl %>% drop_na(spars) %>% count(mid))` mice
  435. \newpage
  436. # Figure 6b$_4$
  437. ```{r tidy_for_6b4_1, include = FALSE}
  438. tb <- tib %>% filter(mi == "sitfmi" | mi == "runfmi")
  439. # Turn long format into wide format, using data.tables and dcast:
  440. foo = dcast(setDT(tb), mid + sid + eid + uid + mseu ~ mi, value.var = "rel")
  441. tbw = as_tibble(foo)
  442. # remove outliers
  443. tbw_clean <- tbw %>% filter(runfmi < 0.99 & runfmi > -0.99 & sitfmi < 0.95 & sitfmi > -0.99)
  444. ```
  445. ## (1) Slope of regression line
  446. ```{r fit_model_6b4_1}
  447. # Random intercept for neurons,
  448. # random intercept for experiments
  449. lmer.6b4_1 = lmer(runfmi ~ sitfmi + (1 | uid) + (1 | eid),
  450. data = tbw_clean %>% drop_na(runfmi, sitfmi))
  451. display(lmer.6b4_1)
  452. anova(lmer.6b4_1)
  453. ```
  454. ```{r, store_coefficients_6b4_1, include=FALSE}
  455. coef_df = data.frame("intercept" = fixef(lmer.6b4_1)[1], "slope" = fixef(lmer.6b4_1)[2], row.names = "")
  456. write_csv(coef_df, "_stats/figure_6b4_coefs.csv")
  457. ```
  458. \textbf{Note: Outliers (11 observations) been exluded before fitting the model!}
  459. Slope of `r format(fixef(lmer.6b4_1)[2], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.6b4_1)[2], digits=2, nsmall=2)` \newline
  460. n = `r nrow(tbw_clean %>% drop_na(runfmi, sitfmi) %>% count(uid))` neurons from `r nrow(tbw_clean %>% drop_na(runfmi, sitfmi) %>% count(mid))` mice
  461. \newpage
  462. # Figure 6b$_4$
  463. ## (2) Average effect of locomotion state on reliability
  464. ```{r, tidy_for_6b4_2, include=F}
  465. # Turn wide format back into long format
  466. foo = melt(setDT(tbw_clean), measure=c("sitfmi", "runfmi"), value.name="rel", variable.name = "run")
  467. tbl_clean = as_tibble(foo)
  468. # Code locomotion state as binary variable
  469. tbl_clean$run = ifelse(tbl_clean$run == "runfmi", 1, 0)
  470. ```
  471. ```{r fit_model_6b4_2}
  472. # Random intercept for neurons,
  473. # random intercept for experiments, nested in series, nested in mice
  474. lmer.6b4_2 = lmer(rel ~ run + (1 | uid) + (1 | mid/sid/eid),
  475. data = tbl_clean %>% drop_na(rel))
  476. display(lmer.6b4_2)
  477. anova(lmer.6b4_2)
  478. ```
  479. ```{r get_predicted_average_effect_6b4_2, include=F}
  480. m_sit = fixef(lmer.6b4_2)[1]
  481. diffMeans = fixef(lmer.6b4_2)[2]
  482. m_run = fixef(lmer.6b4_2)[1] + diffMeans
  483. ```
  484. ## Predicted average effect reliability FMI
  485. \textbf{Note: Outliers (11 observations) been exluded before fitting the model!}
  486. Quiescence: `r format(m_sit, digits=2, nsmall=2)` \newline
  487. Locomotion: `r format(m_run, digits=2, nsmall=2)` \newline
  488. n = `r nrow(tbl_clean %>% drop_na(rel) %>% count(uid))` neurons from `r nrow(tbl_clean %>% drop_na(rel) %>% count(mid))` mice
  489. \newpage
  490. # Figure 6c$_1$
  491. ## Slope of regression line
  492. ```{r tidy_for_6c1, include = FALSE}
  493. tb <- tib %>% filter(mi == "rmi" | mi == "fmi")
  494. # Turn long format into wide format, using data.tables and dcast:
  495. foo = dcast(setDT(tb), mid + sid + eid + uid + mseu ~ mi, value.var = "meanrate")
  496. tbw = as_tibble(foo)
  497. ```
  498. ```{r fit_model_6c1}
  499. # Random intercept for neurons,
  500. # random intercept for series
  501. lmer.6c1 = lmer(fmi ~ rmi + (1 | uid) + (1 | sid),
  502. data = tbw %>% drop_na(fmi, rmi))
  503. display(lmer.6c1)
  504. anova(lmer.6c1)
  505. ```
  506. ```{r, store_coefficients_6c1, include=FALSE}
  507. # store results in file
  508. coef_df = data.frame("intercept" = fixef(lmer.6c1)[1], "slope" = fixef(lmer.6c1)[2], row.names = "")
  509. write_csv(coef_df, "_stats/figure_6c1_coefs.csv")
  510. ```
  511. Slope of `r format(fixef(lmer.6c1)[2], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.6c1)[2], digits=2, nsmall=2)` \newline
  512. n = `r nrow(tbw %>% drop_na(fmi, rmi) %>% count(uid))` neurons from `r nrow(tbw %>% drop_na(fmi, rmi) %>% count(mid))` mice
  513. \newpage
  514. # Figure 6c$_2$
  515. ## Slope of regression line
  516. ```{r, tidy_for_6c2, include=FALSE}
  517. tb <- tib %>% filter(mi == "rmi" | mi == "fmi")
  518. # Turn long format into wide format, using data.tables and dcast:
  519. foo = dcast(setDT(tb), mid + sid + eid + uid + mseu ~ mi, value.var = "meanburstratio")
  520. tbw = as_tibble(foo)
  521. ```
  522. ```{r fit_model_6c2}
  523. # Random intercept for neurons,
  524. # random intercept for experiments, nested in series
  525. lmer.6c2 = lmer(fmi ~ rmi + (1 | uid) + (1 | sid/eid),
  526. data = tbw %>% drop_na(fmi, rmi))
  527. display(lmer.6c2)
  528. anova(lmer.6c2)
  529. ```
  530. ```{r, store_coefficients_6c2}
  531. coef_df = data.frame("intercept" = fixef(lmer.6c2)[1], "slope" = fixef(lmer.6c2)[2], row.names = "")
  532. write_csv(coef_df, "_stats/figure_6c2_coefs.csv")
  533. ```
  534. Slope of `r format(fixef(lmer.6c2)[2], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.6c2)[2], digits=2, nsmall=2)` \newline
  535. n = `r nrow(tbw %>% drop_na(fmi, rmi) %>% count(uid))` neurons from `r nrow(tbw %>% drop_na(fmi, rmi) %>% count(mid))` mice
  536. \newpage
  537. # Figure 6c$_3$
  538. ## Slope of regression line
  539. ```{r tidy_for_6c3, include = FALSE}
  540. tb <- tib %>% filter(mi == "rmi" | mi == "fmi")
  541. # Turn long format into wide format, using data.tables and dcast:
  542. foo = dcast(setDT(tb), mid + sid + eid + uid + mseu ~ mi, value.var = "spars")
  543. tbw = as_tibble(foo)
  544. ```
  545. ```{r fit_model_6c3}
  546. # Random intercept for neurons,
  547. # random intercept for experiments, nested in series
  548. lmer.6c3 = lmer(fmi ~ rmi + (1 | uid) + (1 | sid/eid),
  549. data = tbw %>% drop_na(fmi, rmi))
  550. display(lmer.6c3)
  551. anova(lmer.6c3)
  552. ```
  553. ```{r store_coefficients_6c3, include=FALSE}
  554. coef_df = data.frame("intercept" = fixef(lmer.6c3)[1], "slope" = fixef(lmer.6c3)[2], row.names = "")
  555. write_csv(coef_df, "_stats/figure_6c3_coefs.csv")
  556. ```
  557. Slope of `r format(fixef(lmer.6c3)[2], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.6c3)[2], digits=2, nsmall=2)` \newline
  558. n = `r nrow(tbw %>% drop_na(fmi, rmi) %>% count(uid))` neurons from `r nrow(tbw %>% drop_na(fmi, rmi) %>% count(mid))` mice
  559. \newpage
  560. # Figure 6c$_4$
  561. ## Slope of regression line
  562. ```{r tidy_for_6c4, include = FALSE}
  563. tb <- tib %>% filter(mi == "rmi" | mi == "fmi")
  564. # Turn long format into wide format, using data.tables and dcast:
  565. foo = dcast(setDT(tb), mid + sid + eid + uid + mseu ~ mi, value.var = "rel")
  566. tbw = as_tibble(foo)
  567. ```
  568. ```{r fit_model_6c4}
  569. # Random intercept for neurons,
  570. # random intercept for series, nested in mice
  571. lmer.6c4 = lmer(fmi ~ rmi + (1 | uid) + (1 | mid/sid),
  572. data = tbw %>% drop_na(fmi, rmi))
  573. display(lmer.6c4)
  574. anova(lmer.6c4)
  575. ```
  576. ```{r store_coefficients_6c4, include=FALSE}
  577. coef_df = data.frame("intercept" = fixef(lmer.6c4)[1], "slope" = fixef(lmer.6c4)[2], row.names = "")
  578. write_csv(coef_df, "_stats/figure_6c4_coefs.csv")
  579. ```
  580. Slope of `r format(fixef(lmer.6c4)[2], digits=2, nsmall=2)` $\pm$ `r format(2 * se.fixef(lmer.6c4)[2], digits=2, nsmall=2)` \newline
  581. n = `r nrow(tbw %>% drop_na(fmi, rmi) %>% count(uid))` neurons from `r nrow(tbw %>% drop_na(fmi, rmi) %>% count(mid))` mice