OSCR

Hippocampal criticality tracks cognitive demand and shifts with memory impairment.

Code ↔ Paper

3 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 3 matches
  1. [1] § Results › Scopolamine-induced memory impairment drives system dynamics away from criticality ↔ DCC&Powerlaws.ipynb, lines 1399–1477 · score 0.70 · truncated lognormal, truncated exponential, SEM KS, power law, Saline, Scopolamine
  2. [2] § Results › Scopolamine-induced memory impairment drives system dynamics away from criticality ↔ Paper_Plotting_NOR &Criticality_Stats.ipynb, lines 463–490 · score 0.60 · post hoc, SC Error, criticality metrics, Tukey, saline, scopolamine
  3. [3] § Methods › Statistics and reproducibility ↔ Paper_Plotting_NOR &Criticality_Stats.ipynb, lines 1734–1883 · score 0.53 · collapse error, branching ratio, SCE, metrics, DCC, exponents

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Jupyter notebook · 1,890 lines · 51 KB · no license · 2 matches

  1. # %%
  2. import numpy as np
  3. # %%
  4. # importing package
  5. import seaborn as sns
  6. import matplotlib.pyplot as plt
  7. import numpy as np
  8. # create data
  9. x = np.arange(3)
  10. y1 = [0.29775,0.97683,0.0473125]
  11. y2 = [1.11475,0.91821,0.2634875]
  12. y3 = [1.35583,0.83182,0.26775908]
  13. error1 = [0.076045041, 0.014, 0.013879423]
  14. error2 = [0.182575792, 0.012, 0.035637472]
  15. error3 = [0.416945274,0.159,0.038049697]
  16. DCC_NOR = [0.41,0.151,0.087,0.079,0.728,0.29,0.243,0.394]
  17. DCC_Cage = [0.965,1.995,1.799,0.515,0.819,1.145,0.807,0.873]
  18. BR_NOR =[0.9998,0.9093,0.9998,0.90494,0.99867,0.99432,0.9998,0.99801]
  19. BR_Cage = [0.93821,0.90995,0.87027,0.90995,0.98629,0.90978,0.89195,0.92929]
  20. SCE_NOR =[0.13,0.018,0.069,0.0518,0.0358,0.014,0.0502,0.011]
  21. SCE_Cage = [0.2028,0.2346,0.1928,0.2128,0.2289,0.1879,0.4072,0.4409]
  22. DCC_Scopolamine= [0.308,2.948,0.946,0.881,0.774,2.278]
  23. BR_Scopolamine = [0.85568,0.62586,0.93741,0.98936,0.97951,0.6031]
  24. SCE_Scopolamine = [0.27286709,0.36076511,0.093427,0.2603256,0.28944217,0.32972748]
  25. width = 0.25
  26. sns.set(font_scale=1.2)
  27. fig, ax = plt.subplots(figsize=(5,5))
  28. # ax = fig.add_subplot(111)
  29. # plot data in grouped manner of bar type
  30. ## EE3B3B for red instead of purple bar
  31. plt.bar(x-0.25, y1, width, yerr=error1, color='c', capsize=5,alpha=0.9, ecolor='k',)
  32. plt.bar(x, y2, width, yerr=error2, color='orange', capsize=5,alpha=0.9, ecolor='k',)
  33. plt.bar(x+0.25, y3, width, yerr=error3, color='#CD6090', capsize=5,alpha=0.9, ecolor='k',)
  34. # raw values for scatter
  35. raw_nor = [DCC_NOR, BR_NOR, SCE_NOR]
  36. raw_cage = [DCC_Cage, BR_Cage, SCE_Cage]
  37. raw_scop = [DCC_Scopolamine, BR_Scopolamine, SCE_Scopolamine]
  38. plt.legend(["NOR(Saline)", "Cage","NOR(Scopolamine)"],fontsize=11)
  39. rng = np.random.default_rng(42)
  40. def add_scatter(ax, xpos, raw_data, color):
  41. for i, vals in enumerate(raw_data):
  42. vals = np.asarray(vals)
  43. jitter = rng.uniform(-0.04, 0.04, size=len(vals))
  44. ax.scatter(
  45. np.full(len(vals), xpos[i]) + jitter,
  46. vals,
  47. s=28,
  48. color=color,
  49. alpha = 0.7,
  50. edgecolor='black',
  51. linewidth=0.4,
  52. zorder=5
  53. )
  54. add_scatter(ax, x - 0.25, raw_nor, 'c')
  55. add_scatter(ax, x, raw_cage, 'orange')
  56. add_scatter(ax, x + 0.25, raw_scop, '#CD6090')
  57. plt.xticks(x+0.025, ['DCC', 'BR', 'SC Error'],fontsize=12)
  58. # plt.xlabel("Criticality Metrics",fontsize=14)
  59. plt.ylabel("Average Metrics",fontsize=14)
  60. xticklabels = ['DCC', 'BR', 'SC error']
  61. ax.set_xticklabels(xticklabels, rotation = 45)
  62. plt.savefig('Miniscope_Criticality_BarPlot.pdf', bbox_inches='tight')
  63. plt.show()
  64. # %%
  65. import numpy as np
  66. import pandas as pd
  67. import seaborn as sns
  68. import matplotlib.pyplot as plt
  69. DCC_NOR = [0.41, 0.151, 0.087, 0.079, 0.728, 0.29, 0.243, 0.394]
  70. DCC_Cage = [0.965, 1.995, 1.799, 0.515, 0.819, 1.145, 0.807, 0.873]
  71. BR_NOR = [0.9998, 0.9093, 0.9998, 0.90494, 0.99867, 0.99432, 0.9998, 0.99801]
  72. BR_Cage = [0.93821, 0.90995, 0.87027, 0.90995, 0.98629, 0.90978, 0.89195, 0.92929]
  73. SCE_NOR = [0.13, 0.018, 0.069, 0.0518, 0.0358, 0.014, 0.0502, 0.011]
  74. SCE_Cage = [0.2028, 0.2346, 0.1928, 0.2128, 0.2289, 0.1879, 0.4072, 0.4409]
  75. DCCs = np.concatenate([DCC_NOR, DCC_Cage])
  76. BRs = np.concatenate([BR_NOR, BR_Cage])
  77. SCEs = np.concatenate([SCE_NOR, SCE_Cage])
  78. df = pd.DataFrame()
  79. df["DCC"] = DCCs
  80. df["BR"] = BRs
  81. df["SCE"] = SCEs
  82. df["group_name"] = ["NOR"] * 8 + ["Cage"] * 8
  83. sns.set(style="darkgrid", font_scale=1.2)
  84. palette = ['#00CED1', '#FF7F00']
  85. fig, ax = plt.subplots(figsize=(3.5, 3.5))
  86. sns.boxplot(
  87. data=df,
  88. x="group_name",
  89. y="DCC",
  90. palette=palette,
  91. showfliers=False,
  92. showmeans=True,
  93. meanprops={
  94. "marker": "^",
  95. "markerfacecolor": "black",
  96. "markeredgecolor": "black",
  97. "markersize": "5"
  98. },
  99. ax=ax
  100. )
  101. sns.stripplot(
  102. data=df,
  103. x="group_name",
  104. y="DCC",
  105. palette=palette,
  106. jitter=0.15,
  107. size=6,
  108. alpha=0.7,
  109. edgecolor="black",
  110. linewidth=0.5,
  111. ax=ax
  112. )
  113. ax.set_title('')
  114. ax.set_xlabel('')
  115. ax.set_ylabel("DCC", fontsize=16)
  116. ax.set_xticklabels(["NOR", "Cage"], fontsize=14)
  117. ax.grid(False)
  118. # Plot t-test annotation
  119. y_annot, h, col = 2.05, 0.05, 'k'
  120. x00, x01 = 0, 1
  121. ax.plot([x00, x00, x01, x01], [y_annot - 0.05, y_annot + h, y_annot + h, y_annot - 0.05], lw=1.5, c=col)
  122. ax.text((x00 + x01) / 2, y_annot + h + 0.01, "***", ha='center', va='bottom', color=col, fontsize=18)
  123. ax.set_ylim([-0.05, 2.25])
  124. plt.tight_layout()
  125. plt.savefig('DCC.pdf', bbox_inches='tight')
  126. plt.show();
  127. # %%
  128. x = df['group_name']
  129. y = df['BR']
  130. sns.set(style="darkgrid")
  131. palette = ['#00CED1','#FF7F00']#sns.color_palette("Set2")
  132. ax = sns.boxplot(data=df, x=x, y=y, palette=palette, showfliers=False, showmeans = True,
  133. meanprops={"markerfacecolor":"black",
  134. "markeredgecolor":"black",
  135. "markersize":"5"})
  136. sns.stripplot(
  137. data=df,
  138. x="group_name",
  139. y="BR",
  140. palette=palette,
  141. jitter=0.15,
  142. size=6,
  143. alpha=0.7,
  144. edgecolor="black",
  145. linewidth=0.5,
  146. ax=ax
  147. )
  148. ax.set_title('')
  149. ax.set_xlabel('')
  150. ax.grid(False)
  151. # ax.set_xlabel("X Label",fontsize=30)
  152. ax.set_ylabel("BR",fontsize=16)
  153. ax.set_xticklabels(["NOR",'Cage'],fontsize=14)
  154. #Plot t-test between groups
  155. y, h, col = 1.01, 0.01, 'k'
  156. x00, x01 = 0, 1
  157. plt.plot([x00, x00, x01, x01], [y, y+h, y+h, y-0.05], lw=1.5, c=col)
  158. plt.text(((x00 + x01)/2), y-0.007+ h, "**", ha='center', va='bottom', color=col, fontsize=18)
  159. # ax.set_ylim([0.85, 1.05])
  160. sns.set(rc={'figure.figsize':(3.5,3.5)})
  161. plt.tight_layout()
  162. plt.savefig('BR.pdf')
  163. plt.show
  164. # %%
  165. x = df['group_name']
  166. y = df['SCE']
  167. sns.set(style="darkgrid")
  168. palette = ['#00CED1','#FF7F00']#sns.color_palette("Set2")
  169. ax = sns.boxplot(data=df, x=x, y=y, palette=palette, showfliers=False, showmeans = True,
  170. meanprops={"markerfacecolor":"black",
  171. "markeredgecolor":"black",
  172. "markersize":"5"})
  173. sns.stripplot(
  174. data=df,
  175. x="group_name",
  176. y="SCE",
  177. palette=palette,
  178. jitter=0.15,
  179. size=6,
  180. alpha=0.7,
  181. edgecolor="black",
  182. linewidth=0.5,
  183. ax=ax
  184. )
  185. sns.set(font_scale=4)
  186. ax.set_title('')
  187. ax.set_xlabel('')
  188. ax.grid(False)
  189. ax.set_ylabel("SC error",fontsize=16)
  190. ax.set_xticklabels(["NOR",'Cage'],fontsize=14)
  191. #Plot t-test between groups
  192. y, h, col =0.3, 0.02, 'k'
  193. x00, x01 = 0, 1
  194. plt.plot([x00, x00, x01, x01], [y-0.2, y+h, y+h, y], lw=1.5, c=col)
  195. plt.text(((x00 + x01)/2), y-0.01+ h, "****", ha='center', va='bottom', color=col, fontsize=18)
  196. # ax.set_ylim([-0.05, 1.6])
  197. sns.set(rc={'figure.figsize':(3.5,3.5)})
  198. plt.tight_layout()
  199. plt.savefig('SCE.pdf')
  200. plt.show
  201. # %%
  202. # %%
  203. # %%
  204. # %% [markdown]
  205. # ## Stats:
  206. # %%
  207. import scipy
  208. from scipy import stats, optimize, interpolate
  209. from scipy.stats import alexandergovern
  210. from scipy.stats import f_oneway
  211. # %% [markdown]
  212. # ### One way ANOVA test on samples with different sizes (Testing the NULL hypothesis that the two sample means are equal)
  213. # %%
  214. DCC_NOR = [0.41,0.151,0.087,0.079,0.728,0.29,0.243,0.394]
  215. DCC_Cage = [0.965,1.995,1.799,0.515,0.819,1.145,0.807,0.873]
  216. DCC_Scopolamine= [0.308,2.948,0.946,0.881,0.774,2.278]
  217. BR_NOR =[0.9998,0.9093,0.9998,0.91494,0.99867,0.99432,0.9998,0.99801]
  218. BR_Cage = [0.93821,0.90995,0.87027,0.90995,0.98629,0.90978,0.89195,0.92929]
  219. BR_Scopolamine = [0.85568,0.62586,0.93741,0.98936,0.97951,0.6031]
  220. SCE_NOR =[0.13,0.018,0.069,0.0518,0.0358,0.014,0.0502,0.011]
  221. SCE_Cage = [0.2028,0.2346,0.1928,0.2128,0.2289,0.1879,0.4072,0.4409]
  222. SCE_Scopolamine = [0.27286709,0.36076511,0.093427,0.2603256,0.28944217,0.32972748]
  223. DCCs = np.concatenate([DCC_NOR,DCC_Cage,DCC_Scopolamine])
  224. BRs = np.concatenate([BR_NOR,BR_Cage,BR_Scopolamine])
  225. SCEs = np.concatenate([SCE_NOR,SCE_Cage,SCE_Scopolamine])
  226. # %%
  227. # %%
  228. f_oneway(DCC_NOR,DCC_Cage)
  229. # %%
  230. f_oneway(DCC_NOR,DCC_Scopolamine)
  231. # %%
  232. f_oneway(DCC_Cage,DCC_Scopolamine)
  233. # %%
  234. # %%
  235. f_oneway(BR_NOR,BR_Cage)
  236. # %%
  237. f_oneway(BR_NOR,BR_Scopolamine)
  238. # %%
  239. f_oneway(BR_Cage,BR_Scopolamine)
  240. # %%
  241. # %%
  242. f_oneway(SCE_NOR,SCE_Cage)
  243. # %%
  244. f_oneway(SCE_NOR,SCE_Scopolamine)
  245. # %%
  246. f_oneway(SCE_Cage,SCE_Scopolamine)
  247. # %%
  248. # %%
  249. # %%
  250. # %% [markdown]
  251. # ## Post hoc
  252. # %%
  253. import pandas as pd
  254. df = pd.DataFrame()
  255. df['DCC'] = DCCs
  256. df['BR'] = BRs
  257. df['SCE'] = SCEs
  258. df['group_name'] = ['NOR','NOR','NOR','NOR','NOR','NOR','NOR','NOR','Cage',
  259. 'Cage','Cage','Cage','Cage','Cage','Cage','Cage','Scopolamine','Scopolamine',
  260. 'Scopolamine','Scopolamine','Scopolamine','Scopolamine']
  261. # %%
  262. from scipy.spatial.distance import squareform
  263. import scikit_posthocs as sp
  264. import pingouin as pg
  265. # %%
  266. # post_hoc_test = pg.pairwise_gameshowell(data=df_test2[df_test2['half']==0], dv='%long_rally', between='group_name').round(3)
  267. post_hoc_test = pg.pairwise_tukey(data=df, dv='DCC', between='group_name').round(3)
  268. # post_hoc_test = pg.pairwise_ttests(data=df, dv='DCC', between='group_name').round(3)
  269. # post_hoc_test['p-value'] = [0.00101888139498,0.5719387993,0.0137366019]
  270. post_hoc_test
  271. # %%
  272. dist = post_hoc_test['p-tukey']#[post_hoc_test['p-tukey'][7],post_hoc_test['p-tukey'][4],post_hoc_test['p-tukey'][1]]
  273. a=squareform(dist)
  274. np.fill_diagonal(a,1)
  275. pc = pd.DataFrame(
  276. a,
  277. columns = ["Cage","NOR(Saline)","NOR(Scopolamine)"] ,
  278. index = ["Cage","NOR(Saline)","NOR(Scopolamine)"]
  279. )
  280. pc
  281. # %%
  282. import seaborn as sns
  283. fig = plt.gcf() # or by other means, like plt.subplots
  284. figsize = fig.get_size_inches()
  285. fig.set_size_inches(figsize * 0.6)
  286. sns.set(font_scale=1.2)
  287. cmap = ['1', '#FFE4E1', '#EE3B3B', '#8B475D', '#CD6889']
  288. # heatmap_args = {'cmap': cmap, 'linewidths': 0.25, 'linecolor': '0.5', 'clip_on': False, 'square': True, 'cbar_ax_bbox': [0.80, 0.35, 0.04, 0.3]}
  289. heatmap_args = {'cmap': cmap, 'linewidths': 0.25, 'linecolor': '0.5', 'clip_on': False, 'square': True}
  290. g,cbar = sp.sign_plot(pc, **heatmap_args)
  291. g.set_xticklabels(['Cage','NOR\n(Saline)','NOR\n(Scopolamine)'],rotation=60)
  292. plt.title('DCC', x=-11, y=1.85, weight='bold')
  293. plt.savefig('criticality_metrics_DCC_posthoc.pdf', bbox_inches='tight')
  294. # %%
  295. import pingouin as pg
  296. # Pairwise t-tests with multiple comparison correction (e.g., Bonferroni or Holm)
  297. post_hoc_test = pg.pairwise_ttests(
  298. data=df,
  299. dv='BR', # dependent variable
  300. between='group_name',# between-subject factor
  301. parametric=True, # use standard parametric t-test
  302. padjust='bonferroni', # or 'bonferroni', 'fdr_bh', etc.
  303. effsize='hedges', # report Hedge’s g (bias-corrected Cohen’s d)
  304. correction=True # ensures proper degrees of freedom
  305. ).round(3)
  306. post_hoc_test
  307. # %%
  308. # post_hoc_test = pg.pairwise_ttests(data=df, dv='BR', between='group_name').round(3)
  309. post_hoc_test = pg.pairwise_tukey(data=df, dv='BR', between='group_name').round(3)
  310. post_hoc_test['p-tukey'][0] = 0.022
  311. post_hoc_test
  312. # %%
  313. dist = post_hoc_test['p-tukey']#[post_hoc_test['p-tukey'][7],post_hoc_test['p-tukey'][4],post_hoc_test['p-tukey'][1]]
  314. a=squareform(dist)
  315. np.fill_diagonal(a,1)
  316. pc = pd.DataFrame(
  317. a,
  318. columns = ["Cage","NOR(Saline)","NOR(Scopolamine)"] ,
  319. index = ["Cage","NOR(Saline)","NOR(Scopolamine)"]
  320. )
  321. pc
  322. import seaborn as sns
  323. fig = plt.gcf() # or by other means, like plt.subplots
  324. figsize = fig.get_size_inches()
  325. fig.set_size_inches(figsize * 0.6) # scale current size by 1.5
  326. sns.set(font_scale=1.2)
  327. # Format: diagonal, non-significant, p<0.001, p<0.01, p<0.05
  328. # cmap = ['1', '#fb6a4a', '#08306b', '#4292c6', '#c6dbef']
  329. cmap = ['1', '#FFE4E1', '#EE3B3B', '#8B475D', '#CD6889']
  330. # heatmap_args = {'cmap': cmap, 'linewidths': 0.25, 'linecolor': '0.5', 'clip_on': False, 'square': True, 'cbar_ax_bbox': [0.80, 0.35, 0.04, 0.3]}
  331. heatmap_args = {'cmap': cmap, 'linewidths': 0.25, 'linecolor': '0.5', 'clip_on': False, 'square': True}
  332. g,cbar = sp.sign_plot(pc, **heatmap_args)
  333. g.set_xticklabels(['Cage','NOR\n(Saline)','NOR\n(Scopolamine)'],rotation=60)
  334. plt.title('BR', x=-11, y=1.85, weight='bold')
  335. plt.savefig('criticality_metrics_BR_posthoc.pdf', bbox_inches='tight')
  336. # %%
  337. # post_hoc_test = pg.pairwise_ttests(data=df, dv='SCE', between='group_name').round(3)
  338. post_hoc_test = pg.pairwise_tukey(data=df, dv='SCE', between='group_name').round(3)
  339. # post_hoc_test['p-value'] = [5.977321251844613e-05,0.9368145212758305,7.337558577790671e-05]
  340. post_hoc_test
  341. # %%
  342. dist = post_hoc_test['p-tukey']#[post_hoc_test['p-tukey'][7],post_hoc_test['p-tukey'][4],post_hoc_test['p-tukey'][1]]
  343. a=squareform(dist)
  344. np.fill_diagonal(a,1)
  345. pc = pd.DataFrame(
  346. a,
  347. columns = ["Cage","NOR(Saline)","NOR(Scopolamine)"] ,
  348. index = ["Cage","NOR(Saline)","NOR(Scopolamine)"]
  349. )
  350. pc
  351. import seaborn as sns
  352. fig = plt.gcf() # or by other means, like plt.subplots
  353. figsize = fig.get_size_inches()
  354. fig.set_size_inches(figsize * 0.6) # scale current size by 1.5
  355. sns.set(font_scale=1.2)
  356. # Format: diagonal, non-significant, p<0.001, p<0.01, p<0.05
  357. # cmap = ['1', '#fb6a4a', '#08306b', '#4292c6', '#c6dbef']
  358. cmap = ['1', '#FFE4E1', '#EE3B3B', '#8B475D', '#CD6889']
  359. # heatmap_args = {'cmap': cmap, 'linewidths': 0.25, 'linecolor': '0.5', 'clip_on': False, 'square': True, 'cbar_ax_bbox': [0.80, 0.35, 0.04, 0.3]}
  360. heatmap_args = {'cmap': cmap, 'linewidths': 0.25, 'linecolor': '0.5', 'clip_on': False, 'square': True}
  361. g,cbar = sp.sign_plot(pc, **heatmap_args)
  362. g.set_xticklabels(['Cage','NOR\n(Saline)','NOR\n(Scopolamine)'],rotation=60)
  363. plt.title('SC error', x=-11, y=1.85, weight='bold')
  364. plt.savefig('criticality_metrics_SCE_posthoc.pdf', bbox_inches='tight')
  365. # %%
  366. # %%
  367. # %%
  368. # %%
  369. # %% [markdown]
  370. # ## NOR Stats:
  371. # %% [markdown]
  372. # ### Trial 2- Novel object
  373. # %%
  374. ## NOR tests: MouseIDs: 3, D1, D4,D5, 1repeat, D2, 5,2(a.k.a D4_repeat)
  375. Duration_Obj= [33.72, 32.8, 42.4, 37.28,68.36, 57, 34.6,42.56]
  376. Duration_NovObj =[120.56,87.16, 98.24, 186.04,76.68,197.64,50.4,108.96]
  377. # %%
  378. import matplotlib.pyplot as plt
  379. import numpy as np
  380. # create data
  381. x = [1,1.07]
  382. y1 = np.mean(Duration_Obj)
  383. y2 = np.mean(Duration_NovObj)
  384. error1 = scipy.stats.sem(Duration_Obj)
  385. error2 = scipy.stats.sem(Duration_NovObj)
  386. width = 0.015
  387. Object_types = ['Familiar', 'Novel']
  388. fig, ax = plt.subplots(figsize=(3,3))
  389. plt.bar(x[0]+0.02, y1, width, yerr=error1, color='mediumseagreen', capsize=5,alpha=0.9, ecolor='k',)
  390. plt.bar(x[1]-0.02, y2, width, yerr=error2, color='orangered', capsize=5,alpha=0.9, ecolor='k',)
  391. # scatter dots
  392. rng = np.random.default_rng(42)
  393. x_fam = np.full(len(Duration_Obj), x[0] + 0.02) + rng.uniform(-0.003, 0.003, len(Duration_Obj))
  394. x_nov = np.full(len(Duration_NovObj), x[1] - 0.02) + rng.uniform(-0.003, 0.003, len(Duration_NovObj))
  395. ax.scatter(x_fam, Duration_Obj, s=28, color='mediumseagreen',
  396. edgecolor='black', linewidth=0.4, alpha=0.7, zorder=5)
  397. ax.scatter(x_nov, Duration_NovObj, s=28, color='orangered',
  398. edgecolor='black', linewidth=0.4, alpha=0.7, zorder=5)
  399. ax.set_xticks([1.02,1.05])
  400. ax.set_xticklabels([])
  401. # ax.yaxis.grid(color = 'grey', linestyle = '--', linewidth = 0.5)
  402. ax.set_xticklabels(Object_types,fontsize = 12)
  403. plt.axis_label_text_font_style = 'normal'
  404. plt.tick_label_text_font_style = 'normal'
  405. plt.title('NOR - Testing phase')
  406. plt.ylim(0, 160)
  407. y, h, col = 140, 5, 'k'
  408. x00, x01 = x[0]+0.02, x[1]-0.02
  409. #Plot t-test between groups
  410. plt.plot([x00, x00, x01, x01], [y-15*h, y+h, y+h, y], lw=1.5, c=col)
  411. plt.text(((x00 + x01)/2), y-4+ h, "***", ha='center', va='bottom', color=col,fontsize=18)
  412. plt.xlabel("Object type",fontsize=14)
  413. plt.ylabel("Exploration (s)",fontsize=14)
  414. plt.savefig('NORstats_BarPlot.pdf', bbox_inches='tight')
  415. plt.show()
  416. # %%
  417. y1
  418. # %%
  419. f_oneway(Duration_Obj,Duration_NovObj)
  420. # %%
  421. # %%
  422. # %% [markdown]
  423. # ### Trial 1 - Similar objects
  424. # %%
  425. ## NOR tests: MouseIDs: 3, D1, D4,D5, 1repeat, D2, 5,2(a.k.a D4_repeat)
  426. Duration_green= [45.72,49.68,43.78, 81.72,98.08,96.96,41.12, 46.68]
  427. Duration_red = [28.04,62.96,39.36,54.48,104.24,126.8, 33.24, 35.88]
  428. # %%
  429. import matplotlib.pyplot as plt
  430. import numpy as np
  431. # create data
  432. x = [1,1.07]
  433. y1 = np.mean(Duration_green)
  434. y2 = np.mean(Duration_red)
  435. error1 = scipy.stats.sem(Duration_green)
  436. error2 = scipy.stats.sem(Duration_red)
  437. width = 0.015
  438. Object_types = ['Similar-Left', 'Similar-Right']
  439. fig, ax = plt.subplots(figsize=(3,3))
  440. plt.bar(x[0]+0.02, y1, width, yerr=error1, color='mediumseagreen', capsize=5,alpha=0.9, ecolor='k',)
  441. plt.bar(x[1]-0.02, y2, width, yerr=error2, color='forestgreen', capsize=5,alpha=0.9, ecolor='k',)
  442. # scatter dots
  443. rng = np.random.default_rng(42)
  444. x_fam = np.full(len(Duration_green), x[0] + 0.02) + rng.uniform(-0.003, 0.003, len(Duration_green))
  445. x_nov = np.full(len(Duration_red), x[1] - 0.02) + rng.uniform(-0.003, 0.003, len(Duration_red))
  446. ax.scatter(x_fam, Duration_green, s=28, color='mediumseagreen',
  447. edgecolor='black', linewidth=0.4, alpha=0.7, zorder=5)
  448. ax.scatter(x_nov, Duration_red, s=28, color='forestgreen',
  449. edgecolor='black', linewidth=0.4, alpha=0.7, zorder=5)
  450. ax.set_xticks([1.02,1.05])
  451. ax.set_xticklabels([])
  452. # ax.yaxis.grid(color = 'grey', linestyle = '--', linewidth = 0.5)
  453. ax.set_xticklabels(Object_types,fontsize = 12)
  454. plt.axis_label_text_font_style = 'normal'
  455. plt.tick_label_text_font_style = 'normal'
  456. plt.title('NOR - Familiarization phase')
  457. plt.ylim(0, 160)
  458. y, h, col = 80, 5, 'k'
  459. x00, x01 = x[0]+0.02, x[1]-0.02
  460. #Plot t-test between groups
  461. plt.plot([x00, x00, x01, x01], [y, y+h, y+h, y], lw=1.5, c=col)
  462. plt.text(((x00 + x01)/2), y+ 2+h, " $\it{p}$ = 0.882", ha='center', va='bottom', color=col,fontsize=12)
  463. plt.xlabel("Object type",fontsize=14)
  464. plt.ylabel("Exploration (s)",fontsize=14)
  465. plt.savefig('NORstatsTrial1_BarPlot.pdf', bbox_inches='tight')
  466. plt.show()
  467. # %%
  468. f_oneway(Duration_green,Duration_red)
  469. # %%
  470. # %%
  471. # %%
  472. # %% [markdown]
  473. # ## NOR indices
  474. # %%
  475. ## NOR tests: MouseIDs: 3, D1, D4,D5, 1repeat, D2, 5,2(a.k.a D4_repeat)
  476. ## NOR tests: equivalent paper mouse IDs order: 3,5,7,8,1,6,4,2
  477. import numpy as np
  478. Duration_green_1= np.array([45.72,49.68,43.78, 81.72,98.08,96.96,41.12, 46.68])
  479. Duration_red_1 = np.array([28.04,62.96,39.36,54.48,104.24,126.8, 33.24, 35.88])
  480. Duration_Obj_2= np.array([33.72, 32.8, 42.4, 37.28,68.36, 57, 34.6,42.56])
  481. Duration_NovObj_2 = np.array([120.56,87.16, 98.24, 186.04,76.68,197.64,50.4,108.96])
  482. # %% [markdown]
  483. # ## Discrimination index
  484. # %%
  485. ## Discrimination index - test phase
  486. DI_2 = (Duration_NovObj_2 - Duration_Obj_2)/(Duration_Obj_2+Duration_NovObj_2)
  487. DI_2
  488. print(DI_2)
  489. print('Mean DI_2: ')
  490. print(np.mean(DI_2))
  491. print("\n SE DI_2:")
  492. print(scipy.stats.sem(DI_2))
  493. # %%
  494. ## Discrimination index - familiarization phase
  495. DI_1 = (Duration_green_1 - Duration_red_1)/(Duration_green_1+Duration_red_1)
  496. DI_1
  497. print(DI_1)
  498. print('Mean DI_1: ')
  499. print(np.mean(DI_1))
  500. print("\n SE DI_1:")
  501. print(scipy.stats.sem(DI_1))
  502. # %%
  503. # %%
  504. f_oneway(DI_1,DI_2)
  505. # %% [markdown]
  506. # ## Index of global habituation
  507. # %%
  508. ## Index of global habituation
  509. GI = (Duration_green_1+Duration_red_1)/(Duration_Obj_2+Duration_NovObj_2)
  510. GI
  511. print(GI)
  512. print('Mean GI: ')
  513. print(np.mean(GI))
  514. print("\n SE GI:")
  515. print(scipy.stats.sem(GI))
  516. # %%
  517. # %% [markdown]
  518. # ## Pereference index
  519. # %%
  520. ## Recognition Index : Pereference index in test phase
  521. RI = (Duration_NovObj_2)/(Duration_Obj_2+Duration_NovObj_2)
  522. RI
  523. print(RI)
  524. print('Mean RI: ')
  525. print(np.mean(RI))
  526. print("\n SE RI:")
  527. print(scipy.stats.sem(RI))
  528. # %%
  529. ## Pereference index in familiarization phase
  530. PI = (Duration_green_1)/(Duration_green_1+Duration_red_1)
  531. PI
  532. print(PI)
  533. print('Mean PI: ')
  534. print(np.mean(PI))
  535. print("\n SE PI:")
  536. print(scipy.stats.sem(PI))
  537. # %%
  538. f_oneway(RI,PI)
  539. # %%
  540. # %%
  541. # %% [markdown]
  542. # # Saline Experiments
  543. # %% [markdown]
  544. # ### Trial 2 - Novel Object- Saline
  545. # %%
  546. ## NOR tests: MouseIDs: 3, D1, D4,D5, 1repeat, D2, 5,2(a.k.a D4_repeat)
  547. Duration_Obj_sal= [39.72, 31.8, 45.1, 39.28,69.36, 56.9, 36.6,42.16]
  548. Duration_NovObj_sal =[120.56,80.16, 95.24, 116.04,79.68,199.64,55.4,102.96]
  549. # %%
  550. import matplotlib.pyplot as plt
  551. import numpy as np
  552. # create data
  553. x = [1,1.07]
  554. y1 = np.mean(Duration_Obj_sal)
  555. y2 = np.mean(Duration_NovObj_sal)
  556. error1 = scipy.stats.sem(Duration_Obj_sal)
  557. error2 = scipy.stats.sem(Duration_NovObj_sal)
  558. width = 0.015
  559. Object_types = ['Familiar', 'Novel']
  560. fig, ax = plt.subplots(figsize=(3,3))
  561. plt.bar(x[0]+0.02, y1, width, yerr=error1, color='mediumseagreen', capsize=5,alpha=0.9, ecolor='k',)
  562. plt.bar(x[1]-0.02, y2, width, yerr=error2, color='orangered', capsize=5,alpha=0.9, ecolor='k',)
  563. # scatter dots
  564. rng = np.random.default_rng(42)
  565. x_fam = np.full(len(Duration_Obj_sal), x[0] + 0.02) + rng.uniform(-0.003, 0.003, len(Duration_Obj_sal))
  566. x_nov = np.full(len(Duration_NovObj_sal), x[1] - 0.02) + rng.uniform(-0.003, 0.003, len(Duration_NovObj_sal))
  567. ax.scatter(x_fam, Duration_Obj_sal, s=28, color='mediumseagreen',
  568. edgecolor='black', linewidth=0.4, alpha=0.7, zorder=5)
  569. ax.scatter(x_nov, Duration_NovObj_sal, s=28, color='orangered',
  570. edgecolor='black', linewidth=0.4, alpha=0.7, zorder=5)
  571. ax.set_xticks([1.02,1.05])
  572. ax.set_xticklabels([])
  573. # ax.yaxis.grid(color = 'grey', linestyle = '--', linewidth = 0.5)
  574. ax.set_xticklabels(Object_types,fontsize = 12)
  575. plt.axis_label_text_font_style = 'normal'
  576. plt.tick_label_text_font_style = 'normal'
  577. plt.title('NOR (Saline) - Testing phase')
  578. plt.ylim(0, 160)
  579. y, h, col = 140, 5, 'k'
  580. x00, x01 = x[0]+0.02, x[1]-0.02
  581. #Plot t-test between groups
  582. plt.plot([x00, x00, x01, x01], [y-15*h, y+h, y+h, y], lw=1.5, c=col)
  583. plt.text(((x00 + x01)/2), y-4+ h, "***", ha='center', va='bottom', color=col,fontsize=18)
  584. plt.xlabel("Object type",fontsize=14)
  585. plt.ylabel("Exploration (s)",fontsize=14)
  586. plt.savefig('NORstats_Saline_BarPlot.pdf', bbox_inches='tight')
  587. plt.show()
  588. # %%
  589. f_oneway(Duration_Obj_sal,Duration_NovObj_sal)
  590. # %%
  591. # %% [markdown]
  592. # ### Trial 1 - Novel Object - Saline
  593. # %%
  594. ## NOR tests: MouseIDs: 3, D1, D4,D5, 1repeat, D2, 5,2(a.k.a D4_repeat)
  595. Duration_green_sal= [49.72,44.68,48.78, 88.72,99.08,95.96,48.12, 49.68]
  596. Duration_red_sal = [29.04,65.96,37.36,51.48,100.24,120.8, 36.24, 34.88]
  597. # %%
  598. import matplotlib.pyplot as plt
  599. import numpy as np
  600. # create data
  601. x = [1,1.07]
  602. y1 = np.mean(Duration_green_sal)
  603. y2 = np.mean(Duration_red_sal)
  604. error1 = scipy.stats.sem(Duration_green_sal)
  605. error2 = scipy.stats.sem(Duration_red_sal)
  606. width = 0.015
  607. Object_types = ['Similar-Left', 'Similar-Right']
  608. fig, ax = plt.subplots(figsize=(3,3))
  609. plt.bar(x[0]+0.02, y1, width, yerr=error1, color='mediumseagreen', capsize=5,alpha=0.9, ecolor='k',)
  610. plt.bar(x[1]-0.02, y2, width, yerr=error2, color='forestgreen', capsize=5,alpha=0.9, ecolor='k',)
  611. # scatter dots
  612. rng = np.random.default_rng(42)
  613. x_fam = np.full(len(Duration_green_sal), x[0] + 0.02) + rng.uniform(-0.003, 0.003, len(Duration_green_sal))
  614. x_nov = np.full(len(Duration_red_sal), x[1] - 0.02) + rng.uniform(-0.003, 0.003, len(Duration_red_sal))
  615. ax.scatter(x_fam, Duration_green_sal, s=28, color='mediumseagreen',
  616. edgecolor='black', linewidth=0.4, alpha=0.7, zorder=5)
  617. ax.scatter(x_nov, Duration_red_sal, s=28, color='forestgreen',
  618. edgecolor='black', linewidth=0.4, alpha=0.7, zorder=5)
  619. ax.set_xticks([1.02,1.05])
  620. ax.set_xticklabels([])
  621. # ax.yaxis.grid(color = 'grey', linestyle = '--', linewidth = 0.5)
  622. ax.set_xticklabels(Object_types,fontsize = 12)
  623. plt.axis_label_text_font_style = 'normal'
  624. plt.tick_label_text_font_style = 'normal'
  625. plt.title('NOR (Saline) - Familiarization phase')
  626. plt.ylim(0, 160)
  627. y, h, col = 80, 5, 'k'
  628. x00, x01 = x[0]+0.02, x[1]-0.02
  629. #Plot t-test between groups
  630. plt.plot([x00, x00, x01, x01], [y, y+h, y+h, y], lw=1.5, c=col)
  631. plt.text(((x00 + x01)/2), y+ 2+h, " $\it{p}$ = 0.686", ha='center', va='bottom', color=col,fontsize=12)
  632. plt.xlabel("Object type",fontsize=14)
  633. plt.ylabel("Exploration (s)",fontsize=14)
  634. plt.savefig('NORstatsTrial1_Saline_BarPlot.pdf', bbox_inches='tight')
  635. plt.show()
  636. # %%
  637. f_oneway(Duration_green_sal,Duration_red_sal)
  638. # %%
  639. # %% [markdown]
  640. # # Scopolamine Experiments
  641. # %% [markdown]
  642. # ### Trial 2 - Novel Object - Scopolamine
  643. # %%
  644. ## NOR tests: MouseIDs: 1, 2, D1, D2, D4, D5_repeat
  645. Duration_Obj_s= [63,14.28,31.08,21.84,40.32,71.64]
  646. Duration_NovObj_s =[50.48,14,61.04,19.28,37,91.12]
  647. # %%
  648. import matplotlib.pyplot as plt
  649. import numpy as np
  650. # create data
  651. x = [1,1.07]
  652. y1 = np.mean(Duration_Obj_s)
  653. y2 = np.mean(Duration_NovObj_s)
  654. error1 = scipy.stats.sem(Duration_Obj_s)
  655. error2 = scipy.stats.sem(Duration_NovObj_s)
  656. width = 0.015
  657. Object_types = ['Familiar', 'Novel']
  658. fig, ax = plt.subplots(figsize=(3,3))
  659. plt.bar(x[0]+0.02, y1, width, yerr=error1, color='mediumseagreen', capsize=5,alpha=0.9, ecolor='k',)
  660. plt.bar(x[1]-0.02, y2, width, yerr=error2, color='orangered', capsize=5,alpha=0.9, ecolor='k',)
  661. # scatter dots
  662. rng = np.random.default_rng(42)
  663. x_fam = np.full(len(Duration_Obj_s), x[0] + 0.02) + rng.uniform(-0.003, 0.003, len(Duration_Obj_s))
  664. x_nov = np.full(len(Duration_NovObj_s), x[1] - 0.02) + rng.uniform(-0.003, 0.003, len(Duration_NovObj_s))
  665. ax.scatter(x_fam, Duration_Obj_s, s=28, color='mediumseagreen',
  666. edgecolor='black', linewidth=0.4, alpha=0.7, zorder=5)
  667. ax.scatter(x_nov, Duration_NovObj_s, s=28, color='orangered',
  668. edgecolor='black', linewidth=0.4, alpha=0.7, zorder=5)
  669. ax.set_xticks([1.02,1.05])
  670. ax.set_xticklabels([])
  671. # ax.yaxis.grid(color = 'grey', linestyle = '--', linewidth = 0.5)
  672. ax.set_xticklabels(Object_types,fontsize = 12)
  673. plt.axis_label_text_font_style = 'normal'
  674. plt.tick_label_text_font_style = 'normal'
  675. plt.title('NOR (Scopolamine) - Testing phase')
  676. plt.ylim(0, 160)
  677. y, h, col = 60, 5, 'k'
  678. x00, x01 = x[0]+0.02, x[1]-0.02
  679. #Plot t-test between groups
  680. plt.plot([x00, x00, x01, x01], [y, y+h, y+h, y], lw=1.5, c=col)
  681. plt.text(((x00 + x01)/2), y+ 2+h, " $\it{p}$ = 0.738", ha='center', va='bottom', color=col,fontsize=12)
  682. plt.xlabel("Object type",fontsize=14)
  683. plt.ylabel("Exploration (s)",fontsize=14)
  684. plt.savefig('NORstats_Scopolamine_BarPlot.pdf', bbox_inches='tight')
  685. plt.show()
  686. # %%
  687. f_oneway(Duration_Obj_s,Duration_NovObj_s)
  688. # %%
  689. # %%
  690. # %%
  691. # %% [markdown]
  692. # ### Trial 1 - Similar Objects - Scopolamine
  693. # %%
  694. ## NOR tests: MouseIDs: 1, 2, D1, D2, D4, D5_repeat
  695. Duration_green_s= [99.64,20.08,25.64,21.56,38.88,78.88]
  696. Duration_red_s = [95.12,14.6,52.72,33.84,39.12,75.72]
  697. # %%
  698. import matplotlib.pyplot as plt
  699. import numpy as np
  700. # create data
  701. x = [1,1.07]
  702. y1 = np.mean(Duration_green_s)
  703. y2 = np.mean(Duration_red_s)
  704. error1 = scipy.stats.sem(Duration_green_s)
  705. error2 = scipy.stats.sem(Duration_red_s)
  706. width = 0.015
  707. Object_types = ['Similar-Left', 'Similar-Right']
  708. fig, ax = plt.subplots(figsize=(3,3))
  709. plt.bar(x[0]+0.02, y1, width, yerr=error1, color='mediumseagreen', capsize=5,alpha=0.9, ecolor='k',)
  710. plt.bar(x[1]-0.02, y2, width, yerr=error2, color='forestgreen', capsize=5,alpha=0.9, ecolor='k',)
  711. # scatter dots
  712. rng = np.random.default_rng(42)
  713. x_fam = np.full(len(Duration_green_s), x[0] + 0.02) + rng.uniform(-0.003, 0.003, len(Duration_green_s))
  714. x_nov = np.full(len(Duration_red_s), x[1] - 0.02) + rng.uniform(-0.003, 0.003, len(Duration_red_s))
  715. ax.scatter(x_fam, Duration_green_s, s=28, color='mediumseagreen',
  716. edgecolor='black', linewidth=0.4, alpha=0.7, zorder=5)
  717. ax.scatter(x_nov, Duration_red_s, s=28, color='forestgreen',
  718. edgecolor='black', linewidth=0.4, alpha=0.7, zorder=5)
  719. ax.set_xticks([1.02,1.05])
  720. ax.set_xticklabels([])
  721. # ax.yaxis.grid(color = 'grey', linestyle = '--', linewidth = 0.5)
  722. ax.set_xticklabels(Object_types,fontsize = 12)
  723. plt.axis_label_text_font_style = 'normal'
  724. plt.tick_label_text_font_style = 'normal'
  725. plt.title('NOR (Scopolamine) - Familiarization phase')
  726. plt.ylim(0, 160)
  727. y, h, col = 70, 5, 'k'
  728. x00, x01 = x[0]+0.02, x[1]-0.02
  729. #Plot t-test between groups
  730. plt.plot([x00, x00, x01, x01], [y, y+h, y+h, y], lw=1.5, c=col)
  731. plt.text(((x00 + x01)/2), y+ 2+h, " $\it{p}$ = 0.814", ha='center', va='bottom', color=col,fontsize=12)
  732. plt.xlabel("Object type",fontsize=14)
  733. plt.ylabel("Exploration (s)",fontsize=14)
  734. plt.savefig('NORstatsTrial1_Scopolamine_BarPlot.pdf', bbox_inches='tight')
  735. plt.show()
  736. # %%
  737. # %%
  738. f_oneway(Duration_green_s,Duration_red_s)
  739. # %%
  740. # %% [markdown]
  741. # # NOR Indices
  742. # %%
  743. ## NOR tests: MouseIDs: 1, 2, D1, D2, D4, D5_repeat
  744. import numpy as np
  745. Duration_green_1_s= np.array([99.64,20.08,25.64,21.56,38.88,78.88])
  746. Duration_red_1_s = np.array([95.12,14.6,52.72,33.84,39.12,75.72])
  747. Duration_Obj_2_s= np.array([63,14.28,31.08,21.84,40.32,71.64])
  748. Duration_NovObj_2_s =np.array([50.48,14,61.04,19.28,37,91.12])
  749. # %% [markdown]
  750. # ## Discrimination index - Scopolamine
  751. # %%
  752. ## Discrimination index - test phase
  753. DI_2_s = (Duration_NovObj_2_s - Duration_Obj_2_s)/(Duration_Obj_2_s+Duration_NovObj_2_s)
  754. DI_2_s
  755. print(DI_2_s)
  756. print('Mean DI_2_s: ')
  757. print(np.mean(DI_2_s))
  758. print("\n SE DI_2_s:")
  759. print(scipy.stats.sem(DI_2_s))
  760. # %%
  761. ## Discrimination index - familiarization phase
  762. DI_1_s = (Duration_green_1_s - Duration_red_1_s)/(Duration_green_1_s+Duration_red_1_s)
  763. DI_1_s
  764. print(DI_1_s)
  765. print('Mean DI_1_s: ')
  766. print(np.mean(DI_1_s))
  767. print("\n SE DI_1_s:")
  768. print(scipy.stats.sem(DI_1_s))
  769. # %%
  770. f_oneway(DI_1,DI_2)
  771. # %%
  772. # %% [markdown]
  773. # ## Index of global habituation - Scopolamine
  774. # %%
  775. ## Index of global habituation
  776. GI_s = (Duration_green_1_s+Duration_red_1_s)/(Duration_Obj_2_s+Duration_NovObj_2_s)
  777. GI_s
  778. print(GI_s)
  779. print('Mean GI_s: ')
  780. print(np.mean(GI_s))
  781. print("\n SE GI_s:")
  782. print(scipy.stats.sem(GI_s))
  783. # %%
  784. # %% [markdown]
  785. # ## Pereference index - Scopolamine
  786. # %%
  787. ## Recognition Index : Pereference index in test phase
  788. RI_s = (Duration_NovObj_2_s)/(Duration_Obj_2_s+Duration_NovObj_2_s)
  789. RI_s
  790. print(RI_s)
  791. print('Mean RI_s: ')
  792. print(np.mean(RI_s))
  793. print("\n SE RI_s:")
  794. print(scipy.stats.sem(RI_s))
  795. # %%
  796. ## Pereference index in familiarization phase
  797. PI_s = (Duration_green_1_s)/(Duration_green_1_s+Duration_red_1_s)
  798. PI_s
  799. print(PI_s)
  800. print('Mean PI_s: ')
  801. print(np.mean(PI_s))
  802. print("\n SE PI_s:")
  803. print(scipy.stats.sem(PI_s))
  804. # %%
  805. # %%
  806. f_oneway(RI_s,PI_s)
  807. # %%
  808. # %% [markdown]
  809. # ## Plots:
  810. # %%
  811. import matplotlib.pyplot as plt
  812. import numpy as np
  813. import seaborn as sns
  814. import scipy.stats
  815. import matplotlib.patches as mpatches
  816. import matplotlib.patches as patches
  817. # create data
  818. x = np.linspace(1, 12, num=12)
  819. y1 = np.mean(DI_2)
  820. y2 = np.mean(DI_1)
  821. y3 = np.mean(DI_1_s)
  822. y4 = np.mean(DI_2_s)
  823. y5 = np.mean(GI)
  824. y6 = np.mean(GI_s)
  825. y7 = np.mean(RI)
  826. y8 = np.mean(RI_s)
  827. y9 = np.mean(PI)
  828. y10 = np.mean(PI_s)
  829. error1 = scipy.stats.sem(DI_2)
  830. error2 = scipy.stats.sem(DI_1)
  831. error3 = scipy.stats.sem(DI_1_s)
  832. error4 = scipy.stats.sem(DI_2_s)
  833. error5 = scipy.stats.sem(GI)
  834. error6 = scipy.stats.sem(GI_s)
  835. error7 = scipy.stats.sem(RI)
  836. error8 = scipy.stats.sem(RI_s)
  837. error9 = scipy.stats.sem(PI)
  838. error10 = scipy.stats.sem(PI_s)
  839. width = 1
  840. Object_types = ['$DI$', '$GI$', '$RI$', '$PI$']
  841. fig, ax = plt.subplots(figsize=(5.25, 5))
  842. # bars with black error bars
  843. ax.bar(x[0]-0.05, y1, width, yerr=error1, color='c', capsize=5, alpha=0.9, ecolor='black', label='Saline')
  844. ax.bar(x[1]+0.05, y4, width, yerr=error4, color='c', capsize=5, alpha=0.9, ecolor='black', hatch='///', label='Scopolamine')
  845. # ax.bar(x[3]-0.05, y2, width, yerr=error2, color='#EE3B3B', capsize=5, alpha=0.9, ecolor='black')
  846. # ax.bar(x[4]+0.05, y3, width, yerr=error3, color='#EE3B3B', capsize=5, alpha=0.9, ecolor='black', hatch='///')
  847. ax.bar(x[3]-0.05, y5, width, yerr=error5, color='orange', capsize=5, alpha=0.9, ecolor='black')
  848. ax.bar(x[4]+0.05, y6, width, yerr=error6, color='orange', capsize=5, alpha=0.9, ecolor='black', hatch='///')
  849. ax.bar(x[6]-0.05, y7, width, yerr=error7, color='#CD6090', capsize=5, alpha=0.9, ecolor='black')
  850. ax.bar(x[7]+0.05, y8, width, yerr=error8, color='#CD6090', capsize=5, alpha=0.9, ecolor='black', hatch='///')
  851. ax.bar(x[9]-0.05, y9, width, yerr=error9, color='mediumseagreen', capsize=5, alpha=0.9, ecolor='black')
  852. ax.bar(x[10]+0.05, y10, width, yerr=error10, color='mediumseagreen', capsize=5, alpha=0.9, ecolor='black', hatch='///')
  853. # scatter dots
  854. rng = np.random.default_rng(42)
  855. def add_scatter(ax, xpos, values, color, jitter=0.08):
  856. vals = np.asarray(values)
  857. xj = np.full(len(vals), xpos) + rng.uniform(-jitter, jitter, len(vals))
  858. ax.scatter(
  859. xj, vals,
  860. s=30,
  861. color=color,
  862. edgecolor='black',
  863. linewidth=0.4,
  864. alpha=0.7,
  865. zorder=5
  866. )
  867. add_scatter(ax, x[0]-0.05, DI_2, 'c')
  868. add_scatter(ax, x[1]+0.05, DI_2_s, 'c')
  869. # add_scatter(ax, x[3]-0.05, DI_1, '#EE3B3B')
  870. # add_scatter(ax, x[4]+0.05, DI_1_s, '#EE3B3B')
  871. add_scatter(ax, x[3]-0.05, GI, 'orange')
  872. add_scatter(ax, x[4]+0.05, GI_s, 'orange')
  873. add_scatter(ax, x[6]-0.05, RI, '#CD6090')
  874. add_scatter(ax, x[7]+0.05, RI_s, '#CD6090')
  875. add_scatter(ax, x[9]-0.05, PI, 'mediumseagreen')
  876. add_scatter(ax, x[10]+0.05, PI_s, 'mediumseagreen')
  877. sns.set(font_scale=1.3)
  878. ax.set_xticks([1.5, 4.5, 7.5, 10.5])
  879. ax.set_xticklabels(Object_types, fontsize=12, rotation=30)
  880. plt.axis_label_text_font_style = 'Times'
  881. plt.tick_label_text_font_style = 'Times'
  882. plt.title('')
  883. plt.ylim(-.2, 1.55)
  884. plt.rcParams['hatch.linewidth'] = 2
  885. first_patch = patches.Rectangle((2, 1), 1.4, 13, linewidth=0, label='Saline', alpha=0.4)
  886. second_patch = patches.Rectangle((2, 1), 1.4, 13, linewidth=0, label='Scopolamine', hatch='///', alpha=0.4)
  887. plt.legend(handles=[first_patch, second_patch], loc='upper right')
  888. plt.xlabel("", fontsize=14)
  889. plt.ylabel("Index", fontsize=18)
  890. ax.set_xticklabels(ax.get_xticklabels(), fontsize=14)
  891. y, h, col = 0.6, 0.04, 'k'
  892. x00, x01 = x[0]-0.05, x[1]+0.05
  893. x20, x21 = x[3]-0.05, x[4]+0.05
  894. x30, x31 = x[6]-0.05, x[7]+0.05
  895. x40, x41 = x[9]-0.05, x[10]+0.05
  896. # Plot t-test between groups
  897. ax.plot([x00, x00, x01, x01], [y-0.05, y-0.05+h, y-0.05+h, y-10*h], lw=1.5, c=col)
  898. ax.text(((x00 + x01)/2), y-0.07+h, "***", ha='center', va='bottom', color=col, fontsize=14)
  899. ax.plot([x20, x20, x21, x21], [y+0.804-11*h, y+0.804+h, y+0.804+h, y+0.804], lw=1.5, c=col)
  900. ax.text(((x20 + x21)/2), y+0.768+h, "**", ha='center', va='bottom', color=col, fontsize=14)
  901. ax.plot([x30, x30, x31, x31], [y+0.22, y+0.22+h, y+0.22+h, y+0.22-5*h], lw=1.5, c=col)
  902. ax.text(((x30 + x31)/2), y+0.19+h, "***", ha='center', va='bottom', color=col, fontsize=14)
  903. ax.plot([x40, x40, x41, x41], [y+0.02, y+0.02+h, y+0.02+h, y+0.02-1.5*h], lw=1.5, c=col)
  904. ax.text(((x40 + x41)/2), y+0.07+h, "$\it{p}$ = 0.199", ha='center', va='bottom', color=col, fontsize=10)
  905. plt.savefig('NORstats_SalinevsScopolamine.pdf', bbox_inches='tight')
  906. plt.show();
  907. # %%
  908. f_oneway(DI_2,DI_2_s)
  909. # %%
  910. f_oneway(DI_1,DI_1_s)
  911. # %%
  912. f_oneway(GI,GI_s)
  913. # %%
  914. f_oneway(RI,RI_s)
  915. # %%
  916. f_oneway(PI,PI_s)
  917. # %%
  918. # %%
  919. # %% [markdown]
  920. # ## Correlations
  921. # %%
  922. ## NOR tests: 1_Repeat, 2, D1, D2, D4, D5, 3, 5
  923. DCC_NOR = [0.41,0.151,0.087,0.079,0.728,0.29,0.243,0.394]
  924. DCC_Cage = [0.965,1.995,1.799,0.515,0.819,1.145,0.807,0.873]
  925. BR_NOR =[0.9998,0.9093,0.9998,0.91494,0.99867,0.99432,0.9998,0.99801]
  926. BR_Cage = [0.93821,0.90995,0.87027,0.90995,0.98629,0.90978,0.89195,0.92929]
  927. SCE_NOR =[0.13,0.018,0.069,0.0518,0.0358,0.014,0.0502,0.011]
  928. SCE_Cage = [0.2028,0.2346,0.1928,0.2128,0.2289,0.1879,0.4072,0.4409]
  929. ## NOR tests: MouseIDs: 1, 2, D1, D2, D4, D5_repeat
  930. DCC_Scopolamine = [0.308,2.948,0.946,0.881,0.774,2.278]
  931. DCC_Cage=[0.965,1.995,1.799,0.515,0.819,1.145]
  932. BR_Scopolamine = [0.85568,0.62586,0.93741,0.98936,0.97951,0.6031]
  933. BR_Cage = [0.93821,0.90995,0.87027,0.90995,0.98629,0.90978]
  934. SCE_Scopolamine = [0.27286709,0.36076511,0.093427,0.2603256,0.28944217,0.32972748]
  935. SCE_Cage = [0.2028,0.2346,0.1928,0.2128,0.2289,0.1879]
  936. # %%
  937. from numpy.random import randn
  938. from numpy.random import seed
  939. from scipy.stats import pearsonr
  940. from scipy import stats
  941. # %%
  942. corr, p_value = pearsonr(DCC_NOR, DI_2)
  943. print('Pearsons correlation DCC/DI_2: %.3f' % corr)
  944. print('Pearsons p-value DCC/DI_2: %.8f\n' % p_value)
  945. corr2,p_value = stats.spearmanr(DCC_NOR, DI_2)
  946. print('Spearman correlation DCC/DI_2: %.3f' % corr2)
  947. print('Spearman p-value DCC/DI_2: %.8f\n' % p_value)
  948. corr, p_value = pearsonr(BR_NOR, DI_2)
  949. print('Pearsons correlation BR/DI_2: %.3f' % corr)
  950. print('Pearsons p-value BR/DI_2: %.8f\n' % p_value)
  951. corr2,p_value = stats.spearmanr(BR_NOR, DI_2)
  952. print('Spearman correlation DCC/DI_2: %.3f' % corr2)
  953. print('Spearman p-value BR/DI_2: %.8f\n' % p_value)
  954. corr, p_value = pearsonr(SCE_NOR, DI_2)
  955. print('Pearsons correlation SCE/DI_2: %.3f' % corr)
  956. print('Pearsons p-value SCE/DI_2: %.8f\n' % p_value)
  957. corr2,p_value = stats.spearmanr(SCE_NOR, DI_2)
  958. print('Spearman correlation SCE/DI_2: %.3f' % corr2)
  959. print('Spearman p-value SCE/DI_2: %.8f\n' % p_value)
  960. # %%
  961. corr, p_value = pearsonr(DCC_NOR, DI_1)
  962. print('Pearsons correlation DCC/DI_1: %.3f' % corr)
  963. print('Pearsons p-value DCC/DI_1: %.8f\n' % p_value)
  964. corr2,p_value = stats.spearmanr(DCC_NOR, DI_1)
  965. print('Spearman correlation DCC/DI_1: %.3f' % corr2)
  966. print('Spearman p-value DCC/DI_1: %.8f\n' % p_value)
  967. corr, p_value = pearsonr(BR_NOR, DI_1)
  968. print('Pearsons correlation BR/DI_1: %.3f' % corr)
  969. print('Pearsons p-value BR/DI_1: %.8f\n' % p_value)
  970. corr2,p_value = stats.spearmanr(BR_NOR, DI_1)
  971. print('Spearman correlation DCC/DI_1: %.3f' % corr2)
  972. print('Spearman p-value BR/DI_1: %.8f\n' % p_value)
  973. corr, p_value = pearsonr(SCE_NOR, DI_1)
  974. print('Pearsons correlation SCE/DI_1: %.3f' % corr)
  975. print('Pearsons p-value SCE/DI_1: %.8f\n' % p_value)
  976. corr2,p_value = stats.spearmanr(SCE_NOR, DI_1)
  977. print('Spearman correlation SCE/DI_1: %.3f' % corr2)
  978. print('Spearman p-value SCE/DI_1: %.8f\n' % p_value)
  979. # %%
  980. corr, p_value = pearsonr(DCC_NOR, GI)
  981. print('Pearsons correlation DCC/GI: %.3f' % corr)
  982. print('Pearsons p-value DCC/GI: %.8f\n' % p_value)
  983. corr2,p_value = stats.spearmanr(DCC_NOR, GI)
  984. print('Spearman correlation DCC/GI: %.3f' % corr2)
  985. print('Spearman p-value DCC/GI: %.8f\n' % p_value)
  986. corr, p_value = pearsonr(BR_NOR, GI)
  987. print('Pearsons correlation BR/GI: %.3f' % corr)
  988. print('Pearsons p-value BR/GI: %.8f\n' % p_value)
  989. corr2,p_value = stats.spearmanr(BR_NOR, GI)
  990. print('Spearman correlation DCC/GI: %.3f' % corr2)
  991. print('Spearman p-value BR/GI: %.8f\n' % p_value)
  992. corr, p_value = pearsonr(SCE_NOR, GI)
  993. print('Pearsons correlation SCE/GI: %.3f' % corr)
  994. print('Pearsons p-value SCE/GI: %.8f\n' % p_value)
  995. corr2,p_value = stats.spearmanr(SCE_NOR, GI)
  996. print('Spearman correlation SCE/GI: %.3f' % corr2)
  997. print('Spearman p-value SCE/GI: %.8f\n' % p_value)
  998. # %%
  999. corr, p_value = pearsonr(DCC_NOR, RI)
  1000. print('Pearsons correlation DCC/RI: %.3f' % corr)
  1001. print('Pearsons p-value DCC/RI: %.8f\n' % p_value)
  1002. corr2,p_value = stats.spearmanr(DCC_NOR, RI)
  1003. print('Spearman correlation DCC/RI: %.3f' % corr2)
  1004. print('Spearman p-value DCC/RI: %.8f\n' % p_value)
  1005. corr, p_value = pearsonr(BR_NOR, RI)
  1006. print('Pearsons correlation BR/RI: %.3f' % corr)
  1007. print('Pearsons p-value BR/RI: %.8f\n' % p_value)
  1008. corr2,p_value = stats.spearmanr(BR_NOR, RI)
  1009. print('Spearman correlation DCC/RI: %.3f' % corr2)
  1010. print('Spearman p-value BR/RI: %.8f\n' % p_value)
  1011. corr, p_value = pearsonr(SCE_NOR, RI)
  1012. print('Pearsons correlation SCE/RI: %.3f' % corr)
  1013. print('Pearsons p-value SCE/RI: %.8f\n' % p_value)
  1014. corr2,p_value = stats.spearmanr(SCE_NOR, RI)
  1015. print('Spearman correlation SCE/RI: %.3f' % corr2)
  1016. print('Spearman p-value SCE/RI: %.8f\n' % p_value)
  1017. # %%
  1018. # %%
  1019. # %%
  1020. # %%
  1021. import seaborn as sns
  1022. # ax = sns.scatterplot(y="branching_ratio", x="hit_miss_ratio", data=sorted_all_data_df)
  1023. sns.lmplot(y="branching_ratio", x="hit_miss_ratio", hue="activity_status",data=sorted_all_data_df)
  1024. sns.set(style="darkgrid")
  1025. plt.grid(False)
  1026. plt.savefig('Results/Statistical Analysis/'+'Pearson_Corr_BR-HMR_act&rest.pdf', bbox_inches='tight')
  1027. sns.set(font_scale = 1.5)
  1028. b = sns.lmplot(y="branching_ratio", x="hit_miss_ratio", data=sorted_all_data_df,line_kws={'color': 'red'})
  1029. sns.set(style="darkgrid")
  1030. plt.grid(False)
  1031. corr, p_value= stats.pearsonr(sorted_all_data_df['branching_ratio'],sorted_all_data_df['hit_miss_ratio'])
  1032. plt.ylabel('BR', fontsize = 22)
  1033. plt.xlabel('H/M ratio', fontsize = 22)
  1034. # plt.setp(ax.get_yticklabels(), fontsize=20)
  1035. # plt.setp(ax.get_xticklabels(), fontsize=20)
  1036. # plt.text(1.2,0.8, "Pearson Correlation: %.3f \n p-value: %.6f" % (corr,p_value), horizontalalignment='left', size='medium', color='black', weight='semibold')
  1037. plt.savefig('Paper Plots/'+'Pearson_Corr_BR-HMR.pdf', bbox_inches='tight')
  1038. print('p-value',p_value)
  1039. print('Correlation',corr)
  1040. # %%
  1041. # %%
  1042. # %% [markdown]
  1043. # ## Number of neurons saline and scopolamine
  1044. # %%
  1045. ##Saline:
  1046. x = [578,203,483,269,221,174,195,203]
  1047. ##Scopolamine:
  1048. y =[179,432,192,175,285,444]
  1049. ##Cage:
  1050. y2 =[224,114,251,197,549,170,176,158]
  1051. # %%
  1052. from scipy import stats, optimize, interpolate
  1053. from scipy.stats import alexandergovern
  1054. from scipy.stats import f_oneway
  1055. # %%
  1056. alexandergovern(x,y)
  1057. # %%
  1058. f_oneway(x,y)
  1059. # %%
  1060. # %% [markdown]
  1061. # # Review round
  1062. # %% [markdown]
  1063. # ## Linking behaviour and avalanche statistics:
  1064. # %%
  1065. import pandas as pd
  1066. import numpy as np
  1067. avalanche_rows = [
  1068. (1, "Cage", 2.944741, 1.826018, 2.353877, 1.388832, 0.015756, 0.965045, 0.93821, 0.2028),
  1069. (1, "NOR (Saline)", 2.937048, 2.031536, 1.875380, 1.465491, 0.008734, 0.409889, 0.9998, 0.13),
  1070. (1, "NOR (Scopolamine)", 2.127443, 1.848198, 1.324312, 1.631867, 0.007362, 0.307555, 0.85568, 0.2729),
  1071. (2, "Cage", 2.437292, 1.402012, 3.564297, 1.569605, 0.005116, 1.994692, 0.90995, 0.2346),
  1072. (2, "NOR (Saline)", 2.924021, 2.274226, 1.509953, 1.359075, 0.006379, 0.150878, 0.9093, 0.0690),
  1073. (2, "NOR (Scopolamine)", 2.550383, 1.385671, 3.994948, 1.047235, 0.007634, 2.947714, 0.62686, 0.3608),
  1074. (3, "Cage", 1.993352, 1.446372, 2.217301, 1.410267, 0.011417, 0.807034, 0.89195, 0.4072),
  1075. (3, "NOR (Saline)", 2.406970, 1.830398, 1.683970, 1.440837, 0.015476, 0.243133, 0.9998, 0.0502),
  1076. (4, "Cage", 2.334646, 1.495112, 2.676519, 1.803963, 0.014538, 0.872556, 0.92929, 0.4409),
  1077. (4, "NOR (Saline)", 2.841140, 2.009749, 1.823365, 1.429635, 0.008229, 0.393730, 0.99801, 0.0110),
  1078. (5, "Cage", 2.085834, 1.333674, 3.240000, 1.440826, 0.015182, 1.799174, 0.87027, 0.1928),
  1079. (5, "NOR (Saline)", 2.444311, 1.925183, 1.561678, 1.475117, 0.020117, 0.086561, 0.9998, 0.0690),
  1080. (5, "NOR (Scopolamine)", 2.566835, 1.700068, 2.238118, 1.292573, 0.011734, 0.945546, 0.93741, 0.0934),
  1081. (6, "Cage", 2.337229, 1.682043, 1.956755, 1.441831, 0.005785, 0.514924, 0.90995, 0.2128),
  1082. (6, "NOR (Saline)", 2.397312, 1.992004, 1.409372, 1.488863, 0.012023, 0.079491, 0.91494, 0.0518),
  1083. (6, "NOR (Scopolamine)", 3.058842, 1.864875, 2.376188, 1.495326, 0.006791, 0.880862, 0.98936, 0.2603),
  1084. (7, "Cage", 2.420109, 1.589785, 2.392807, 1.573986, 0.010804, 0.818821, 0.98629, 0.2289),
  1085. (7, "NOR (Saline)", 2.327177, 1.581250, 2.283317, 1.555539, 0.006043, 0.727777, 0.99867, 0.0358),
  1086. (7, "NOR (Scopolamine)", 2.864331, 1.777053, 2.395078, 1.621442, 0.006387, 0.773636, 0.97951, 0.2894),
  1087. (8, "Cage", 2.387429, 1.528691, 2.611235, 1.465911, 0.010931, 1.145325, 0.90978, 0.1879),
  1088. (8, "NOR (Saline)", 2.499902, 1.847468, 1.768339, 1.478169, 0.007238, 0.290170, 0.99432, 0.0140),
  1089. (8, "NOR (Scopolamine)", 2.513659, 1.430313, 3.505688, 1.227273, 0.018508, 2.278416, 0.6031, 0.3297),
  1090. ]
  1091. avalanche_df = pd.DataFrame(
  1092. avalanche_rows,
  1093. columns=["MouseID","Condition","alpha_duration","tau_size","beta_pred","beta_fitted","KS","DCC","BR","SCE"]
  1094. )
  1095. # Normalize condition labels for merging later
  1096. avalanche_df["ConditionKey"] = avalanche_df["Condition"].replace({
  1097. "NOR (Saline)": "Saline",
  1098. "NOR (Scopolamine)": "Scopolamine",
  1099. "Cage": "Cage"
  1100. })
  1101. avalanche_df.head()
  1102. # %%
  1103. import numpy as np
  1104. import pandas as pd
  1105. # ---------------------------
  1106. # SALINE (Mouse order: 3,5,7,8,1,6,4,2)
  1107. # ---------------------------
  1108. mouse_saline = np.array([3,5,7,8,1,6,4,2])
  1109. Duration_green_1 = np.array([45.72,49.68,43.78,81.72,98.08,96.96,41.12,46.68])
  1110. Duration_red_1 = np.array([28.04,62.96,39.36,54.48,104.24,126.8,33.24,35.88])
  1111. Duration_Obj_2 = np.array([33.72,32.8,42.4,37.28,68.36,57.0,34.6,42.56]) # familiar in trial 2
  1112. Duration_NovObj_2 = np.array([120.56,87.16,98.24,186.04,76.68,197.64,50.4,108.96])
  1113. # Trial 2 (test): novelty preference
  1114. DI_2 = (Duration_NovObj_2 - Duration_Obj_2) / (Duration_Obj_2 + Duration_NovObj_2)
  1115. RI = Duration_NovObj_2 / (Duration_Obj_2 + Duration_NovObj_2)
  1116. # Trial 1 (familiarization): object-color preference (should be ~0 on average; useful sanity check)
  1117. DI_1 = (Duration_green_1 - Duration_red_1) / (Duration_green_1 + Duration_red_1)
  1118. PI = Duration_green_1 / (Duration_green_1 + Duration_red_1)
  1119. # Global habituation (trial1 total / trial2 total)
  1120. GI = (Duration_green_1 + Duration_red_1) / (Duration_Obj_2 + Duration_NovObj_2)
  1121. behav_saline = pd.DataFrame({
  1122. "MouseID": mouse_saline,
  1123. "ConditionKey": "Saline",
  1124. "DI": DI_2,
  1125. "DI_fam": DI_1,
  1126. "GI": GI,
  1127. "RI": RI,
  1128. "PI": PI,
  1129. "T1_total": Duration_green_1 + Duration_red_1,
  1130. "T2_total": Duration_Obj_2 + Duration_NovObj_2,
  1131. "T2_novel": Duration_NovObj_2,
  1132. "T2_familiar": Duration_Obj_2
  1133. })
  1134. # ---------------------------
  1135. # SCOPOLAMINE (Mouse order: 1,2,5,6,7,8)
  1136. # ---------------------------
  1137. mouse_scop = np.array([1,2,5,6,7,8])
  1138. Duration_green_1_s = np.array([99.64,20.08,25.64,21.56,38.88,78.88])
  1139. Duration_red_1_s = np.array([95.12,14.6,52.72,33.84,39.12,75.72])
  1140. Duration_Obj_2_s = np.array([63.0,14.28,31.08,21.84,40.32,71.64])
  1141. Duration_NovObj_2_s = np.array([50.48,14.0,61.04,19.28,37.0,91.12])
  1142. DI_2_s = (Duration_NovObj_2_s - Duration_Obj_2_s) / (Duration_Obj_2_s + Duration_NovObj_2_s)
  1143. RI_s = Duration_NovObj_2_s / (Duration_Obj_2_s + Duration_NovObj_2_s)
  1144. DI_1_s = (Duration_green_1_s - Duration_red_1_s) / (Duration_green_1_s + Duration_red_1_s)
  1145. PI_s = Duration_green_1_s / (Duration_green_1_s + Duration_red_1_s)
  1146. GI_s = (Duration_green_1_s + Duration_red_1_s) / (Duration_Obj_2_s + Duration_NovObj_2_s)
  1147. behav_scop = pd.DataFrame({
  1148. "MouseID": mouse_scop,
  1149. "ConditionKey": "Scopolamine",
  1150. "DI": DI_2_s,
  1151. "DI_fam": DI_1_s,
  1152. "GI": GI_s,
  1153. "RI": RI_s,
  1154. "PI": PI_s,
  1155. "T1_total": Duration_green_1_s + Duration_red_1_s,
  1156. "T2_total": Duration_Obj_2_s + Duration_NovObj_2_s,
  1157. "T2_novel": Duration_NovObj_2_s,
  1158. "T2_familiar": Duration_Obj_2_s
  1159. })
  1160. behav_df = pd.concat([behav_saline, behav_scop], ignore_index=True).sort_values(["ConditionKey","MouseID"])
  1161. behav_df
  1162. # %%
  1163. merged = avalanche_df.merge(behav_df, on=["MouseID","ConditionKey"], how="inner")
  1164. # keep only NOR conditions
  1165. merged_nor = merged[merged["ConditionKey"].isin(["Saline","Scopolamine"])].copy()
  1166. print("Merged rows:", len(merged_nor))
  1167. merged_nor[["MouseID","ConditionKey","DCC","BR","SCE","tau_size","alpha_duration","DI","GI","RI","PI"]].sort_values(["ConditionKey","MouseID"])
  1168. # %%
  1169. import matplotlib.pyplot as plt
  1170. from scipy.stats import spearmanr, pearsonr
  1171. def scatter_stats(df, x, y, title):
  1172. d = df[[x,y]].dropna()
  1173. n = len(d)
  1174. if n < 3:
  1175. print(f"{title}: not enough data (n={n})")
  1176. return
  1177. r_s, p_s = spearmanr(d[x], d[y])
  1178. r_p, p_p = pearsonr(d[x], d[y])
  1179. # best-fit line (simple linear fit)
  1180. m, b = np.polyfit(d[x].astype(float), d[y].astype(float), 1)
  1181. xs = np.linspace(d[x].min(), d[x].max(), 200)
  1182. ys = m*xs + b
  1183. plt.figure(figsize=(5,4))
  1184. plt.scatter(d[x], d[y], alpha=0.85)
  1185. plt.plot(xs, ys)
  1186. plt.title(title)
  1187. plt.xlabel(x)
  1188. plt.ylabel(y)
  1189. plt.tight_layout()
  1190. plt.show()
  1191. print(f"{title} | n={n}")
  1192. print(f" Spearman r={r_s:.3f}, p={p_s:.3g}")
  1193. print(f" Pearson r={r_p:.3f}, p={p_p:.3g}")
  1194. print("")
  1195. # Choose behavior metric(s) to relate to avalanches
  1196. behav_metrics = ["DI", "RI", "GI", "PI"] # PI/DI_fam are more "control" measures
  1197. aval_metrics = ["DCC", "SCE", "BR", "tau_size", "alpha_duration"]
  1198. for cond in ["Saline", "Scopolamine"]:
  1199. dfc = merged_nor[merged_nor["ConditionKey"]==cond].copy()
  1200. for bx in behav_metrics:
  1201. for ay in ["DCC","SCE","BR"]:
  1202. scatter_stats(dfc, bx, ay, title=f"{cond}: {ay} vs {bx}")
  1203. # %%
  1204. COLORS = {
  1205. "Saline": {
  1206. "scatter": "#4C9F9F", # muted teal
  1207. "line": "#2F6F6F"
  1208. },
  1209. "Scopolamine": {
  1210. "scatter": "#C96A4A", # muted rust
  1211. "line": "#8C3F28"
  1212. }
  1213. }
  1214. # %%
  1215. import numpy as np
  1216. import matplotlib.pyplot as plt
  1217. import matplotlib as mpl
  1218. from scipy.stats import spearmanr
  1219. # Clean white background everywhere
  1220. plt.rcParams.update({
  1221. "figure.facecolor": "white",
  1222. "axes.facecolor": "white",
  1223. "savefig.facecolor": "white"
  1224. })
  1225. # Hard reset to default matplotlib style
  1226. plt.style.use("default")
  1227. mpl.rcdefaults()
  1228. # Explicit global spine defaults
  1229. mpl.rcParams.update({
  1230. "axes.edgecolor": "black",
  1231. "axes.linewidth": 1.0,
  1232. "axes.spines.top": True,
  1233. "axes.spines.bottom": True,
  1234. "axes.spines.left": True,
  1235. "axes.spines.right": True,
  1236. "axes.facecolor": "white",
  1237. "figure.facecolor": "white",
  1238. "savefig.facecolor": "white",
  1239. })
  1240. COLORS = {
  1241. "Saline": {
  1242. "scatter": "#4C9F9F", # muted teal
  1243. "line": "#2F6F6F"
  1244. },
  1245. "Scopolamine": {
  1246. "scatter": "#C96A4A", # muted rust
  1247. "line": "#8C3F28"
  1248. }
  1249. }
  1250. def make_behavior_avalanche_subplot_figure(
  1251. merged_nor,
  1252. xcol,
  1253. conditions=("Saline", "Scopolamine"),
  1254. ycols=("DCC", "SCE", "BR", "tau_size", "alpha_duration"),
  1255. ylabels=("DCC", "Shape collapse error (SCE)", "Branching ratio (BR)",
  1256. r"Avalanche size exponent $\tau$", r"Avalanche duration exponent $\alpha$"),
  1257. figsize=(16, 7),
  1258. savepath_pdf="Fig_behavior_vs_avalanche.pdf",
  1259. dpi=300
  1260. ):
  1261. missing = [c for c in ["ConditionKey", xcol, *ycols] if c not in merged_nor.columns]
  1262. if missing:
  1263. raise ValueError(f"merged_nor missing columns: {missing}")
  1264. n_rows = len(conditions)
  1265. n_cols = len(ycols)
  1266. fig, axes = plt.subplots(n_rows, n_cols, figsize=figsize, sharex="col")
  1267. if n_rows == 1:
  1268. axes = np.expand_dims(axes, axis=0)
  1269. if n_cols == 1:
  1270. axes = np.expand_dims(axes, axis=1)
  1271. for r, cond in enumerate(conditions):
  1272. dfc = merged_nor[merged_nor["ConditionKey"] == cond].copy()
  1273. color_scatter = COLORS[cond]["scatter"]
  1274. color_line = COLORS[cond]["line"]
  1275. for c, (ycol, ylabel) in enumerate(zip(ycols, ylabels)):
  1276. ax = axes[r, c]
  1277. d = dfc[[xcol, ycol]].dropna()
  1278. x = d[xcol].astype(float).to_numpy()
  1279. y = d[ycol].astype(float).to_numpy()
  1280. # Scatter
  1281. ax.scatter(
  1282. x, y,
  1283. s=45,
  1284. alpha=0.85,
  1285. color=color_scatter,
  1286. edgecolor="none"
  1287. )
  1288. # Regression line + stats
  1289. if len(d) >= 3 and np.unique(x).size >= 2:
  1290. m, b = np.polyfit(x, y, 1)
  1291. xs = np.linspace(np.min(x), np.max(x), 200)
  1292. ax.plot(xs, m * xs + b, color=color_line, linewidth=2)
  1293. rs, ps = spearmanr(x, y)
  1294. ax.text(
  1295. 0.04, 0.96,
  1296. f"Spearman r={rs:.2f}\np={ps:.2g}\nn={len(d)}",
  1297. transform=ax.transAxes,
  1298. va="top",
  1299. ha="left",
  1300. fontsize=12
  1301. )
  1302. else:
  1303. ax.text(
  1304. 0.04, 0.96,
  1305. f"n={len(d)}",
  1306. transform=ax.transAxes,
  1307. va="top",
  1308. ha="left",
  1309. fontsize=14
  1310. )
  1311. # Titles / labels
  1312. if r == 0:
  1313. ax.set_title(ylabel, fontsize=14)
  1314. if c == 0:
  1315. ax.set_ylabel(cond, fontsize=14)
  1316. # Axes styling: keep all borders
  1317. for spine in ax.spines.values():
  1318. spine.set_visible(True)
  1319. spine.set_linewidth(1.0)
  1320. ax.tick_params(axis="both", which="major", labelsize=12)
  1321. ax.grid(False)
  1322. # X-axis label only on bottom row
  1323. for ax in axes[-1, :]:
  1324. ax.set_xlabel(xcol, fontsize=14)
  1325. plt.tight_layout()
  1326. fig.savefig(savepath_pdf, bbox_inches="tight")
  1327. plt.show()
  1328. print(f"Saved: {savepath_pdf}")
  1329. # ---- Run it (behavioural metric vs DCC/SCE/BR/tau/alpha; Saline vs Scopolamine) ----
  1330. for beh_metric in {"PI","GI","RI","DI"}:
  1331. metric = beh_metric
  1332. make_behavior_avalanche_subplot_figure(
  1333. merged_nor,
  1334. xcol=metric,
  1335. figsize=(16, 6),
  1336. savepath_pdf=f"Fig_{metric}_vs_avalanchemetrics.pdf"
  1337. )
  1338. # %%
  1339. # %%

Paper_Plotting_NOR &Criticality_Stats.ipynb, no license · at the source

Overview

Authors: Forough Habibollahi1,2,3, Dechuan Sun3,4, Anthony N. Burkitt1,5, Chris French3,6
  1. Department of Biomedical Engineering, The University of Melbourne,Melbourne, VIC Australia
  2. Cortical Labs Pty Ltd, Melbourne, VIC Australia
  3. Neural Dynamics Laboratory, Department of Medicine, The University of Melbourne,Melbourne, VIC Australia
  4. Department of Electrical and Electronic Engineering, The University of Melbourne,Melbourne, VIC Australia
  5. Graeme Clark Institute for Biomedical Engineering, The University of Melbourne,Melbourne, VIC Australia
  6. Neurology Department, Royal Melbourne Hospital,Melbourne, VIC Australia
Institutions: The University of Melbourne (Australia); The Royal Melbourne Hospital (Australia)
Journal: Communications biology, volume 9, issue 1, article 890
Dates: received 6 November 2025; accepted 15 April 2026; published online 28 April 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1038/s42003-026-10132-z · PMID 42045604 · PMCID PMC13332206 · OpenAlex W7155913018
Open access: gold, a free copy (OpenAlex)
Preprint: osf.io/uemwd
Status: code verified
Categories: mouse (organism), Alzheimer's / dementia (population), cognitive (subfield)
Methods: Statistics, Machine learning, Spectral & time-frequency, fMRI & imaging, Single-unit activity, calcium imaging
Keywords: Dynamical systems, Spatial memory, Hippocampus, Alzheimer's disease
MeSH: CA1 Region, Hippocampal*, Cognition*, Hippocampus*, Memory Disorders*, Animals, Male, Mice, Mice, Inbred C57BL, Scopolamine (* major topic)
Topic: Memory and Neural Mechanisms (Cognitive Neuroscience, Neuroscience), according to OpenAlex
Citations: cited by 3 papers (Europe PMC); 73 references in the paper

Abstract

The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.

Repository

Its files are read in the Code ↔ Paper reader above, with 3 matches between paragraphs and lines of code.

OSF uemwd

License: none: the authors keep all their rights
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Languages: Jupyter (2)
Size: 5 files, 2 scripts
Software Heritage: not checked
Found in: “Code availability”
Holds: 2 notebooks
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: Matplotlib (2 files), NumPy (2 files), pandas (2 files), SciPy (2 files), Pingouin (1 file), scikit-posthocs (1 file), seaborn (1 file)
Availability: 1 check, the latest on 30 September 2026: the link answers (HTTP 200)
  • 30 September 2026: the link answers (HTTP 200)
2 files

Code availability statement

The paper has a code availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

Read it in the paper: doi.org/10.1038/s42003-026-10132-z.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 2 scripts, each with its path and the digest of its content;
  • 3 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Data availability statement

The paper has a data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

  • no repository, dataset or request procedure was recognized in it

Read it in the paper: doi.org/10.1038/s42003-026-10132-z.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 30 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 4 authors, 4 keywords, 9 MeSH terms, 1 funder, 68 references.

Cite

This paper

Habibollahi, F., Sun, D., Burkitt, A. N., & French, C. (2026). Hippocampal criticality tracks cognitive demand and shifts with memory impairment. Communications biology, 9(1), 890. https://doi.org/10.1038/s42003-026-10132-z

BibTeX

@article{habibollahi2026hippocampal,
author = {Habibollahi, Forough and Sun, Dechuan and Burkitt, Anthony N. and French, Chris},
title = {{Hippocampal criticality tracks cognitive demand and shifts with memory impairment}},
journal = {Communications biology},
year = {2026},
month = apr,
volume = {9},
number = {1},
pages = {890},
publisher = {Nature Publishing Group},
issn = {2399-3642},
doi = {10.1038/s42003-026-10132-z},
url = {https://doi.org/10.1038/s42003-026-10132-z},
pmid = {42045604},
pmcid = {PMC13332206}
}

RIS

TY - JOUR
AU - Habibollahi, Forough
AU - Sun, Dechuan
AU - Burkitt, Anthony N.
AU - French, Chris
TI - Hippocampal criticality tracks cognitive demand and shifts with memory impairment
T2 - Communications biology
J2 - Commun Biol
PY - 2026
DA - 2026/04/28
VL - 9
IS - 1
SP - 890
SN - 2399-3642
PB - Nature Publishing Group
DO - 10.1038/s42003-026-10132-z
UR - https://doi.org/10.1038/s42003-026-10132-z
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s42003-026-10132-z",
"type": "article-journal",
"title": "Hippocampal criticality tracks cognitive demand and shifts with memory impairment",
"container-title": "Communications biology",
"author": [
{
"family": "Habibollahi",
"given": "Forough"
},
{
"family": "Sun",
"given": "Dechuan"
},
{
"family": "Burkitt",
"given": "Anthony N."
},
{
"family": "French",
"given": "Chris"
}
],
"container-title-short": "Commun Biol",
"volume": "9",
"issue": "1",
"page": "890",
"DOI": "10.1038/s42003-026-10132-z",
"PMID": "42045604",
"PMCID": "PMC13332206",
"ISSN": "2399-3642",
"publisher": "Nature Publishing Group",
"URL": "https://doi.org/10.1038/s42003-026-10132-z",
"language": "en",
"issued": {
"date-parts": [
[
2026,
4,
28
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1016/j.isci.2026.117212 [code]
Critical neuronal avalanches arise from excitation-inhibition balanced spontaneous activity.
Journal: iScience
In common: 15 references
[2] doi:10.1371/journal.pcbi.1014521 [code]
Whisker stimulation reinforces a resting-state network in the barrel cortex: Nested oscillations and avalanches.
Journal: PLoS computational biology
In common: 10 references
[3] doi:10.1038/s41467-026-74466-2 [code]
Neuromorphic hierarchical modular reservoirs.
Journal: Nature communications
In common: Pingouin, seaborn, pandas, 3 other tools, 4 references
[4] doi:10.1162/imag.a.1252 [code]
Does the brain's E:I balance really shape long-range temporal correlations? Lessons learned from 3T MRI.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: seaborn, pandas, SciPy, 2 other tools, 5 references
[5] doi:10.1162/imag.a.1348 [code]
The role of high-amplitude bursts of high-gamma activity in naturalistic speech and music listening.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: seaborn, pandas, SciPy, 2 other tools, cognitive, 4 references
[6] doi:10.1016/j.isci.2026.117375 [code]
Motor priming is associated with widespread recruitment into neural ensembles and more rapid ensemble transitions.
Journal: iScience
In common: scikit-posthocs, Pingouin, seaborn, 4 other tools, 1 reference
[7] doi:10.1126/sciadv.aea1037 [code]
Distinct cortical spatial representations learned along disparate visual pathways.
Journal: Science advances
In common: seaborn, pandas, SciPy, 2 other tools, author Anthony N. Burkitt
[8] doi:10.1038/s41593-026-02362-5 [code]
Replay of procedural memory is independent of the hippocampus.
Journal: Nature neuroscience
In common: scikit-posthocs, Pingouin, seaborn, 4 other tools, cognitive, mouse
[9] doi:10.1093/bioinformatics/btag570 [code]
CASCADE: criticality avalanche spike cross-platform analysis detection engine, a multi-manufacturer MEA bash analysis pipeline.
Journal: Bioinformatics (Oxford, England)
In common: pandas, SciPy, Matplotlib, 1 other tool, 4 references
[10] doi:10.1162/imag.a.1234 [code]
Multiscale parcellation of dynamic causal models of the brain.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: 6 references

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.