Reproducing Peyrache et al. (2015) from DANDI:000056¶

Paper. Peyrache A, Lacroix MM, Petersen PC, Buzsáki G (2015). Internally organized mechanisms of the head direction sense. Nature Neuroscience 18, 569-575. doi:10.1038/nn.3968.

Dataset. DANDI:000056, version 0.261106.1949 (doi:10.48324/dandi.000056/0.261106.1949), streamed from the archive. The paper cites no version of the dandiset. This is the most recent published version, and the only one whose units carry a brain region (ADn or post-subiculum), the paper's sleep scoring and the open-field epoch. The earlier versions (0.210812.1518, 0.250624.0430) hold 40 sessions without regions, so they cannot separate the two structures that every claim compares; nothing here was read from them.

Text. The claims file claims/peyrache-2015.yaml was written from the NIH author manuscript (PMC4376557, Europe PMC) with its supplements (Supplementary Figures 1 to 8, Supplementary Table 1, reporting checklist). Every method below is from that file's criteria, or from a passage of the paper cited in hd.py or in the cell.

Claims. 35 claims. 32 are tested here, and two more (fig5d-adn-predicts-pos-reliably, fig5e-adn-predicts-pos, the GLM of Fig. 5d,e) in glm_peyrache_2015.ipynb, which runs on its own, as the GLM is slow (its run time is printed there). The last, fig5e-readout-windows, runs with its dense window grid in glm_windows_peyrache_2015.ipynb. It was first recorded as blocked (too_large); the third verification round agreed with the outcome that notebook gives. The table at the end gives every outcome.

Units of both structures. The files label units of four mice ADn and post-subiculum (PoS): Mouse24, 25 and 28, which the paper lists, and Mouse20, in 3 sessions, on electrode groups the lab labelled 'postsub' on a device the files call the post-subicular probe (data check). Every analysis follows the files' labels; the paper's three mice are shown as a variant where the choice matters.

In [1]:
import os
os.environ["OMP_NUM_THREADS"] = "1"
os.environ["OPENBLAS_NUM_THREADS"] = "1"
import time, resource
import numpy as np
import pandas as pd
from scipy import stats
import statsmodels.formula.api as smf
import statsmodels.api as sm
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import hd
pd.set_option("display.width", 200)
pd.set_option("display.max_columns", 40)
print("dandiset", hd.DANDISET, "version", hd.VERSION)
dandiset 000056 version 0.261106.1949
In [2]:
# Stream and analyse all 42 sessions (four at a time). The per-session
# measures are in hd.analyze_session; everything below aggregates them.
t0 = time.time()
RES = hd.run_all(workers=4)
print(f"analysed {len(RES)} sessions in {(time.time() - t0) / 60:.1f} min; "
      f"peak memory of this process {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1e6:.2f} GB")
analysed 42 sessions in 16.5 min; peak memory of this process 0.29 GB
In [3]:
SUM = pd.DataFrame([o["summary"] for o in RES])
CELLS = pd.DataFrame([c for o in RES for c in o["cells"]])
PAIRS = pd.DataFrame([c for o in RES for c in o["pairs"]])
# Ensembles of HD cells under (hd-a), with every measure, and under (hd-b),
# waking decoding only (decoding-tracks-hd, fig4d,e).
ENS_ALL = pd.DataFrame([{k: v for k, v in c.items() if k != "coherence"} for o in RES for c in o["ens"]])
ENS = ENS_ALL[ENS_ALL.reading == "hd-a"].reset_index(drop=True)
COH = pd.DataFrame([dict(session=c["session"], region=c["region"], state=k[0], ref=k[1], dist=k[2], mean=v[0], median=v[1])
                    for o in RES for c in o["ens"] if c["reading"] == "hd-a" for k, v in c["coherence"].items()])
FAST = pd.DataFrame([c for o in RES for c in o["fast"]])
MONO = pd.DataFrame([c for o in RES for c in o["mono"]])
DEC5B = pd.DataFrame([c for o in RES for c in o["dec5b"]])
LFP = pd.DataFrame([c for o in RES for c in o["lfp"]])
SHIFT = pd.DataFrame([dict(session=o["summary"]["session"], region=k[0], shift_s=k[1], err=v)
                      for o in RES for k, v in o["shift"].items()])
# Mice with both structures. The files label units of four mice ADn and PoS
# (Mouse20 too, on a device the files call the post-subicular probe; see the
# data check). The analyses follow the files' labels; the paper's list of
# three mice (Supplementary Table 1) is shown as a variant where it matters.
BOTH = sorted(SUM[(SUM.n_adn > 0) & (SUM.n_pos > 0)].subject.unique())
DUAL = ["Mouse24", "Mouse25", "Mouse28"]  # Supplementary Table 1: ADn and PoS recorded together
print("mice with units labelled ADn and PoS in one session:", BOTH, "| the paper's:", DUAL)
print({k: len(v) for k, v in dict(cells=CELLS, pairs=PAIRS, ens=ENS, ens_hd_b=ENS_ALL[ENS_ALL.reading == "hd-b"], fast=FAST, mono=MONO, dec5b=DEC5B, lfp=LFP).items()})
mice with units labelled ADn and PoS in one session: ['Mouse20', 'Mouse24', 'Mouse25', 'Mouse28'] | the paper's: ['Mouse24', 'Mouse25', 'Mouse28']
{'cells': 1064, 'pairs': 17362, 'ens': 30, 'ens_hd_b': 38, 'fast': 4302, 'mono': 4765, 'dec5b': 401, 'lfp': 175}

Data check¶

What was loaded, per session, and each check of the description against the values.

In [4]:
cols = ["session", "subject", "n_units", "n_adn", "n_pos", "other_regions", "has_hd", "has_states", "open_field",
        "sleep_pre", "sleep_post", "lfp", "wake_s", "SWS_s", "REM_s", "hd_valid_wake", "x_range_cm", "y_range_cm"]
print(SUM[cols].to_string())
print("\nsessions", len(SUM), "| mice", SUM.subject.nunique(), "| units", SUM.n_units.sum(),
      "| ADn units", SUM.n_adn.sum(), "| PoS units", SUM.n_pos.sum())
print("units per mouse and region:")
print(SUM.groupby("subject")[["n_units", "n_adn", "n_pos"]].sum().to_string())
print("\nsessions without head direction:", list(SUM.session[~SUM.has_hd]))
print("sessions without the paper's sleep scoring:", list(SUM.session[~SUM.has_states]))
print("sessions without LFP:", list(SUM.session[~SUM.lfp]))
print("spike times sorted in every unit of every session:", bool(SUM.spikes_sorted.all()))
print("first spike >= 0 s:", bool((SUM.spike_min >= 0).all()),
      "| sessions with spikes after the last sub-recording:",
      list(SUM.session[SUM.spike_max > SUM.rec_end + 1]), (SUM.spike_max - SUM.rec_end)[SUM.spike_max > SUM.rec_end + 1].round(1).tolist())
h = SUM[SUM.has_hd]
print(f"head direction: {h.hd_rate.unique()} Hz, range {h.hd_min.min():.4f} to {h.hd_max.max():.4f} rad; "
      f"valid (both LEDs) in wake {h.hd_valid_wake.min():.3f} to {h.hd_valid_wake.max():.3f}")
print("head direction = LED (red minus blue) angle minus a fixed offset: resultant length of the difference",
      f"{h.led_hd_R.min():.5f} to {h.led_hd_R.max():.5f}; offsets (deg) by mouse:")
print(h.groupby("subject").led_minus_hd_deg.agg(lambda x: sorted(set(np.round(x % 360, 0)))).to_string())
print("head-direction samples minus position samples:", h.hd_len_minus_pos_len.value_counts().to_dict())
print(f"wake extent of the red LED: x {h.x_range_cm.min():.1f} to {h.x_range_cm.max():.1f} cm, "
      f"y {h.y_range_cm.min():.1f} to {h.y_range_cm.max():.1f} cm (arena 53 x 46 cm, paper)")
print("wake (open field) min:", (h.wake_s / 60).round(1).describe()[["min", "50%", "max"]].to_dict())
print("SWS and REM periods inside the home-cage epochs (fraction):",
      SUM.SWS_in_homecage.min(), SUM.REM_in_homecage.min())
ov = SUM[SUM.wake_in_open_field.notna()]
print(f"scored wake interval against the open-field epochs, {len(ov)} sessions with both: fraction of wake inside "
      f"the open field {ov.wake_in_open_field.min():.4f} to {ov.wake_in_open_field.max():.4f}; fraction of the open field "
      f"inside wake {ov.open_field_in_wake.min():.4f} to {ov.open_field_in_wake.max():.4f}")
print("sessions with an open field but no scored wake (open field used as wake):",
      list(SUM.session[SUM.open_field & SUM.wake_in_open_field.isna()]))
print("\nsessions with a device named postsubicular_probe, by mouse:", SUM.groupby("subject").has_pos_probe.sum().to_dict())
print("electrode groups of the units labelled PoS in Mouse20:")
for _, r in SUM[(SUM.subject == "Mouse20") & (SUM.n_pos > 0)].iterrows():
    print(" ", r.session, r.n_pos, "units |", r.pos_groups)
           session  subject  n_units  n_adn  n_pos                                               other_regions  has_hd  has_states  open_field  sleep_pre  sleep_post    lfp  wake_s      SWS_s    REM_s  hd_valid_wake  x_range_cm  y_range_cm
0   Mouse12-120806  Mouse12       62     41      0                                    Field CA1;Prelimbic area    True        True        True       True        True   True  2188.9   7321.000  1006.40       0.968914    64.33600    55.20500
1   Mouse12-120807  Mouse12       64     41      0                                    Field CA1;Prelimbic area    True        True        True       True        True   True  2079.9   8367.000  1215.10       0.954681    66.55900    56.55500
2   Mouse12-120808  Mouse12       68     40      0                                    Field CA1;Prelimbic area    True        True        True       True        True   True  2739.0   8343.350  1189.60       0.932649   129.91085    97.37885
3   Mouse12-120809  Mouse12      278     50      0  Field CA1;Prelimbic area;Reticular nucleus of the thalamus    True        True        True       True        True   True  2103.8   9832.832  1775.55       0.974909    65.12200    56.97900
4   Mouse12-120810  Mouse12       76     45      0                                    Field CA1;Prelimbic area    True        True        True       True        True   True  1803.6   8818.152  1439.38       0.973841    64.66300    55.87000
5   Mouse17-130125  Mouse17        7      3      0                                                   Field CA1    True        True        True       True        True   True  1847.6   9196.000  1898.00       0.995926    58.51600    66.92900
6   Mouse17-130128  Mouse17       30     22      0                                                   Field CA1    True        True        True       True        True   True  1898.7   8107.000  1654.00       0.983524    58.26700    68.31100
7   Mouse17-130129  Mouse17       43     35      0                                                   Field CA1    True        True        True       True        True   True  3373.0   9754.000  1699.00       0.977641    59.18700    68.86800
8   Mouse17-130130  Mouse17       37     29      0                                                   Field CA1    True        True        True       True        True   True  2053.8   9403.000  1767.00       0.945492    59.27500    70.50100
9   Mouse17-130131  Mouse17       33     27      0                                                   Field CA1    True        True        True       True        True   True  2403.9   9846.000  1553.10       0.989670    64.69800    55.89000
10  Mouse17-130201  Mouse17       37     34      0                                                   Field CA1    True        True        True       True        True   True  2023.6   8188.000  1535.00       0.995117    68.07200    57.36800
11  Mouse17-130202  Mouse17       39     34      0                                                   Field CA1    True        True        True       True        True   True  1801.9   8552.000  1492.00       0.998068    69.17800    57.84900
12  Mouse17-130203  Mouse17       41     34      0                                                   Field CA1    True        True        True       True        True   True  2439.9  10062.000  1553.00       0.994901    60.16300    69.02100
13  Mouse17-130204  Mouse17       34     27      0                                                   Field CA1    True        True        True       True        True   True  1843.1  10393.000  1877.00       0.996028    60.49200    69.16100
14  Mouse20-130514  Mouse20        8      6      2                                                                True        True        True       True        True   True  1884.1   7323.000  1350.00       0.996168    59.99300    72.42300
15  Mouse20-130515  Mouse20        9      7      2                                                                True        True        True       True        True   True  1907.5  11222.000  2405.00       0.995960    67.95700    58.14400
16  Mouse20-130516  Mouse20       10      9      0                                                     unknown    True        True        True       True        True   True  1895.6   9222.000  1985.00       0.995165    69.11900    59.04500
17  Mouse20-130517  Mouse20       18     16      0                                                     unknown    True        True        True       True        True   True  1846.5   9456.000  2152.00       0.998198    58.77100    72.43710
18  Mouse20-130520  Mouse20       18     10      4                                           Field CA1;unknown    True        True        True       True        True   True  1811.7   9162.900  1604.00       0.998022    64.29600    57.21200
19  Mouse24-131213  Mouse24       14      5      9                                                                True        True        True      False        True   True  1487.6   5157.000   936.00       0.998331    66.13100    61.03200
20  Mouse24-131216  Mouse24       26     10     13                                                     unknown    True        True        True       True        True   True  1593.2   9323.700  1914.00       0.998972    69.68100    60.84700
21  Mouse24-131217  Mouse24       25     10     13                                                     unknown    True        True        True       True        True   True  1801.2   9966.000  1724.00       0.998280    58.86000    67.62400
22  Mouse24-131218  Mouse24       29     12     13                                                     unknown    True        True        True       True        True   True  1640.8   9300.200  1616.00       0.999953    67.22500    57.53300
23  Mouse25-140123  Mouse25       26      7     19                                                                True        True        True       True        True   True  2109.5  11901.000  1501.00       0.998920    66.88800    65.37300
24  Mouse25-140124  Mouse25       22      6     16                                                                True        True        True       True        True   True  1713.5  12603.000  1398.00       0.992485    73.30500    68.47120
25  Mouse25-140128  Mouse25       19      4     15                                                                True        True        True       True        True   True  1814.2  12911.000  1510.00       0.978241    83.86600    69.98100
26  Mouse25-140129  Mouse25       20      1     19                                                                True        True        True       True        True   True  1254.5  12927.000  1575.00       0.983430    87.86700    82.96460
27  Mouse25-140130  Mouse25       25     10     15                                                                True        True        True       True        True   True  1876.8  11480.000  1468.00       0.999795    68.88000    71.57300
28  Mouse25-140131  Mouse25       26      9     17                                                                True       False        True       True        True   True     NaN        NaN      NaN            NaN         NaN         NaN
29  Mouse25-140203  Mouse25       18     10      8                                                                True        True        True       True        True   True  1901.3  10919.000  1168.00       0.998829    85.37200    69.21900
30  Mouse25-140204  Mouse25       26     10     12                                                     unknown    True       False        True       True        True   True     NaN        NaN      NaN            NaN         NaN         NaN
31  Mouse25-140205  Mouse25       24      9      9                                                     unknown    True        True        True       True        True   True  1784.9   9030.000  1113.00       0.977138    80.98900    77.61000
32  Mouse25-140206  Mouse25       15      9      5                                                     unknown    True        True        True       True        True   True  1846.9   9992.000  1168.00       0.981773    84.57800    75.09100
33  Mouse28-140310  Mouse28       36     11     15                                                     unknown    True        True        True       True        True   True  1622.3  10591.000  1056.00       0.994903    60.90600    63.16390
34  Mouse28-140311  Mouse28       43     12     13                                                     unknown    True        True        True       True        True   True  1807.1  13712.000   543.00       0.986514    60.21000    65.72570
35  Mouse28-140312  Mouse28       61     18     42                                                     unknown    True        True        True       True        True   True  2023.8  16610.000  1138.00       0.996914    61.21300    67.06320
36  Mouse28-140313  Mouse28       62     22     38                                                     unknown    True        True        True       True        True   True  2286.4  11216.000  1389.00       0.999037    57.73400    63.34780
37  Mouse28-140314  Mouse28       53     21     28                                                     unknown   False       False        True       True        True  False     NaN        NaN      NaN            NaN         NaN         NaN
38  Mouse28-140317  Mouse28       43     20     18                                                     unknown    True        True        True       True        True   True  1747.9  11977.000   350.00       0.938969    64.33500    67.79370
39  Mouse28-140318  Mouse28       48     22     20                                                     unknown    True        True        True       True        True   True  2023.8  11155.000   815.00       0.918070    61.95800    65.20860
40  Mouse32-140820  Mouse32       56     56      0                                                               False       False       False      False       False   True     NaN        NaN      NaN            NaN         NaN         NaN
41  Mouse32-140822  Mouse32       53     49      0                                                   Field CA1   False       False        True       True        True  False     NaN        NaN      NaN            NaN         NaN         NaN

sessions 42 | mice 7 | units 1682 | ADn units 853 | PoS units 365
units per mouse and region:
         n_units  n_adn  n_pos
subject                       
Mouse12      548    217      0
Mouse17      301    245      0
Mouse20       63     48      8
Mouse24       94     37     48
Mouse25      221     75    135
Mouse28      346    126    174
Mouse32      109    105      0

sessions without head direction: ['Mouse28-140314', 'Mouse32-140820', 'Mouse32-140822']
sessions without the paper's sleep scoring: ['Mouse25-140131', 'Mouse25-140204', 'Mouse28-140314', 'Mouse32-140820', 'Mouse32-140822']
sessions without LFP: ['Mouse28-140314', 'Mouse32-140822']
spike times sorted in every unit of every session: True
first spike >= 0 s: True | sessions with spikes after the last sub-recording: ['Mouse17-130130'] [1101.1]
head direction: [39.0625] Hz, range 0.0000 to 6.2832 rad; valid (both LEDs) in wake 0.918 to 1.000
head direction = LED (red minus blue) angle minus a fixed offset: resultant length of the difference 0.99828 to 1.00000; offsets (deg) by mouse:
subject
Mouse12         [270.0]
Mouse17         [270.0]
Mouse20         [270.0]
Mouse24         [270.0]
Mouse25    [0.0, 360.0]
Mouse28         [180.0]
head-direction samples minus position samples: {0.0: 38, 1.0: 1}
wake extent of the red LED: x 57.7 to 129.9 cm, y 55.2 to 97.4 cm (arena 53 x 46 cm, paper)
wake (open field) min: {'min': 20.9, '50%': 31.3, 'max': 56.2}
SWS and REM periods inside the home-cage epochs (fraction): 1.0 1.0
scored wake interval against the open-field epochs, 37 sessions with both: fraction of wake inside the open field 0.9998 to 1.0000; fraction of the open field inside wake 0.9998 to 1.0000
sessions with an open field but no scored wake (open field used as wake): ['Mouse25-140131', 'Mouse25-140204', 'Mouse28-140314', 'Mouse32-140822']

sessions with a device named postsubicular_probe, by mouse: {'Mouse12': 0, 'Mouse17': 0, 'Mouse20': 5, 'Mouse24': 4, 'Mouse25': 10, 'Mouse28': 7, 'Mouse32': 0}
electrode groups of the units labelled PoS in Mouse20:
  Mouse20-130514 2 units | group10: anatomical channel group 10 of the session's .xml file: the lab labels this group 'postsub
  Mouse20-130515 2 units | group10: anatomical channel group 10 of the session's .xml file: the lab labels this group 'postsub
  Mouse20-130520 4 units | group10: anatomical channel group 10 of the session's .xml file: the lab labels this group 'postsub;group9: anatomical channel group 9 of the session's .xml file: the lab labels this group 'postsub'
In [5]:
# Clock check (protocol, data check): waking decoding error with the head
# direction shifted in time. If spikes and head direction share a clock, the
# error is smallest at 0 s.
piv = SHIFT.pivot_table(index=["session", "region"], columns="shift_s", values="err")
print(piv.round(1).to_string())
best = piv.idxmin(axis=1)
print("\nshift with the smallest error, count of ensembles:", best.value_counts().to_dict())
print("median error over ensembles by shift (deg):", piv.median().round(1).to_dict())
shift_s                -10.0  -2.0   -0.5    0.0    0.5    2.0    10.0
session        region                                                 
Mouse12-120806 ADn      88.2   44.0   18.8   12.2   19.2   40.8   85.5
Mouse12-120807 ADn      68.5   36.8   16.6   10.6   17.2   35.9   66.2
Mouse12-120808 ADn      70.7   29.6   13.6    7.9   12.4   29.0   77.2
Mouse12-120809 ADn      90.4   46.0   18.8    9.5   18.3   43.8   88.1
Mouse12-120810 ADn      90.5   42.0   17.7   11.8   21.6   43.5   91.0
Mouse17-130129 ADn      95.1   40.2   14.9   11.0   20.9   44.1   97.4
Mouse17-130130 ADn      87.5   35.0   12.8   11.7   20.7   41.7   91.6
Mouse17-130131 ADn      91.7   42.5   16.5   13.0   23.1   46.3   94.9
Mouse17-130201 ADn      97.8   45.0   17.9   12.0   21.5   48.5   96.8
Mouse20-130517 ADn      76.0   38.7   17.3   11.4   18.8   38.5   77.3
Mouse24-131216 ADn     101.9   44.6   15.9   13.1   26.1   53.5  102.0
Mouse24-131217 ADn      94.2   45.9   18.5   10.5   19.2   44.6   92.3
Mouse24-131218 ADn      99.3   45.6   16.2    9.6   19.6   47.4  100.5
Mouse25-140123 PoS      62.8   31.5   17.5   13.6   17.6   29.1   60.1
Mouse25-140130 ADn      83.2   37.1   14.5    8.2   13.9   36.6   82.3
Mouse25-140131 ADn      88.1   42.8   16.6    9.4   16.5   41.1   89.0
               PoS      89.4   48.9   21.0   14.4   22.9   49.5   89.3
Mouse25-140203 ADn      75.3   36.8   13.2    8.9   16.8   38.2   75.1
Mouse25-140204 ADn      80.1   38.8   15.4    9.1   15.9   35.8   78.0
Mouse25-140205 ADn      74.9   33.3   14.4    9.6   15.0   32.6   76.5
Mouse25-140206 ADn      75.2   33.9   13.7    9.3   15.4   33.8   72.5
Mouse28-140310 ADn      36.1   21.9   13.7    9.5   12.4   20.4   33.3
               PoS      46.2   38.0   28.7   25.1   29.0   36.5   47.7
Mouse28-140311 ADn      64.7   35.9   16.9    9.7   14.6   33.1   63.2
Mouse28-140312 ADn      56.8   32.4   16.2   10.2   14.6   29.2   55.8
               PoS      69.1   46.6   28.7   23.3   29.2   47.5   67.5
Mouse28-140313 ADn      60.8   35.1   15.5   10.1   16.4   33.2   59.8
               PoS      64.9   40.0   17.5   13.2   20.5   38.4   63.1
Mouse28-140317 ADn      54.7   30.9   17.2   12.2   17.0   28.9   51.1
Mouse28-140318 ADn      42.4   26.4   16.2   11.7   15.0   24.8   41.8

shift with the smallest error, count of ensembles: {0.0: 30}
median error over ensembles by shift (deg): {-10.0: 75.7, -2.0: 38.4, -0.5: 16.6, 0.0: 10.8, 0.5: 18.0, 2.0: 38.3, 10.0: 77.2}
In [6]:
# Per-cell table: what the analysis uses.
print(CELLS.groupby(["subject", "region"]).size().unstack().to_string())
for k in ["rate_wake", "rate_SWS", "rate_REM", "peak_a", "kappa_a", "info", "dur_ms", "t2p_ms"]:
    v = CELLS[k].replace([np.inf, -np.inf], np.nan)
    print(f"{k}: n {v.notna().sum()}, range {v.min():.3g} to {v.max():.3g}, median {v.median():.3g}")
print("classifiable cells (sessions with head direction):", len(CELLS))
print("agreement of HD reading (hd-a) with the file's is_hd_cell column:")
print(pd.crosstab(CELLS.hd_a, CELLS.lab_hd, rownames=["hd_a"], colnames=["file is_hd_cell"]))
print(pd.crosstab(CELLS.hd_b, CELLS.lab_hd, rownames=["hd_b"], colnames=["file is_hd_cell"]))
print("PoS cell classes from the waveform:", CELLS[CELLS.region == "PoS"].cls.value_counts().to_dict())
region     ADn    PoS
subject              
Mouse12  217.0    NaN
Mouse17  245.0    NaN
Mouse20   48.0    8.0
Mouse24   37.0   48.0
Mouse25   75.0  135.0
Mouse28  105.0  146.0
rate_wake: n 1064, range 0.000593 to 139, median 3.11
rate_SWS: n 1016, range 0 to 97, median 2.59
rate_REM: n 1016, range 0 to 96.9, median 2.92
peak_a: n 1064, range 0.0131 to 182, median 8.45
kappa_a: n 1064, range 0.00994 to 86.6, median 0.325
info: n 1064, range -4.25 to 3.24, median 0.0318
dur_ms: n 1064, range 0.279 to 5, median 0.8
t2p_ms: n 1064, range 0.11 to 0.744, median 0.366
classifiable cells (sessions with head direction): 1064
agreement of HD reading (hd-a) with the file's is_hd_cell column:
file is_hd_cell  False  True 
hd_a                         
False              650     39
True                18    357
file is_hd_cell  False  True 
hd_b                         
False              620     12
True                48    384
PoS cell classes from the waveform: {'pyr': 177, 'und': 93, 'int': 67}

The session rule of the Methods¶

"To prevent statistical bias of neuron sampling, we discarded from analysis sessions separated by less than three days during which the thalamic probe was not moved" (Methods, Electrodes). The files give the thalamic probe depth of each session (device description, from the CRCNS table). hd.thalamic_rule keeps a session when the depth changed since the last kept session or three days have passed. Supplementary Table 1 counts ADn cells from 2, 3 and 3 sessions in Mouse24, 25 and 28, and PoS cells from all of their 4, 10 and 7. The rule is shown as a variant of the cell counts; the main analysis uses every session, as the files do not say which sessions the paper kept.

In [7]:
import re as _re
deps = []
for o in RES:
    deps.append((o["summary"]["session"], o["summary"].get("thal_depth")))
rule = hd.thalamic_rule(deps)
SUM["thal_depth"] = [d for _, d in deps]
SUM["rule_keep"] = SUM.session.map(rule)
print(SUM[["session", "thal_depth", "rule_keep"]].to_string())
print(SUM.groupby("subject").rule_keep.sum().to_dict())
CELLS["rule_keep"] = CELLS.session.map(rule)
           session  thal_depth  rule_keep
0   Mouse12-120806        2.97       True
1   Mouse12-120807        3.04       True
2   Mouse12-120808        3.11       True
3   Mouse12-120809        3.18       True
4   Mouse12-120810        3.25       True
5   Mouse17-130125        2.71       True
6   Mouse17-130128        2.78       True
7   Mouse17-130129        2.85       True
8   Mouse17-130130        2.92       True
9   Mouse17-130131        2.99       True
10  Mouse17-130201        2.99      False
11  Mouse17-130202        3.06       True
12  Mouse17-130203        3.13       True
13  Mouse17-130204        3.20       True
14  Mouse20-130514        3.28       True
15  Mouse20-130515        3.42       True
16  Mouse20-130516        3.49       True
17  Mouse20-130517        3.63       True
18  Mouse20-130520        3.77       True
19  Mouse24-131213        3.04       True
20  Mouse24-131216        3.11       True
21  Mouse24-131217        3.11      False
22  Mouse24-131218        3.18       True
23  Mouse25-140123        2.51       True
24  Mouse25-140124        2.58       True
25  Mouse25-140128        2.58       True
26  Mouse25-140129        2.72       True
27  Mouse25-140130        2.72      False
28  Mouse25-140131        2.72      False
29  Mouse25-140203        2.72       True
30  Mouse25-140204        2.72      False
31  Mouse25-140205        2.72      False
32  Mouse25-140206        2.72       True
33  Mouse28-140310        2.56       True
34  Mouse28-140311        2.56      False
35  Mouse28-140312        2.56      False
36  Mouse28-140313        2.56       True
37  Mouse28-140314        2.56      False
38  Mouse28-140317        2.56       True
39  Mouse28-140318        2.56      False
40  Mouse32-140820         NaN       True
41  Mouse32-140822        3.01       True
{'Mouse12': 5, 'Mouse17': 8, 'Mouse20': 5, 'Mouse24': 3, 'Mouse25': 6, 'Mouse28': 3, 'Mouse32': 2}

recording-sample¶

HD cell ensembles were recorded in 7 mice over 42 open-field sessions with home-cage sleep, with ADn and PoS recorded simultaneously in 3 mice over 21 sessions.

Readings (criterion): (a) all sessions, (b) sessions with sleep before and after the open field.

In [8]:
s_open = SUM[SUM.open_field & (SUM.n_units > 0)]
s_sleep = s_open[s_open.sleep_pre & s_open.sleep_post]
print("sessions in the dandiset:", len(SUM), "| mice:", SUM.subject.nunique())
print("without an open-field epoch:", list(SUM.session[~SUM.open_field]))
rows = []
for rd, sel in (("(a) open field and spikes", s_open), ("(b) and sleep before and after", s_sleep)):
    both = sel[(sel.n_adn > 0) & (sel.n_pos > 0)]
    both_p = sel[sel.subject.isin(DUAL)]
    rows.append(dict(reading=rd, mice=sel.subject.nunique(), sessions=len(sel),
                     both_sessions_labels=len(both), both_mice_labels=both.subject.nunique(),
                     both_sessions_paper_list=len(both_p), both_mice_paper_list=both_p.subject.nunique()))
print(pd.DataFrame(rows).to_string(index=False))
print("expected: 7 mice (exact), 42 sessions (+-4.2), 21 sessions with both (+-2.1), 3 mice with both (exact)")
print("sessions per mouse:", SUM.groupby("subject").size().to_dict())
both_lab = s_open[(s_open.n_adn > 0) & (s_open.n_pos > 0)]
print("sessions with units of both labels, by mouse (a):", both_lab.groupby("subject").size().to_dict())
print("sessions without sleep before and after:", list(s_open.session[~(s_open.sleep_pre & s_open.sleep_post)]))
sessions in the dandiset: 42 | mice: 7
without an open-field epoch: ['Mouse32-140820']
                       reading  mice  sessions  both_sessions_labels  both_mice_labels  both_sessions_paper_list  both_mice_paper_list
     (a) open field and spikes     7        41                    24                 4                        21                     3
(b) and sleep before and after     7        40                    23                 4                        20                     3
expected: 7 mice (exact), 42 sessions (+-4.2), 21 sessions with both (+-2.1), 3 mice with both (exact)
sessions per mouse: {'Mouse12': 5, 'Mouse17': 9, 'Mouse20': 5, 'Mouse24': 4, 'Mouse25': 10, 'Mouse28': 7, 'Mouse32': 2}
sessions with units of both labels, by mouse (a): {'Mouse20': 3, 'Mouse24': 4, 'Mouse25': 10, 'Mouse28': 7}
sessions without sleep before and after: ['Mouse24-131213']

Result: partially reproduced. Under reading (a), the dandiset holds 7 mice and 41 sessions with an open-field epoch and spikes (Mouse32-140820 has no epochs), both within tolerance. By the files' labels, 24 of these sessions in 4 mice hold units of both structures, against 21 sessions (tolerance 2.1) in 3 mice: Mouse20 has PoS units in 3 sessions. Under reading (b) (40 sessions with sleep before and after) the counts are 23 sessions in 4 mice; the session count is then within tolerance, the mouse count is not. Only with the paper's own list of three mice (a variant from Supplementary Table 1, not from the data) are the counts 21 and 3. The table's 50 sessions are not matched.

Head-direction cells: supptable1-per-animal, hd-cell-fraction, hd-fraction-hd-shanks, ensemble-sizes¶

HD cells as in the claims file's opening comment: tuning curve in 1 degree bins smoothed with a 6 degree s.d. Gaussian in waking (the open-field epoch), frames with either LED missing excluded; von Mises concentration > 1, peak rate > 1 Hz, Rayleigh p < 0.001; readings (hd-a) and (hd-b) (hd.vm_fit_a, hd.vm_fit_b). Cells of sessions without head direction (Mouse28-140314, both Mouse32 sessions) cannot be classified.

In [9]:
EXP_ADN = dict(Mouse12=63, Mouse17=52, Mouse20=15, Mouse24=17, Mouse25=23, Mouse28=37, Mouse32=35)
EXP_POS = dict(Mouse24=9, Mouse25=53, Mouse28=49)
REC_ADN = dict(Mouse12=217, Mouse17=245, Mouse20=49, Mouse24=22, Mouse25=27, Mouse28=55, Mouse32=105)
REC_POS = dict(Mouse24=48, Mouse25=135, Mouse28=174)
rec_units = SUM.groupby("subject")[["n_adn", "n_pos"]].sum()
rec_rule = SUM[SUM.rule_keep.fillna(True).astype(bool)].groupby("subject")[["n_adn"]].sum()
testable = set(SUM[SUM.has_hd].subject)
def table(sel, label):
    rows = []
    for reg, exp in (("ADn", EXP_ADN), ("PoS", EXP_POS)):
        for m, v in exp.items():
            na = int(sel[(sel.subject == m) & (sel.region == reg)].hd_a.sum())
            nb = int(sel[(sel.subject == m) & (sel.region == reg)].hd_b.sum())
            nl = int(sel[(sel.subject == m) & (sel.region == reg)].lab_hd.fillna(False).astype(bool).sum())
            rows.append(dict(region=reg, mouse=m, expected=v, testable=m in testable, hd_a=na, hd_b=nb, file_is_hd=nl,
                             within_a=abs(na - v) <= 0.1 * v, within_b=abs(nb - v) <= 0.1 * v))
    T = pd.DataFrame(rows)
    print(label)
    print(T.to_string(index=False))
    print("within tolerance: hd-a", int(T.within_a.sum()), "of 10; hd-b", int(T.within_b.sum()), "of 10;",
          int(T.testable.sum()), "counts testable (no head direction in any session of",
          sorted(set(EXP_ADN) - testable), ")")
    return T
T_all = table(CELLS, "all sessions")
T_rule = table(CELLS[(CELLS.region == "PoS") | CELLS.rule_keep.astype(bool)], "\nADn cells from sessions kept by the session rule (variant)")
print("\nrecorded units per mouse (dandiset, all sessions) against Supplementary Table 1:")
print(pd.DataFrame(dict(ADn=rec_units.n_adn, ADn_table=pd.Series(REC_ADN), ADn_rule=rec_rule.n_adn,
                        PoS=rec_units.n_pos, PoS_table=pd.Series(REC_POS))).to_string())
all sessions
region   mouse  expected  testable  hd_a  hd_b  file_is_hd  within_a  within_b
   ADn Mouse12        63      True    66    66          63      True      True
   ADn Mouse17        52      True    51    54          52      True      True
   ADn Mouse20        15      True    14    16          15      True      True
   ADn Mouse24        17      True    26    29          26     False     False
   ADn Mouse25        23      True    62    65          63     False     False
   ADn Mouse28        37      True    74    82          74     False     False
   ADn Mouse32        35     False     0     0           0     False     False
   PoS Mouse24         9      True     7     9           9     False      True
   PoS Mouse25        53      True    41    63          53     False     False
   PoS Mouse28        49      True    34    48          41     False      True
within tolerance: hd-a 3 of 10; hd-b 5 of 10; 9 counts testable (no head direction in any session of ['Mouse32'] )

ADn cells from sessions kept by the session rule (variant)
region   mouse  expected  testable  hd_a  hd_b  file_is_hd  within_a  within_b
   ADn Mouse12        63      True    66    66          63      True      True
   ADn Mouse17        52      True    45    48          46     False      True
   ADn Mouse20        15      True    14    16          15      True      True
   ADn Mouse24        17      True    18    20          18      True     False
   ADn Mouse25        23      True    27    29          28     False     False
   ADn Mouse28        37      True    37    41          38      True     False
   ADn Mouse32        35     False     0     0           0     False     False
   PoS Mouse24         9      True     7     9           9     False      True
   PoS Mouse25        53      True    41    63          53     False     False
   PoS Mouse28        49      True    34    48          41     False      True
within tolerance: hd-a 4 of 10; hd-b 5 of 10; 9 counts testable (no head direction in any session of ['Mouse32'] )

recorded units per mouse (dandiset, all sessions) against Supplementary Table 1:
         ADn  ADn_table  ADn_rule  PoS  PoS_table
Mouse12  217        217       217    0        NaN
Mouse17  245        245       211    0        NaN
Mouse20   48         49        48    8        NaN
Mouse24   37         22        27   48       48.0
Mouse25   75         27        37  135      135.0
Mouse28  126         55        53  174      174.0
Mouse32  105        105       105    0        NaN

Result: partially reproduced. Under reading (hd-b), 5 of the 10 HD counts are within tolerance, and under (hd-a) 3. The session-rule variant gives 5 under (hd-b) and 4 under (hd-a). Mouse32's count (35) cannot be tested: neither of its sessions holds head direction, so 9 of the 10 counts are testable and its 0 is not a measurement. The outcome would be the same with Mouse32 left out: 5 of the 9 testable counts are within tolerance under (hd-b), and a passing Mouse32 would make 6. Over all sessions the dual mice have more ADn HD cells (26, 62 and 74 under hd-a, against 17, 23 and 37), as Supplementary Table 1 counts their ADn cells from a subset of sessions. Recorded units equal the table in Mouse12, Mouse17 and Mouse32 (217, 245, 105), Mouse20 has 48 against 49, and the PoS counts match (48, 135, 174).

In [10]:
def fractions(sel, rd):
    out = {}
    for reg, key in (("ADn", "thal"), ("PoS", "pos")):
        c = sel[sel.region == reg]
        out[key + "_hd"] = int(c["hd_" + rd].sum())
        out[key + "_rec"] = len(c)
        ps = c.groupby("session")["hd_" + rd].mean()
        pm = c.groupby("subject")["hd_" + rd].mean()
        out[key + "_frac_sessions"] = ps.mean()
        out[key + "_frac_mice"] = pm.mean()
        out[key + "_frac_pooled"] = c["hd_" + rd].mean()
    return out
rows = []
for lab, sel in (("all sessions", CELLS), ("session rule", CELLS[(CELLS.region == "PoS") | CELLS.rule_keep.astype(bool)])):
    for rd in ("a", "b"):
        r = fractions(sel, rd); r.update(sample=lab, reading=rd); rows.append(r)
F = pd.DataFrame(rows)
print(F.round(3).to_string(index=False))
print("expected: thalamic 242 of 720, 41% on average; PoS 111 of 357, 31%")
print("recorded ADn units including sessions without head direction:", int(SUM.n_adn.sum()),
      "| PoS:", int(SUM.n_pos.sum()), "| of these classifiable:", int((CELLS.region == "ADn").sum()), int((CELLS.region == "PoS").sum()))
print("recorded units in the dual mice under the session rule (ADn):", int(SUM[SUM.rule_keep.fillna(True).astype(bool)].n_adn.sum()))
 thal_hd  thal_rec  thal_frac_sessions  thal_frac_mice  thal_frac_pooled  pos_hd  pos_rec  pos_frac_sessions  pos_frac_mice  pos_frac_pooled       sample reading
     293       727               0.528           0.506             0.403      82      337              0.215          0.171            0.243 all sessions       a
     312       727               0.572           0.548             0.429     120      337              0.331          0.246            0.356 all sessions       b
     207       593               0.458           0.484             0.349      82      337              0.215          0.171            0.243 session rule       a
     220       593               0.499           0.527             0.371     120      337              0.331          0.246            0.356 session rule       b
expected: thalamic 242 of 720, 41% on average; PoS 111 of 357, 31%
recorded ADn units including sessions without head direction: 853 | PoS: 365 | of these classifiable: 727 337
recorded units in the dual mice under the session rule (ADn): 698

Result: not reproduced. No combination of readings puts all four counts within tolerance. Over all sessions, reading (hd-a) gives 293 thalamic HD cells of 727 classifiable thalamic cells, and 82 PoS HD cells of 337. Reading (hd-b) gives 312 and 120. The per-session mean fractions are 0.53 and 0.22 (hd-a), and 0.57 and 0.33 (hd-b). The PoS counts (337 classifiable, 365 units), the hd-b PoS HD count (120) and the hd-b per-session PoS fraction (0.33) are within tolerance. The thalamic HD counts exceed 242 because the dual mice add sessions the paper did not count; under the session rule they are 207 and 220 of 593.

In [11]:
rows = []
for rd in ("a", "b"):
    a = CELLS[CELLS.region == "ADn"].groupby(["session", "shank"])["hd_" + rd].agg(["sum", "count"])
    a = a[a["sum"] > 0]
    rows.append(dict(reading=rd, shank_sessions=len(a), mean_of_shanks=(a["sum"] / a["count"]).mean(),
                     pooled=a["sum"].sum() / a["count"].sum()))
print(pd.DataFrame(rows).round(3).to_string(index=False), "\nexpected 0.71 (tolerance 0.071)")
reading  shank_sessions  mean_of_shanks  pooled
      a              63           0.733   0.736
      b              63           0.799   0.784 
expected 0.71 (tolerance 0.071)

Result: reproduced. On 63 thalamic shank-sessions with at least one HD cell, the mean HD fraction is 0.733 under (hd-a) and the pooled fraction 0.736, both within 0.639 to 0.781. Under (hd-b) they are 0.799 and 0.784, outside the tolerance.

In [12]:
rows = []
for rd in ("a", "b"):
    for m20 in ("with Mouse20", "without Mouse20"):
        for reg in ("ADn", "PoS"):
            c = CELLS[CELLS.region == reg]
            if m20 == "without Mouse20":
                if reg == "ADn":
                    continue  # Mouse20's ADn cells are in the paper's sample either way
                c = c[c.subject != "Mouse20"]
            per = c.groupby("session")["hd_" + rd].sum()
            for lab, p in (("(a) sessions with the structure", per), ("(b) sessions with >= 1 HD cell", per[per > 0]),
                           ("(c) sessions with >= 6 HD cells (decoding rule)", per[per >= 6])):
                mean, sd = p.mean(), p.std(ddof=1)
                exp_m, exp_s = (8.4, 5.1) if reg == "ADn" else (5.0, 2.8)
                rows.append(dict(hd=rd, pos_sample=m20 if reg == "PoS" else "", region=reg, reading=lab, n=len(p),
                                 mean=mean, sd=sd, mean_ok=abs(mean - exp_m) <= 0.1 * exp_m, sd_ok=abs(sd - exp_s) <= 0.1 * exp_s))
ES = pd.DataFrame(rows)
print(ES.round(2).to_string(index=False))
print("expected ADn 8.4 +- 5.1 s.d., PoS 5 +- 2.8 s.d.; tolerance 10% of each value")
best = []
for rd in ("a", "b"):
    for smp in ("with Mouse20", "without Mouse20"):
        for lab in ES.reading.unique():
            a = ES[(ES.hd == rd) & (ES.region == "ADn") & (ES.reading == lab)].iloc[0]
            p = ES[(ES.hd == rd) & (ES.region == "PoS") & (ES.pos_sample == smp) & (ES.reading == lab)].iloc[0]
            best.append(dict(hd=rd, pos_sample=smp, reading=lab, both_means=a.mean_ok & p.mean_ok,
                             all_four=a.mean_ok & p.mean_ok & a.sd_ok & p.sd_ok))
print(pd.DataFrame(best).to_string(index=False))
print("by mouse (ADn, hd-a / hd-b):", CELLS[CELLS.region == "ADn"].groupby(["subject", "session"])[["hd_a", "hd_b"]].sum()
      .groupby("subject").mean().round(1).to_dict())
hd      pos_sample region                                         reading  n  mean   sd  mean_ok  sd_ok
 a                    ADn                 (a) sessions with the structure 39  7.51 4.39    False  False
 a                    ADn                  (b) sessions with >= 1 HD cell 39  7.51 4.39    False  False
 a                    ADn (c) sessions with >= 6 HD cells (decoding rule) 25 10.04 3.27    False  False
 a    with Mouse20    PoS                 (a) sessions with the structure 23  3.57 2.97    False   True
 a    with Mouse20    PoS                  (b) sessions with >= 1 HD cell 20  4.10 2.81    False   True
 a    with Mouse20    PoS (c) sessions with >= 6 HD cells (decoding rule)  5  8.20 1.48    False  False
 a without Mouse20    PoS                 (a) sessions with the structure 20  4.10 2.81    False   True
 a without Mouse20    PoS                  (b) sessions with >= 1 HD cell 20  4.10 2.81    False   True
 a without Mouse20    PoS (c) sessions with >= 6 HD cells (decoding rule)  5  8.20 1.48    False  False
 b                    ADn                 (a) sessions with the structure 39  8.00 4.42     True  False
 b                    ADn                  (b) sessions with >= 1 HD cell 39  8.00 4.42     True  False
 b                    ADn (c) sessions with >= 6 HD cells (decoding rule) 27 10.19 3.41    False  False
 b    with Mouse20    PoS                 (a) sessions with the structure 23  5.22 4.11     True  False
 b    with Mouse20    PoS                  (b) sessions with >= 1 HD cell 20  6.00 3.83    False  False
 b    with Mouse20    PoS (c) sessions with >= 6 HD cells (decoding rule) 11  8.64 3.04    False   True
 b without Mouse20    PoS                 (a) sessions with the structure 20  6.00 3.83    False  False
 b without Mouse20    PoS                  (b) sessions with >= 1 HD cell 20  6.00 3.83    False  False
 b without Mouse20    PoS (c) sessions with >= 6 HD cells (decoding rule) 11  8.64 3.04    False   True
expected ADn 8.4 +- 5.1 s.d., PoS 5 +- 2.8 s.d.; tolerance 10% of each value
hd      pos_sample                                         reading  both_means  all_four
 a    with Mouse20                 (a) sessions with the structure       False     False
 a    with Mouse20                  (b) sessions with >= 1 HD cell       False     False
 a    with Mouse20 (c) sessions with >= 6 HD cells (decoding rule)       False     False
 a without Mouse20                 (a) sessions with the structure       False     False
 a without Mouse20                  (b) sessions with >= 1 HD cell       False     False
 a without Mouse20 (c) sessions with >= 6 HD cells (decoding rule)       False     False
 b    with Mouse20                 (a) sessions with the structure        True     False
 b    with Mouse20                  (b) sessions with >= 1 HD cell       False     False
 b    with Mouse20 (c) sessions with >= 6 HD cells (decoding rule)       False     False
 b without Mouse20                 (a) sessions with the structure       False     False
 b without Mouse20                  (b) sessions with >= 1 HD cell       False     False
 b without Mouse20 (c) sessions with >= 6 HD cells (decoding rule)       False     False
by mouse (ADn, hd-a / hd-b): {'hd_a': {'Mouse12': 13.2, 'Mouse17': 5.7, 'Mouse20': 2.8, 'Mouse24': 6.5, 'Mouse25': 6.2, 'Mouse28': 12.3}, 'hd_b': {'Mouse12': 13.2, 'Mouse17': 6.0, 'Mouse20': 3.2, 'Mouse24': 7.2, 'Mouse25': 6.5, 'Mouse28': 13.7}}

Result: partially reproduced. Under reading (hd-b) with reading (a), both means are within tolerance: ADn HD cells per session are 8.00 over 39 sessions (7.56 to 9.24) and PoS HD cells 5.22 over 23 sessions (4.5 to 5.5). The s.d. are not: 4.42 against 5.1 plus or minus 0.51, and 4.11 against 2.8 plus or minus 0.28. No other combination puts both means within tolerance. The PoS mean rests on the 3 Mouse20 sessions with PoS units (no HD cells among them): without them it is 6.00 over 20 sessions, outside. Under (hd-a), the means are 7.51 and 3.57 (a), 7.51 and 4.10 (b), 10.04 and 8.20 (c).

In [13]:
sl = SUM[SUM.has_states & SUM.sleep_pre | SUM.has_states & SUM.sleep_post].copy()
sl["homecage_h"] = sl.homecage_s / 3600
sl["scored_h"] = (sl.SWS_s + sl.REM_s) / 3600
print(sl[["session", "homecage_h", "scored_h"]].round(2).to_string(index=False))
for k in ("homecage_h", "scored_h"):
    print(f"{k}: n {len(sl)}, mean {sl[k].mean():.2f} h, s.d. {sl[k].std(ddof=1):.2f} h")
print("expected 5 +- 1 s.d. h (tolerance 0.5 and 0.1)")
print("by mouse (home cage, h):", sl.groupby("subject").homecage_h.mean().round(2).to_dict())
       session  homecage_h  scored_h
Mouse12-120806        3.79      2.31
Mouse12-120807        3.68      2.66
Mouse12-120808        4.38      2.65
Mouse12-120809        4.59      3.22
Mouse12-120810        3.67      2.85
Mouse17-130125        5.48      3.08
Mouse17-130128        4.70      2.71
Mouse17-130129        5.52      3.18
Mouse17-130130        5.14      3.10
Mouse17-130131        5.52      3.17
Mouse17-130201        4.29      2.70
Mouse17-130202        5.37      2.79
Mouse17-130203        5.65      3.23
Mouse17-130204        5.91      3.41
Mouse20-130514        3.61      2.41
Mouse20-130515        5.40      3.79
Mouse20-130516        4.69      3.11
Mouse20-130517        4.69      3.22
Mouse20-130520        4.87      2.99
Mouse24-131213        2.57      1.69
Mouse24-131216        4.78      3.12
Mouse24-131217        4.31      3.25
Mouse24-131218        4.61      3.03
Mouse25-140123        4.31      3.72
Mouse25-140124        5.13      3.89
Mouse25-140128        5.27      4.01
Mouse25-140129        5.61      4.03
Mouse25-140130        5.43      3.60
Mouse25-140203        4.88      3.36
Mouse25-140205        4.22      2.82
Mouse25-140206        4.78      3.10
Mouse28-140310        4.95      3.24
Mouse28-140311        6.13      3.96
Mouse28-140312        7.92      4.93
Mouse28-140313        6.77      3.50
Mouse28-140317        6.21      3.42
Mouse28-140318        5.64      3.32
homecage_h: n 37, mean 4.99 h, s.d. 0.97 h
scored_h: n 37, mean 3.20 h, s.d. 0.57 h
expected 5 +- 1 s.d. h (tolerance 0.5 and 0.1)
by mouse (home cage, h): {'Mouse12': 4.02, 'Mouse17': 5.29, 'Mouse20': 4.65, 'Mouse24': 4.07, 'Mouse25': 4.95, 'Mouse28': 6.27}

Result: reproduced. Under reading (a), the home-cage epochs before and after the open field total 4.99 h on average, with an s.d. of 0.97 h, over 37 sessions with the paper's scoring. Both values are within tolerance. The scored SWS and REM total 3.20 plus or minus 0.57 h (reading b), outside it.

Firing and information: adn-pos-peak-rate, adn-pos-hd-information, supfig2a-unimodality¶

In [14]:
rows = []
for rd in ("a", "b"):
    h = CELLS[CELLS["hd_" + rd]]
    A, P = h[h.region == "ADn"]["peak_" + rd], h[h.region == "PoS"]["peak_" + rd]
    u = stats.mannwhitneyu(A, P, alternative="two-sided")
    rows.append(dict(reading=rd, n_adn=len(A), n_pos=len(P), median_adn=A.median(), median_pos=P.median(),
                     ratio_medians=A.median() / P.median(), mean_adn=A.mean(), mean_pos=P.mean(),
                     ratio_means=A.mean() / P.mean(), U=u.statistic, p=u.pvalue))
print(pd.DataFrame(rows).to_string(index=False))
print("expected ratio 3 (tolerance 0.3, or 2.5 to 3), Mann-Whitney p < 1e-10")
h = CELLS[CELLS.hd_a]
print("by mouse, median peak rate (hd-a):")
print(h.groupby(["subject", "region"]).peak_a.median().unstack().round(2).to_string())
reading  n_adn  n_pos  median_adn  median_pos  ratio_medians  mean_adn  mean_pos  ratio_means       U            p
      a    293     82   22.004626    5.858957       3.755724 33.727584  8.533907     3.952186 18397.0 1.877539e-13
      b    312    120   19.619081    5.589722       3.509849 32.501595  7.637062     4.255772 28909.0 1.855398e-18
expected ratio 3 (tolerance 0.3, or 2.5 to 3), Mann-Whitney p < 1e-10
by mouse, median peak rate (hd-a):
region     ADn   PoS
subject             
Mouse12  23.56   NaN
Mouse17  18.57   NaN
Mouse20  23.91   NaN
Mouse24  16.94  7.54
Mouse25  34.07  6.14
Mouse28  21.57  4.76

Result: partially reproduced. ADn HD cells have higher peak rates than PoS HD cells (Mann-Whitney p = 1.9e-13 under hd-a, 1.9e-18 under hd-b, both below 1e-10). The ratio is above 3.3 under every reading: medians 3.76 and means 3.95 (hd-a), medians 3.51 and means 4.26 (hd-b).

In [15]:
rows = []
for rd in ("a", "b"):
    h = CELLS[CELLS["hd_" + rd]]
    A, P = h[h.region == "ADn"]["info"], h[h.region == "PoS"]["info"]
    u = stats.mannwhitneyu(A, P, alternative="two-sided")
    rows.append(dict(reading=rd, n_adn=len(A), n_pos=len(P), median_adn=A.median(), median_pos=P.median(),
                     mean_adn=A.mean(), mean_pos=P.mean(), U=u.statistic, p=u.pvalue))
print(pd.DataFrame(rows).to_string(index=False))
print("expected ADn 1.44, PoS 1.11 bit/spike (tolerance 10%), Mann-Whitney p < 1e-6")
print("by mouse, median (hd-a):")
print(h.groupby(["subject", "region"])["info"].median().unstack().round(2).to_string())
reading  n_adn  n_pos  median_adn  median_pos  mean_adn  mean_pos       U            p
      a    293     82    1.378313    1.139096  1.435049  1.171175 15552.0 4.537354e-05
      b    312    120    1.347514    0.867008  1.383568  1.004238 26403.0 3.851164e-11
expected ADn 1.44, PoS 1.11 bit/spike (tolerance 10%), Mann-Whitney p < 1e-6
by mouse, median (hd-a):
region    ADn   PoS
subject            
Mouse12  1.40   NaN
Mouse17  1.47   NaN
Mouse20  1.26   NaN
Mouse24  1.55  0.57
Mouse25  1.36  1.11
Mouse28  1.11  0.78

Result: reproduced. Under reading (hd-b) with means, ADn HD cells carry 1.38 and PoS HD cells 1.00 bits per spike, both within tolerance, with Mann-Whitney p = 3.9e-11. Under (hd-a) both medians (1.38, 1.14) and both means (1.44, 1.17) are within tolerance, but p = 4.5e-5 does not reach 1e-6. With (hd-b) medians the PoS value (0.87) is outside.

In [16]:
rows = []
for rd in ("a", "b"):
    h = CELLS[CELLS["hd_" + rd]]
    for reg in ("ADn", "PoS"):
        c = h[h.region == reg]
        rows.append(dict(hd_reading=rd, region=reg, n=len(c), not_unimodal_a=c.unimodal_fail_a.mean(),
                         not_unimodal_b=c.unimodal_fail_b.mean()))
print(pd.DataFrame(rows).round(3).to_string(index=False))
print("expected ADn 0.12, PoS 0.32 (tolerance 10%)")
hd_reading region   n  not_unimodal_a  not_unimodal_b
         a    ADn 293           0.109           0.034
         a    PoS  82           0.183           0.122
         b    ADn 312           0.122           0.051
         b    PoS 120           0.292           0.242
expected ADn 0.12, PoS 0.32 (tolerance 10%)

Result: reproduced. Under HD reading (hd-b) and peak reading (a), 12.2% of ADn and 29.2% of PoS HD cells have a second peak of 50% or more, both within tolerance. Under (hd-a) the ADn fraction (10.9%) is within and the PoS fraction (18.3%) is not. Peak reading (b) gives lower fractions (3.4 to 5.1% ADn, 12.2 to 24.2% PoS).

State preservation: fig2a-rates-preserved, fig2b-pair-correlations-preserved¶

In [17]:
rows = []
for rd in ("a", "b"):
    for sel_name in ("sessions with SWS and REM", "rate-a", "rate-b"):
        h = CELLS[CELLS["hd_" + rd] & CELLS.has_sleep]
        if sel_name == "rate-a":
            h = h[h.pass_rate_a]
        if sel_name == "rate-b":
            h = h[h.pass_rate_b]
        for reg in ("ADn", "PoS"):
            c = h[h.region == reg]
            for st in ("SWS", "REM"):
                r, p = stats.pearsonr(c.rate_wake, c["rate_" + st])
                rl, _ = stats.pearsonr(np.log10(c.rate_wake + 1e-3), np.log10(c["rate_" + st] + 1e-3))
                rows.append(dict(hd=rd, cells=sel_name, region=reg, state=st, n=len(c), r=r, p=p, r_log=rl))
F2A = pd.DataFrame(rows)
print(F2A.round(4).to_string(index=False))
print("expected n: ADn 215, PoS 62; threshold readings r >= 0.7 or r >= 0.5")
h = CELLS[CELLS.hd_a & CELLS.has_sleep]
print("by mouse (hd-a, ADn and PoS together), r wake-SWS / wake-REM:")
for m, c in h.groupby("subject"):
    if len(c) > 3:
        print(m, len(c), round(stats.pearsonr(c.rate_wake, c.rate_SWS)[0], 3), round(stats.pearsonr(c.rate_wake, c.rate_REM)[0], 3))
hd                     cells region state   n      r   p  r_log
 a sessions with SWS and REM    ADn   SWS 274 0.8014 0.0 0.8134
 a sessions with SWS and REM    ADn   REM 274 0.8624 0.0 0.8820
 a sessions with SWS and REM    PoS   SWS  69 0.6524 0.0 0.4068
 a sessions with SWS and REM    PoS   REM  69 0.6599 0.0 0.5619
 a                    rate-a    ADn   SWS 245 0.7815 0.0 0.7945
 a                    rate-a    ADn   REM 245 0.8519 0.0 0.8782
 a                    rate-a    PoS   SWS  38 0.7270 0.0 0.6521
 a                    rate-a    PoS   REM  38 0.6566 0.0 0.6864
 a                    rate-b    ADn   SWS 272 0.7999 0.0 0.8080
 a                    rate-b    ADn   REM 272 0.8615 0.0 0.8787
 a                    rate-b    PoS   SWS  66 0.6437 0.0 0.3971
 a                    rate-b    PoS   REM  66 0.6439 0.0 0.5060
 b sessions with SWS and REM    ADn   SWS 293 0.8036 0.0 0.8165
 b sessions with SWS and REM    ADn   REM 293 0.8656 0.0 0.8870
 b sessions with SWS and REM    PoS   SWS 100 0.6581 0.0 0.4515
 b sessions with SWS and REM    PoS   REM 100 0.6824 0.0 0.6398
 b                    rate-a    ADn   SWS 264 0.7858 0.0 0.7948
 b                    rate-a    ADn   REM 264 0.8563 0.0 0.8786
 b                    rate-a    PoS   SWS  58 0.6806 0.0 0.6572
 b                    rate-a    PoS   REM  58 0.6430 0.0 0.7075
 b                    rate-b    ADn   SWS 290 0.8016 0.0 0.8085
 b                    rate-b    ADn   REM 290 0.8644 0.0 0.8824
 b                    rate-b    PoS   SWS  97 0.6538 0.0 0.4436
 b                    rate-b    PoS   REM  97 0.6745 0.0 0.6074
expected n: ADn 215, PoS 62; threshold readings r >= 0.7 or r >= 0.5
by mouse (hd-a, ADn and PoS together), r wake-SWS / wake-REM:
Mouse12 66 0.83 0.845
Mouse17 51 0.847 0.903
Mouse20 14 0.88 0.966
Mouse24 33 0.681 0.916
Mouse25 71 0.834 0.824
Mouse28 108 0.812 0.902

Result: reproduced. Under the r of at least 0.5 reading, all four correlations pass with p < 0.05. In ADn the waking rates correlate with SWS rates at r = 0.80 and with REM rates at r = 0.86 (hd-a, 274 cells in sessions with both sleep stages). In PoS the values are 0.65 and 0.66 (69 cells). The PoS values are below 0.7 under every cell reading except waking against SWS with rate-a cells (0.73). The cell counts are 245 to 293 ADn and 38 to 100 PoS, against 215 and 62.

In [18]:
# Pairs of HD cells with their offsets and the rate threshold flags.
C_idx = CELLS.set_index(["session", "unit"])
def attach(df, a="u1", b="u2"):
    df = df.copy()
    for side, col in (("1", a), ("2", b)):
        key = list(zip(df.session, df[col]))
        sub = C_idx.loc[key]
        for k in ("region", "hd_a", "hd_b", "pref_a", "pref_b", "pass_rate_a", "pass_rate_b", "rate_wake", "rate_SWS",
                  "rate_REM", "peak_a", "has_sleep"):
            df[k + side] = sub[k].values
    df["off_a"] = np.degrees(np.abs(hd.circ_diff(df.pref_a1.values.astype(float), df.pref_a2.values.astype(float))))
    df["off_b"] = np.degrees(np.abs(hd.circ_diff(df.pref_b1.values.astype(float), df.pref_b2.values.astype(float))))
    return df
PP = attach(PAIRS)
def hdpairs(rd, rate):
    m = PP["hd_" + rd + "1"].astype(bool) & PP["hd_" + rd + "2"].astype(bool)
    m &= PP["pass_rate_" + rate + "1"].astype(bool) & PP["pass_rate_" + rate + "2"].astype(bool)
    return PP[m]
print("all pairs of ADn and PoS cells:", len(PP), PP.groupby("kind").size().to_dict())
for rd in ("a", "b"):
    for rate in ("a", "b"):
        print(f"hd-{rd}, rate-{rate}:", hdpairs(rd, rate).groupby("kind").size().to_dict())
all pairs of ADn and PoS cells: 17362 {'ADn-ADn': 9869, 'ADn-PoS': 4177, 'PoS-PoS': 3316}
hd-a, rate-a: {'ADn-ADn': 1006, 'ADn-PoS': 322, 'PoS-PoS': 36}
hd-a, rate-b: {'ADn-ADn': 1290, 'ADn-PoS': 694, 'PoS-PoS': 179}
hd-b, rate-a: {'ADn-ADn': 1137, 'ADn-PoS': 546, 'PoS-PoS': 110}
hd-b, rate-b: {'ADn-ADn': 1425, 'ADn-PoS': 1123, 'PoS-PoS': 407}
In [19]:
rows = []
for rd in ("a", "b"):
    for rate in ("a", "b"):
        for ss in ("all pairs", "different shanks"):
            P_ = hdpairs(rd, rate)
            P_ = P_[P_.has_sleep1.astype(bool)]
            if ss == "different shanks":
                P_ = P_[~P_.same_shank]
            for kind, c in P_.groupby("kind"):
                for st in ("SWS", "REM"):
                    ok = c[["corr_wake", "corr_" + st]].notna().all(1)
                    r, p = stats.pearsonr(c.corr_wake[ok], c["corr_" + st][ok])
                    rows.append(dict(hd=rd, rate=rate, pairs=ss, kind=kind, state=st, n=int(ok.sum()), r=r, p=p))
F2B = pd.DataFrame(rows)
print(F2B.round(4).to_string(index=False))
print("expected pairs: ADn 970 (Fig. 2b) or 907 (Fig. 3a), PoS 92")
hd rate            pairs    kind state    n      r   p
 a    a        all pairs ADn-ADn   SWS 1006 0.9444 0.0
 a    a        all pairs ADn-ADn   REM 1006 0.9681 0.0
 a    a        all pairs ADn-PoS   SWS  322 0.9079 0.0
 a    a        all pairs ADn-PoS   REM  322 0.9309 0.0
 a    a        all pairs PoS-PoS   SWS   36 0.9378 0.0
 a    a        all pairs PoS-PoS   REM   36 0.9147 0.0
 a    a different shanks ADn-ADn   SWS  394 0.9343 0.0
 a    a different shanks ADn-ADn   REM  394 0.9656 0.0
 a    a different shanks ADn-PoS   SWS  322 0.9079 0.0
 a    a different shanks ADn-PoS   REM  322 0.9309 0.0
 a    a different shanks PoS-PoS   SWS   18 0.9530 0.0
 a    a different shanks PoS-PoS   REM   18 0.9179 0.0
 a    b        all pairs ADn-ADn   SWS 1217 0.9410 0.0
 a    b        all pairs ADn-ADn   REM 1217 0.9644 0.0
 a    b        all pairs ADn-PoS   SWS  590 0.8875 0.0
 a    b        all pairs ADn-PoS   REM  590 0.9073 0.0
 a    b        all pairs PoS-PoS   SWS  145 0.8468 0.0
 a    b        all pairs PoS-PoS   REM  145 0.8801 0.0
 a    b different shanks ADn-ADn   SWS  479 0.9310 0.0
 a    b different shanks ADn-ADn   REM  479 0.9632 0.0
 a    b different shanks ADn-PoS   SWS  590 0.8875 0.0
 a    b different shanks ADn-PoS   REM  590 0.9073 0.0
 a    b different shanks PoS-PoS   SWS   82 0.8740 0.0
 a    b different shanks PoS-PoS   REM   82 0.8760 0.0
 b    a        all pairs ADn-ADn   SWS 1137 0.9415 0.0
 b    a        all pairs ADn-ADn   REM 1137 0.9639 0.0
 b    a        all pairs ADn-PoS   SWS  546 0.9066 0.0
 b    a        all pairs ADn-PoS   REM  546 0.9233 0.0
 b    a        all pairs PoS-PoS   SWS  110 0.8638 0.0
 b    a        all pairs PoS-PoS   REM  110 0.8857 0.0
 b    a different shanks ADn-ADn   SWS  442 0.9307 0.0
 b    a different shanks ADn-ADn   REM  442 0.9607 0.0
 b    a different shanks ADn-PoS   SWS  546 0.9066 0.0
 b    a different shanks ADn-PoS   REM  546 0.9233 0.0
 b    a different shanks PoS-PoS   SWS   55 0.9079 0.0
 b    a different shanks PoS-PoS   REM   55 0.8823 0.0
 b    b        all pairs ADn-ADn   SWS 1352 0.9388 0.0
 b    b        all pairs ADn-ADn   REM 1352 0.9605 0.0
 b    b        all pairs ADn-PoS   SWS  955 0.8808 0.0
 b    b        all pairs ADn-PoS   REM  955 0.9026 0.0
 b    b        all pairs PoS-PoS   SWS  324 0.8108 0.0
 b    b        all pairs PoS-PoS   REM  324 0.8663 0.0
 b    b different shanks ADn-ADn   SWS  529 0.9284 0.0
 b    b different shanks ADn-ADn   REM  529 0.9578 0.0
 b    b different shanks ADn-PoS   SWS  955 0.8808 0.0
 b    b different shanks ADn-PoS   REM  955 0.9026 0.0
 b    b different shanks PoS-PoS   SWS  182 0.8236 0.0
 b    b different shanks PoS-PoS   REM  182 0.8551 0.0
expected pairs: ADn 970 (Fig. 2b) or 907 (Fig. 3a), PoS 92
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)
/tmp/ipykernel_2503/1885310188.py:11: Pandas4Warning: Starting with pandas version 4.0 all arguments of all will be keyword-only.
  ok = c[["corr_wake", "corr_" + st]].notna().all(1)

Result: reproduced. The waking pair correlations predict the SWS and REM ones in every pair type, reading and shank selection, with r from 0.81 to 0.97 (all p < 0.05), so the 0.7 reading holds. The ADn pair counts (1006 to 1425 HD pairs) are above 970.

Speed of the internal HD signal: fig2f-sws-tenfold-faster, fig2e-decoded-speed, fig2f-rem-similar-to-wake¶

The cross-correlogram speed fit is hd.fit_speed (Methods, Estimation of angular velocity): 10 ms bins, lags to +-2 s in wake and REM and +-0.5 s in SWS (reading v-a), chi-squared (3 d.f.) speed distribution, coarse grid then Nelder-Mead. Speeds are in degrees per second.

In [20]:
def speed_pairs(rd, rate, st):
    """HD pairs of one type with a positive, finite fitted speed in wake and in state st."""
    P_ = hdpairs(rd, rate)
    P_ = P_[P_.kind.isin(["ADn-ADn", "PoS-PoS"])]
    ok = np.isfinite(P_.v_wake) & np.isfinite(P_["v_" + st]) & (P_.v_wake > 0) & (P_["v_" + st] > 0)
    return P_[ok], int((~ok).sum())
def at_edge(c, st):
    return (c.v_wake < 5.01) | (c.v_wake > 4999) | (c["v_" + st] < 5.01) | (c["v_" + st] > 4999)
rows = []
for rd in ("a", "b"):
    for rate in ("a", "b"):
        P_, ndrop = speed_pairs(rd, rate, "SWS")
        for kind, c0 in P_.groupby("kind"):
            for edge in ("all fits", "no fit at a grid end"):
                c = c0 if edge == "all fits" else c0[~at_edge(c0, "SWS")]
                ratio = c.v_SWS / c.v_wake
                w = stats.wilcoxon(np.log(ratio))
                rows.append(dict(hd=rd, rate=rate, kind=kind, fits=edge, n=len(c), dropped_zero=ndrop, v_wake=c.v_wake.median(),
                                 v_SWS=c.v_SWS.median(), median_ratio=ratio.median(), frac_SWS_faster=(ratio > 1).mean(),
                                 wilcoxon_p=w.pvalue))
F2F = pd.DataFrame(rows)
print(F2F.to_string(index=False, float_format=lambda x: f"{x:.4g}"))
print("expected median SWS/wake ratio 10 (tolerance 1)")
c = hdpairs("a", "a")
c = c[c.kind == "ADn-ADn"]
print("ADn-ADn (hd-a, rate-a) by mouse, median ratio:", (c.v_SWS / c.v_wake).groupby(c.subject).median().round(2).to_dict())
SP = PP[PP.kind.isin(["ADn-ADn", "PoS-PoS"]) & PP.v_wake.notna()]
print("fit quality per state, HD pairs of one structure (residual sum of squares over the CCG's sum of squares about its mean):")
for st in ("wake", "SWS", "REM"):
    v, r = SP["v_" + st], SP["res_" + st]
    print(f"  {st}: pairs {int(v.notna().sum())}; residual median {r.median():.3f}, 90th pct {r.quantile(0.9):.3f}, "
          f"fraction above 1 {float((r > 1).mean()):.3f}; speed at the grid ends (<= 5 or >= 5000 deg/s) {int(((v < 5.01) | (v > 4999)).sum())}; "
          f"speed 0 {int((v == 0).sum())}, below 1 deg/s {int((v < 1).sum())}; range {v.min():.3g} to {v.max():.4g} deg/s")
print("pairs with a fitted speed at a grid end in some state:",
      int(((SP[["v_wake", "v_SWS", "v_REM"]] < 5.01) | (SP[["v_wake", "v_SWS", "v_REM"]] > 4999)).any(axis=1).sum()), "of", len(SP))
hd rate    kind                 fits    n  dropped_zero  v_wake  v_SWS  median_ratio  frac_SWS_faster  wilcoxon_p
 a    a ADn-ADn             all fits 1006             0   30.87  350.5         12.31           0.9573  1.719e-136
 a    a ADn-ADn no fit at a grid end  882             0   31.19  346.4         11.71            0.983  4.247e-143
 a    a PoS-PoS             all fits   36             0   25.77  185.1         6.125           0.8889   0.0003561
 a    a PoS-PoS no fit at a grid end   28             0   27.39  185.1         6.149                1   7.451e-09
 a    b ADn-ADn             all fits 1217           107   31.19  352.7         12.25           0.9581  3.765e-168
 a    b ADn-ADn no fit at a grid end 1074           107   31.35  347.2         11.67           0.9804  3.267e-174
 a    b PoS-PoS             all fits  145           107   32.26    218         5.591           0.8759   8.243e-13
 a    b PoS-PoS no fit at a grid end  102           107   34.13  191.6          5.18            0.951   6.544e-15
 b    a ADn-ADn             all fits 1137             0   31.44  340.8         11.67           0.9428  3.821e-144
 b    a ADn-ADn no fit at a grid end  982             0   31.58  333.6         11.04           0.9745  4.448e-156
 b    a PoS-PoS             all fits  110             0   27.99  185.8         6.125           0.8818   8.612e-12
 b    a PoS-PoS no fit at a grid end   86             0   28.17  176.1         6.023           0.9651   1.135e-15
 b    b ADn-ADn             all fits 1352           156   31.54  342.7         11.65           0.9445  1.439e-175
 b    b ADn-ADn no fit at a grid end 1175           156   31.66  334.6         11.04           0.9728  1.053e-186
 b    b PoS-PoS             all fits  324           156   31.31    198         6.125           0.8796   1.712e-29
 b    b PoS-PoS no fit at a grid end  241           156   31.63  182.3         5.591           0.9461    2.39e-34
expected median SWS/wake ratio 10 (tolerance 1)
ADn-ADn (hd-a, rate-a) by mouse, median ratio: {'Mouse12': 11.89, 'Mouse17': 11.82, 'Mouse20': 16.33, 'Mouse24': 12.07, 'Mouse25': 13.15, 'Mouse28': 12.17}
fit quality per state, HD pairs of one structure (residual sum of squares over the CCG's sum of squares about its mean):
  wake: pairs 1950; residual median 0.549, 90th pct 1.694, fraction above 1 0.252; speed at the grid ends (<= 5 or >= 5000 deg/s) 127; speed 0 0, below 1 deg/s 71; range 1.51e-14 to 1.1e+04 deg/s
  SWS: pairs 1778; residual median 0.523, 90th pct 2.051, fraction above 1 0.259; speed at the grid ends (<= 5 or >= 5000 deg/s) 197; speed 0 0, below 1 deg/s 49; range 1.51e-14 to 3.773e+04 deg/s
  REM: pairs 1778; residual median 1.043, 90th pct 3.296, fraction above 1 0.498; speed at the grid ends (<= 5 or >= 5000 deg/s) 194; speed 0 0, below 1 deg/s 99; range 1.51e-14 to 2.049e+04 deg/s
pairs with a fitted speed at a grid end in some state: 387 of 1950

Result: partially reproduced. The SWS speed exceeds the waking speed in most pairs (Wilcoxon p < 0.001 in every reading), but the median SWS to waking ratio is outside 9 to 11. In ADn-ADn pairs it is 11.65 to 12.31 with all fits and 11.04 to 11.71 without pairs whose fit sits at an end of the speed grid; 95.7% of ADn-ADn pairs are faster in SWS under hd-a and rate-a. In PoS-PoS pairs it is 5.18 to 6.15. It is above 5 in both, the partial criterion. No fitted speed is exactly 0, but every state has fits at 1.5e-14 deg/s, effectively 0 (the count below 1 deg/s is printed per state); they are among the fits at a grid end, so the variant without those fits leaves them out and gives the 11.04 to 11.71 above. Pairs without a finite speed in both states (107 or 156 under rate-b, sessions without sleep scoring) are left out. Fits are loose: the median residual is about half of the cross-correlogram's variance in waking and SWS and about equal to it in REM, and 387 of 1950 pairs have a speed at a grid end in some state.

In [21]:
cols = ["session", "region", "n_hd", "speed_af_wake", "speed_b_wake", "speed_a_actual", "speed_b_actual",
        "speed_af_SWS", "speed_b_SWS", "speed_af_REM", "speed_b_REM"]
print(ENS[cols].round(1).to_string(index=False))
rows = []
E_ = ENS[ENS.speed_a_SWS.notna()]
STEPS = {"a, sub-degree": ("af", "a"), "a, 1-degree grid": ("a", "a"), "b": ("b", "b")}
for reg, e in E_.groupby("region"):
    for step, (key, akey) in STEPS.items():
        for wk in ("w-a decoded", "w-b actual"):
            for summ in ("median", "mean"):
                if summ == "mean" and key == "a":
                    continue
                k_ = {"af": "afmean", "b": "bmean"}.get(key, key) if summ == "mean" else key
                ka = {"a": "afmean", "b": "bmean"}[akey] if summ == "mean" else akey
                w = e[f"speed_{k_}_wake"] if wk.startswith("w-a") else e[f"speed_{ka}_actual"]
                sws, rem = e[f"speed_{k_}_SWS"].median(), e[f"speed_{k_}_REM"].median()
                rs = sws / w.median() if w.median() > 0 else np.inf
                rr = rem / w.median() if w.median() > 0 else np.inf
                rows.append(dict(region=reg, step=step, wake=wk, per_ensemble=summ, n=len(e), wake_med=w.median(), SWS_med=sws,
                                 REM_med=rem, ratio_SWS=rs, ratio_REM=rr, SWS_ok=9 <= rs <= 11, REM_ok=0.67 <= rr <= 1.5))
F2E = pd.DataFrame(rows)
print(F2E.round(3).to_string(index=False))
print("expected SWS/wake 10 (tolerance 1); REM/wake between 0.67 and 1.5. Per-ensemble value: the median speed (criterion),"
      " or the mean speed (variant). Columns *_med: median over ensembles.")
print("steps spanning two intervals of a state are left out; reading (a) at the 1-degree grid gives 0 or 100 deg/s medians")
       session region  n_hd  speed_af_wake  speed_b_wake  speed_a_actual  speed_b_actual  speed_af_SWS  speed_b_SWS  speed_af_REM  speed_b_REM
Mouse12-120806    ADn    20           23.8          23.3            83.9            37.4         106.5        160.0          13.7         13.3
Mouse12-120807    ADn    13           18.6          20.0            77.3            30.5          90.3        160.0          10.2         13.3
Mouse12-120808    ADn    11           17.0          16.7            68.7            25.9          98.9        140.0           9.4         10.0
Mouse12-120809    ADn    13           28.7          30.0            86.7            43.3         107.5        140.0          11.4         13.3
Mouse12-120810    ADn     9           24.9          26.7            79.0            38.0         135.6        180.0          12.2         13.3
Mouse17-130129    ADn     8           24.6          26.7            84.0            41.9         132.1        160.0          15.5         16.7
Mouse17-130130    ADn    10           21.3          23.3            81.0            38.6         110.3        140.0          12.7         13.3
Mouse17-130131    ADn     7           21.2          26.7            77.9            37.5         113.3        160.0          11.8         16.7
Mouse17-130201    ADn     6           21.4          26.7            94.4            44.6          99.0        140.0          11.3         13.3
Mouse20-130517    ADn     6           16.6          20.0            78.3            28.4         126.4        180.0          12.2         16.7
Mouse24-131216    ADn     8           23.0          30.0            83.3            43.5         108.6        160.0          12.1         16.7
Mouse24-131217    ADn     8           18.5          23.3            81.0            42.2          99.1        140.0          11.9         16.7
Mouse24-131218    ADn     9           19.2          23.3            83.9            45.1          81.7        120.0          10.6         13.3
Mouse25-140123    PoS     8           10.7          13.3            59.8            21.4          40.4         60.0           8.9         13.3
Mouse25-140130    ADn     8           19.1          20.0            68.7            32.3          76.3        100.0          10.8         13.3
Mouse25-140131    ADn     9           22.3          23.3            78.8            37.3           NaN          NaN           NaN          NaN
Mouse25-140131    PoS     8           12.9          20.0            78.8            37.3           NaN          NaN           NaN          NaN
Mouse25-140203    ADn     8           21.2          23.3            74.8            34.8          98.7        140.0          13.5         13.3
Mouse25-140204    ADn    10           19.7          23.3            76.3            34.1           NaN          NaN           NaN          NaN
Mouse25-140205    ADn     8           17.1          20.0            70.7            27.8          93.1        160.0          11.8         13.3
Mouse25-140206    ADn     6           15.7          20.0            68.7            25.8          89.9        160.0          11.7         16.7
Mouse28-140310    ADn    10           11.7          13.3            49.5            13.8          92.4        140.0          12.2         13.3
Mouse28-140310    PoS     6            7.9          13.3            49.5            13.8           0.0          0.0           9.8         16.7
Mouse28-140311    ADn    10           20.5          20.0            84.8            30.1          75.6        100.0          13.1         16.7
Mouse28-140312    ADn    14           19.3          20.0            85.8            27.8          78.1        100.0          14.7         16.7
Mouse28-140312    PoS    10            9.4          16.7            85.8            27.8          16.3         20.0           8.3         13.3
Mouse28-140313    ADn    15           23.0          23.3            64.2            29.7          82.5        100.0          14.9         16.7
Mouse28-140313    PoS     9           15.5          20.0            64.2            29.7          50.4        100.0          12.6         20.0
Mouse28-140317    ADn    12           17.2          16.7           113.2            31.3          81.3        100.0          16.9         23.3
Mouse28-140318    ADn    13           14.3          13.3           107.0            28.2          79.2        100.0          14.9         20.0
region             step        wake per_ensemble  n  wake_med  SWS_med  REM_med  ratio_SWS  ratio_REM  SWS_ok  REM_ok
   ADn    a, sub-degree w-a decoded       median 23    19.319   98.681   12.161      5.108      0.630   False   False
   ADn    a, sub-degree w-a decoded         mean 23    38.293  568.519   47.385     14.847      1.237   False    True
   ADn    a, sub-degree  w-b actual       median 23    81.020   98.681   12.161      1.218      0.150   False   False
   ADn    a, sub-degree  w-b actual         mean 23   106.328  568.519   47.385      5.347      0.446   False   False
   ADn a, 1-degree grid w-a decoded       median 23     0.000  100.000    0.000        inf        inf   False   False
   ADn a, 1-degree grid  w-b actual       median 23    81.020  100.000    0.000      1.234      0.000   False   False
   ADn                b w-a decoded       median 23    23.333  140.000   13.333      6.000      0.571   False   False
   ADn                b w-a decoded         mean 23    36.288  513.346   44.239     14.147      1.219   False    True
   ADn                b  w-b actual       median 23    32.303  140.000   13.333      4.334      0.413   False   False
   ADn                b  w-b actual         mean 23    50.044  513.346   44.239     10.258      0.884    True    True
   PoS    a, sub-degree w-a decoded       median  4    10.038   28.319    9.321      2.821      0.929   False    True
   PoS    a, sub-degree w-a decoded         mean  4    67.563  458.009   78.377      6.779      1.160   False    True
   PoS    a, sub-degree  w-b actual       median  4    61.996   28.319    9.321      0.457      0.150   False   False
   PoS    a, sub-degree  w-b actual         mean  4    81.864  458.009   78.377      5.595      0.957   False    True
   PoS a, 1-degree grid w-a decoded       median  4     0.000    0.000    0.000        inf        inf   False   False
   PoS a, 1-degree grid  w-b actual       median  4    61.996    0.000    0.000      0.000      0.000   False   False
   PoS                b w-a decoded       median  4    15.000   40.000   15.000      2.667      1.000   False    True
   PoS                b w-a decoded         mean  4    60.067  414.272   68.760      6.897      1.145   False    True
   PoS                b  w-b actual       median  4    24.610   40.000   15.000      1.625      0.610   False   False
   PoS                b  w-b actual         mean  4    40.570  414.272   68.760     10.211      1.695    True   False
expected SWS/wake 10 (tolerance 1); REM/wake between 0.67 and 1.5. Per-ensemble value: the median speed (criterion), or the mean speed (variant). Columns *_med: median over ensembles.
steps spanning two intervals of a state are left out; reading (a) at the 1-degree grid gives 0 or 100 deg/s medians

Result: partially reproduced. The SWS part fails under every reading; the REM part holds in PoS only. With the per-ensemble median speed (the criterion), the ADn SWS to waking ratio is 5.11 at 10 ms steps with the posterior maximum located below the 1 degree grid (reading a), 6.00 at the smoothing window (b), and 1.22 or 4.33 with the actual head speed in waking (w-b); the ADn REM ratios are 0.15 to 0.63, below 0.67. In PoS (4 ensembles with sleep) the SWS ratios are 0.46 to 2.82 and the REM ratio is 0.93 (a, w-a) and 1.00 (b, w-a), inside 0.67 to 1.5. On the 1 degree grid, 10 ms medians are 0 or 100 deg/s and cannot decide. As a variant outside the criterion, mean speeds per ensemble give ADn ratios of 10.26 (SWS) and 0.88 (REM) at the smoothing window with the actual waking speed.

In [22]:
rows = []
for rd in ("a", "b"):
    for rate in ("a", "b"):
        P_, ndrop = speed_pairs(rd, rate, "REM")
        for kind, c in P_.groupby("kind"):
            ratio = c.v_REM / c.v_wake
            w = stats.wilcoxon(np.log(ratio))
            rows.append(dict(hd=rd, rate=rate, kind=kind, n=len(c), dropped_zero=ndrop, v_wake=c.v_wake.median(),
                             v_REM=c.v_REM.median(), median_ratio=ratio.median(), wilcoxon_p=w.pvalue))
print(pd.DataFrame(rows).round(4).to_string(index=False))
print("readings: (a) median ratio in 0.67 to 1.5; (b) Wilcoxon of the log ratio p >= 0.05")
hd rate    kind    n  dropped_zero  v_wake   v_REM  median_ratio  wilcoxon_p
 a    a ADn-ADn 1006             0 30.8704 31.3521        1.0284      0.2093
 a    a PoS-PoS   36             0 25.7654 24.1526        1.1109      0.6247
 a    b ADn-ADn 1217           107 31.1873 31.2898        1.0302      0.1655
 a    b PoS-PoS  145           107 32.2647 31.6839        0.9623      0.3613
 b    a ADn-ADn 1137             0 31.4437 31.5681        1.0247      0.2713
 b    a PoS-PoS  110             0 27.9851 29.9495        1.2033      0.3199
 b    b ADn-ADn 1352           156 31.5372 31.5890        1.0265      0.2770
 b    b PoS-PoS  324           156 31.3063 31.9179        1.0473      0.6565
readings: (a) median ratio in 0.67 to 1.5; (b) Wilcoxon of the log ratio p >= 0.05

Result: reproduced. Both readings hold in ADn-ADn and PoS-PoS pairs under every HD and rate reading. The median REM to waking speed ratio is 0.96 to 1.20, inside 0.67 to 1.5, and no Wilcoxon test of the log ratio reaches p < 0.05 (p from 0.17 to 0.66). Pairs without a positive, finite speed in both states are left out. No speed is exactly 0, but some fits sit at 1.5e-14 deg/s, effectively 0 (counts in the fig2f-sws-tenfold-faster cell); they are kept, and the medians do not rest on them.

The activity packet: fig3a-packet-60-degrees, fig3a-adn-stronger-than-pos, supfig5-rate-independent, fig3b-packet-coherence¶

In [23]:
def crossing(off, corr, width):
    b = np.arange(0, 180 + width, width)
    cen = 0.5 * (b[1:] + b[:-1])
    m = np.array([np.mean(corr[(off >= lo) & (off < hi)]) if np.any((off >= lo) & (off < hi)) else np.nan
                  for lo, hi in zip(b[:-1], b[1:])])
    for i in range(len(m) - 1):
        if m[i] > 0 and m[i + 1] <= 0:
            return cen[i] + (cen[i + 1] - cen[i]) * m[i] / (m[i] - m[i + 1])
    return np.nan
rows = []
for rd in ("a", "b"):
    for rate in ("a", "b"):
        P_ = hdpairs(rd, rate)
        for kind, c in P_.groupby("kind"):
            for st in ("wake", "SWS", "REM"):
                ok = c["corr_" + st].notna()
                off = c["off_" + rd][ok].values
                cc = c["corr_" + st][ok].values
                ra, pa = stats.pearsonr(off, cc)
                rb, pb = stats.pearsonr(np.cos(np.radians(off)), cc)
                rows.append(dict(hd=rd, rate=rate, kind=kind, state=st, n=int(ok.sum()), r_abs=ra, p_abs=pa, r_cos=rb, p_cos=pb,
                                 cross10=crossing(off, cc, 10), cross20=crossing(off, cc, 20)))
F3A = pd.DataFrame(rows)
print(F3A.to_string(index=False, float_format=lambda x: f"{x:.3g}"))
print("expected crossing 60 deg (tolerance 6); pairs ADn-ADn 907, ADn-PoS 512, PoS-PoS 92; Pearson p < 1e-6")
ok = F3A[(F3A.r_abs < 0) & (F3A.p_abs < 1e-6) & (F3A.r_cos > 0) & (F3A.p_cos < 1e-6)]
for rd in ("a", "b"):
    for rate in ("a", "b"):
        f = F3A[(F3A.hd == rd) & (F3A.rate == rate)]
        print(f"hd-{rd} rate-{rate}: Pearson (abs offset) falling with p < 1e-6 in {int(((f.r_abs < 0) & (f.p_abs < 1e-6)).sum())} of 9;"
              f" (cos) {int(((f.r_cos > 0) & (f.p_cos < 1e-6)).sum())} of 9; crossing within 54-66 deg: 10-deg bins"
              f" {int(f.cross10.between(54, 66).sum())}, 20-deg bins {int(f.cross20.between(54, 66).sum())} of 9")
fig, ax = plt.subplots(1, 3, figsize=(12, 3))
P_ = hdpairs("a", "a")
for i, st in enumerate(("wake", "SWS", "REM")):
    for kind, c in P_.groupby("kind"):
        b = np.arange(0, 190, 10)
        m = [c["corr_" + st][(c.off_a >= lo) & (c.off_a < lo + 10)].mean() for lo in b[:-1]]
        ax[i].plot(b[:-1] + 5, m, label=kind)
    ax[i].axhline(0, color="k", lw=0.5); ax[i].set_title(st); ax[i].set_xlabel("offset (deg)")
ax[0].legend(); ax[0].set_ylabel("mean correlation"); plt.tight_layout(); plt.show()
hd rate    kind state    n  r_abs     p_abs  r_cos     p_cos  cross10  cross20
 a    a ADn-ADn  wake 1006 -0.772 7.09e-200   0.75 8.82e-183     54.8     56.2
 a    a ADn-ADn   SWS 1006 -0.704 3.08e-151  0.678 3.07e-136     56.7       59
 a    a ADn-ADn   REM 1006 -0.762 2.44e-191  0.741 1.49e-175     57.3     59.4
 a    a ADn-PoS  wake  322 -0.762  2.05e-62  0.744  5.15e-58     61.9     60.8
 a    a ADn-PoS   SWS  322 -0.684  1.03e-45  0.662  5.82e-42     64.2       65
 a    a ADn-PoS   REM  322 -0.742  1.95e-57  0.725  9.98e-54     63.6     62.6
 a    a PoS-PoS  wake   36 -0.678  5.54e-06  0.669  8.23e-06     61.6     66.4
 a    a PoS-PoS   SWS   36 -0.612  7.19e-05  0.594  0.000133      102      101
 a    a PoS-PoS   REM   36 -0.663  1.04e-05  0.649  1.89e-05     45.7     48.9
 a    b ADn-ADn  wake 1290 -0.761  1.2e-244   0.74 2.57e-224     54.2     55.6
 a    b ADn-ADn   SWS 1217 -0.694 2.47e-175  0.668 5.42e-158     56.3       58
 a    b ADn-ADn   REM 1217 -0.752    2e-222  0.732 2.54e-204     57.3     58.7
 a    b ADn-PoS  wake  694 -0.715 1.64e-109  0.696 1.26e-101       56     59.7
 a    b ADn-PoS   SWS  590 -0.616  5.76e-63  0.595  9.78e-58     62.5     63.6
 a    b ADn-PoS   REM  590 -0.693  9.76e-86  0.678   9.6e-81     61.5     61.6
 a    b PoS-PoS  wake  179 -0.612  8.76e-20  0.594  1.92e-18       54     57.9
 a    b PoS-PoS   SWS  145 -0.479  1.05e-09  0.458  7.08e-09     54.4      108
 a    b PoS-PoS   REM  145  -0.62  8.95e-17  0.601  1.28e-15     51.8     54.8
 b    a ADn-ADn  wake 1137 -0.739 2.62e-197  0.715 2.01e-178     51.4     52.7
 b    a ADn-ADn   SWS 1137 -0.678 1.11e-153  0.648 1.19e-136     52.2     54.9
 b    a ADn-ADn   REM 1137 -0.724 1.72e-185  0.699  9.1e-168     52.4     55.4
 b    a ADn-PoS  wake  546 -0.665  4.83e-71  0.638  1.05e-63     48.8     49.4
 b    a ADn-PoS   SWS  546   -0.6  1.39e-54  0.568  5.89e-48     51.3     54.1
 b    a ADn-PoS   REM  546 -0.634  1.26e-62  0.609  9.66e-57     50.5     51.5
 b    a PoS-PoS  wake  110 -0.545   7.7e-10  0.509   1.4e-08     42.8       48
 b    a PoS-PoS   SWS  110 -0.526  3.64e-09  0.494  4.06e-08     54.7     61.5
 b    a PoS-PoS   REM  110 -0.564  1.34e-10  0.535  1.71e-09     42.4     49.4
 b    b ADn-ADn  wake 1425 -0.735 6.19e-242   0.71 6.72e-219     51.2     52.4
 b    b ADn-ADn   SWS 1352 -0.671 8.45e-178  0.642 8.62e-158     51.8       54
 b    b ADn-ADn   REM 1352 -0.721 4.94e-217  0.696 3.01e-196     52.6     55.2
 b    b ADn-PoS  wake 1123 -0.614 1.81e-117  0.587 3.69e-105     49.9     49.6
 b    b ADn-PoS   SWS  955  -0.53  2.19e-70  0.501  1.09e-61     52.3     55.1
 b    b ADn-PoS   REM  955 -0.587  1.16e-89  0.564  2.07e-81     52.1     53.5
 b    b PoS-PoS  wake  407 -0.517   3.7e-29  0.484  3.07e-25     43.2       48
 b    b PoS-PoS   SWS  324 -0.457  4.31e-18  0.428   6.9e-16     69.7     69.2
 b    b PoS-PoS   REM  324 -0.541  4.63e-26  0.513  3.83e-23     45.2     48.6
expected crossing 60 deg (tolerance 6); pairs ADn-ADn 907, ADn-PoS 512, PoS-PoS 92; Pearson p < 1e-6
hd-a rate-a: Pearson (abs offset) falling with p < 1e-6 in 6 of 9; (cos) 6 of 9; crossing within 54-66 deg: 10-deg bins 7, 20-deg bins 6 of 9
hd-a rate-b: Pearson (abs offset) falling with p < 1e-6 in 9 of 9; (cos) 9 of 9; crossing within 54-66 deg: 10-deg bins 7, 20-deg bins 8 of 9
hd-b rate-a: Pearson (abs offset) falling with p < 1e-6 in 9 of 9; (cos) 9 of 9; crossing within 54-66 deg: 10-deg bins 1, 20-deg bins 4 of 9
hd-b rate-b: Pearson (abs offset) falling with p < 1e-6 in 9 of 9; (cos) 9 of 9; crossing within 54-66 deg: 10-deg bins 0, 20-deg bins 3 of 9

Result: partially reproduced. Under hd-a and rate-b, the zero-lag correlation falls with the preferred-direction offset in all 9 state and pair-type combinations (p < 1e-6 with the absolute offset and with its cosine). The zero crossing is within 54 to 66 degrees in 7 of 9 combinations with 10 degree bins, and 8 of 9 with 20 degree bins. PoS-PoS in SWS crosses at 54 and 108 degrees. Under hd-a and rate-a the PoS-PoS tests reach only p = 5.5e-6 to 7.2e-5 with the absolute offset and 8.2e-6 to 1.3e-4 with its cosine (36 pairs); under hd-b and rate-a all 9 tests pass. ADn-ADn pairs cross at 54 to 59 degrees in every state.

In [24]:
rows = []
for rd in ("a", "b"):
    for rate in ("a", "b"):
        P_ = hdpairs(rd, rate)
        P_ = P_[P_["off_" + rd] < 60]
        for st in ("wake", "SWS", "REM"):
            A = P_[P_.kind == "ADn-ADn"]["corr_" + st].dropna()
            B = P_[P_.kind == "PoS-PoS"]["corr_" + st].dropna()
            u = stats.mannwhitneyu(A, B, alternative="two-sided")
            rows.append(dict(hd=rd, rate=rate, state=st, n_adn=len(A), n_pos=len(B), med_adn=A.median(), med_pos=B.median(), p=u.pvalue))
print(pd.DataFrame(rows).to_string(index=False, float_format=lambda x: f"{x:.3g}"))
print("expected pairs below 60 deg: ADn-ADn 345, PoS-PoS 55")
hd rate state  n_adn  n_pos  med_adn  med_pos        p
 a    a  wake    328     12    0.313   0.0868    0.045
 a    a   SWS    328     12    0.162   0.0407   0.0314
 a    a   REM    328     12    0.253   0.0546   0.0341
 a    b  wake    429     63    0.284   0.0575 1.85e-07
 a    b   SWS    401     53    0.151   0.0155 4.57e-08
 a    b   REM    401     53     0.23   0.0576  1.7e-06
 b    a  wake    374     46    0.295   0.0421 1.44e-06
 b    a   SWS    374     46    0.151   0.0289 2.53e-05
 b    a   REM    374     46    0.245   0.0292 3.71e-06
 b    b  wake    480    150    0.266    0.055 6.33e-14
 b    b   SWS    452    121    0.144    0.021  2.4e-11
 b    b   REM    452    121    0.226   0.0421 1.01e-11
expected pairs below 60 deg: ADn-ADn 345, PoS-PoS 55

Result: reproduced. Under hd-a and rate-b, pairs closer than 60 degrees are more correlated in ADn than in PoS in every state. The medians are 0.28 against 0.06 in waking, 0.15 against 0.02 in SWS and 0.23 against 0.06 in REM, with Mann-Whitney p = 1.9e-7, 4.6e-8 and 1.7e-6, each below the text's 1e-5. Under hd-a and rate-a, PoS has only 12 pairs and p is 0.03 to 0.045. The ADn pair counts are 328 to 480; 328 (hd-a, rate-a) and 374 (hd-b, rate-a) are within 345 plus or minus 34.5.

In [25]:
rows = []
for rd in ("a", "b"):
    for rate in ("a", "b"):
        P0 = hdpairs(rd, rate)
        P0 = P0[P0.kind.isin(["ADn-ADn", "PoS-PoS"])]
        pk = CELLS.set_index(["session", "unit"])["peak_" + rd]
        P0 = P0.assign(pk1=pk.loc[list(zip(P0.session, P0.u1))].values, pk2=pk.loc[list(zip(P0.session, P0.u2))].values)
        for which in ("all", "<60"):
            P1 = P0 if which == "all" else P0[P0["off_" + rd] < 60]
            for rmeas in ("geo_peak", "mean_rate_state", "mean_rate_wake"):
                for st in ("wake", "SWS", "REM", "pooled"):
                    sts = ("wake", "SWS", "REM") if st == "pooled" else (st,)
                    parts_ = []
                    for k in sts:
                        D = P1.assign(corr=P1["corr_" + k], state=k)
                        if rmeas == "geo_peak":  # peak rates of the HD reading's fit
                            rr = np.sqrt(D.pk1.astype(float) * D.pk2.astype(float))
                        elif rmeas == "mean_rate_state":  # mean rates in the state tested
                            rr = 0.5 * (D["rate_" + k + "1"].astype(float) + D["rate_" + k + "2"].astype(float))
                        else:  # waking mean rates (variant)
                            rr = 0.5 * (D.rate_wake1.astype(float) + D.rate_wake2.astype(float))
                        parts_.append(D.assign(rg=np.where(rr < 5, "lt5", np.where(rr < 10, "5to10", "gt10"))))
                    D = pd.concat(parts_)
                    D = D[(D.rg != "gt10") & D["corr"].notna()]
                    if D.kind.nunique() < 2 or D.rg.nunique() < 2:
                        continue
                    m = smf.ols("corr ~ C(kind) + C(rg)", data=D).fit()
                    a = sm.stats.anova_lm(m, typ=2)
                    rows.append(dict(hd=rd, rate=rate, pairs=which, rate_measure=rmeas, state=st, n=len(D),
                                     p_region=a.loc["C(kind)", "PR(>F)"], p_rategroup=a.loc["C(rg)", "PR(>F)"]))
S5 = pd.DataFrame(rows)
print(S5.to_string(index=False, float_format=lambda x: f"{x:.3g}"))
for rm, g in S5.groupby("rate_measure"):
    print(f"{rm}: readings {len(g)}; region p < 1e-7 in {int((g.p_region < 1e-7).sum())}; rate-group p > 0.05 in "
          f"{int((g.p_rategroup > 0.05).sum())}; both in {int(((g.p_region < 1e-7) & (g.p_rategroup > 0.05)).sum())}; "
          f"rate-group p < 0.05 where region p < 1e-7: {int(((g.p_region < 1e-7) & (g.p_rategroup < 0.05)).sum())}")
print("all:", len(S5), "readings; region p < 1e-7:", int((S5.p_region < 1e-7).sum()),
      "| rate-group p > 0.05:", int((S5.p_rategroup > 0.05).sum()), "| both:", int(((S5.p_region < 1e-7) & (S5.p_rategroup > 0.05)).sum()))
hd rate pairs    rate_measure  state    n  p_region  p_rategroup
 a    a   all        geo_peak   wake  155     0.888        0.756
 a    a   all        geo_peak    SWS  155      0.83        0.884
 a    a   all        geo_peak    REM  155     0.376        0.503
 a    a   all        geo_peak pooled  465      0.47        0.494
 a    a   all mean_rate_state   wake  767     0.893        0.558
 a    a   all mean_rate_state    SWS  962     0.656        0.269
 a    a   all mean_rate_state    REM  852     0.513        0.394
 a    a   all mean_rate_state pooled 2581     0.561        0.112
 a    a   all  mean_rate_wake   wake  767     0.893        0.558
 a    a   all  mean_rate_wake    SWS  767     0.932        0.323
 a    a   all  mean_rate_wake    REM  767     0.745        0.946
 a    a   all  mean_rate_wake pooled 2301     0.948        0.984
 a    a   <60        geo_peak   wake   60     0.319        0.217
 a    a   <60        geo_peak    SWS   60     0.312        0.465
 a    a   <60        geo_peak    REM   60     0.362        0.717
 a    a   <60        geo_peak pooled  180     0.107        0.194
 a    a   <60 mean_rate_state   wake  251     0.113        0.145
 a    a   <60 mean_rate_state    SWS  318    0.0836     0.000433
 a    a   <60 mean_rate_state    REM  287     0.114       0.0188
 a    a   <60 mean_rate_state pooled  856    0.0091        5e-06
 a    a   <60  mean_rate_wake   wake  251     0.113        0.145
 a    a   <60  mean_rate_wake    SWS  251     0.149      0.00122
 a    a   <60  mean_rate_wake    REM  251     0.144       0.0462
 a    a   <60  mean_rate_wake pooled  753    0.0119     0.000417
 a    b   all        geo_peak   wake  423     0.885        0.606
 a    b   all        geo_peak    SWS  389     0.391        0.689
 a    b   all        geo_peak    REM  389     0.309        0.657
 a    b   all        geo_peak pooled 1201     0.287         0.44
 a    b   all mean_rate_state   wake 1165     0.979        0.546
 a    b   all mean_rate_state    SWS 1281      0.18        0.185
 a    b   all mean_rate_state    REM 1164     0.338        0.202
 a    b   all mean_rate_state pooled 3610     0.196       0.0539
 a    b   all  mean_rate_wake   wake 1165     0.979        0.546
 a    b   all  mean_rate_wake    SWS 1078     0.641        0.276
 a    b   all  mean_rate_wake    REM 1078     0.714        0.916
 a    b   all  mean_rate_wake pooled 3321      0.69        0.945
 a    b   <60        geo_peak   wake  156  0.000233       0.0037
 a    b   <60        geo_peak    SWS  144  7.63e-05        0.141
 a    b   <60        geo_peak    REM  144   0.00315        0.217
 a    b   <60        geo_peak pooled  444  1.03e-08      0.00125
 a    b   <60 mean_rate_state   wake  393  0.000118      0.00215
 a    b   <60 mean_rate_state    SWS  432  6.87e-06     2.24e-05
 a    b   <60 mean_rate_state    REM  399  0.000449      0.00126
 a    b   <60 mean_rate_state pooled 1224   1.8e-10     1.77e-10
 a    b   <60  mean_rate_wake   wake  393  0.000118      0.00215
 a    b   <60  mean_rate_wake    SWS  363  0.000188     1.96e-06
 a    b   <60  mean_rate_wake    REM  363   0.00213     0.000864
 a    b   <60  mean_rate_wake pooled 1119  5.33e-09     1.74e-09
 b    a   all        geo_peak   wake  255     0.835        0.844
 b    a   all        geo_peak    SWS  255       0.9        0.932
 b    a   all        geo_peak    REM  255     0.361         0.81
 b    a   all        geo_peak pooled  765     0.448        0.984
 b    a   all mean_rate_state   wake  946     0.744        0.717
 b    a   all mean_rate_state    SWS 1162     0.327        0.318
 b    a   all mean_rate_state    REM 1041     0.221         0.29
 b    a   all mean_rate_state pooled 3149     0.135        0.143
 b    a   all  mean_rate_wake   wake  946     0.744        0.717
 b    a   all  mean_rate_wake    SWS  946     0.793        0.175
 b    a   all  mean_rate_wake    REM  946     0.476        0.746
 b    a   all  mean_rate_wake pooled 2838      0.45        0.635
 b    a   <60        geo_peak   wake   92  0.000422       0.0386
 b    a   <60        geo_peak    SWS   92    0.0062        0.284
 b    a   <60        geo_peak    REM   92   0.00319        0.315
 b    a   <60        geo_peak pooled  276  2.11e-07       0.0177
 b    a   <60 mean_rate_state   wake  323   0.00012       0.0109
 b    a   <60 mean_rate_state    SWS  395   0.00031      0.00036
 b    a   <60 mean_rate_state    REM  360  0.000143      0.00133
 b    a   <60 mean_rate_state pooled 1078  5.62e-10     1.53e-08
 b    a   <60  mean_rate_wake   wake  323   0.00012       0.0109
 b    a   <60  mean_rate_wake    SWS  323   0.00192     4.83e-05
 b    a   <60  mean_rate_wake    REM  323  0.000512      0.00346
 b    a   <60  mean_rate_wake pooled  969  3.62e-09     2.78e-07
 b    b   all        geo_peak   wake  659     0.852        0.816
 b    b   all        geo_peak    SWS  584     0.495        0.856
 b    b   all        geo_peak    REM  584     0.392        0.822
 b    b   all        geo_peak pooled 1827     0.491        0.724
 b    b   all mean_rate_state   wake 1502     0.808        0.722
 b    b   all mean_rate_state    SWS 1590    0.0588        0.217
 b    b   all mean_rate_state    REM 1461     0.094       0.0999
 b    b   all mean_rate_state pooled 4553    0.0292       0.0566
 b    b   all  mean_rate_wake   wake 1502     0.808        0.722
 b    b   all  mean_rate_wake    SWS 1366     0.425         0.13
 b    b   all  mean_rate_wake    REM 1366     0.405        0.911
 b    b   all  mean_rate_wake pooled 4234     0.317        0.688
 b    b   <60        geo_peak   wake  235  7.61e-07      0.00303
 b    b   <60        geo_peak    SWS  211  1.05e-07       0.0783
 b    b   <60        geo_peak    REM  211  7.09e-06       0.0898
 b    b   <60        geo_peak pooled  657   1.7e-15     0.000208
 b    b   <60 mean_rate_state   wake  523   1.7e-08     2.11e-05
 b    b   <60 mean_rate_state    SWS  548  1.24e-09     1.61e-05
 b    b   <60 mean_rate_state    REM  511  4.98e-08     5.42e-05
 b    b   <60 mean_rate_state pooled 1582   1.1e-20     4.79e-14
 b    b   <60  mean_rate_wake   wake  523   1.7e-08     2.11e-05
 b    b   <60  mean_rate_wake    SWS  474  4.19e-07     9.36e-09
 b    b   <60  mean_rate_wake    REM  474  1.57e-06     1.92e-05
 b    b   <60  mean_rate_wake pooled 1471  1.51e-17     8.75e-15
geo_peak: readings 32; region p < 1e-7 in 2; rate-group p > 0.05 in 26; both in 0; rate-group p < 0.05 where region p < 1e-7: 2
mean_rate_state: readings 32; region p < 1e-7 in 6; rate-group p > 0.05 in 17; both in 0; rate-group p < 0.05 where region p < 1e-7: 6
mean_rate_wake: readings 32; region p < 1e-7 in 4; rate-group p > 0.05 in 17; both in 0; rate-group p < 0.05 where region p < 1e-7: 4
all: 96 readings; region p < 1e-7: 12 | rate-group p > 0.05: 60 | both: 0

Result: not reproduced. The rate-group effect is significant wherever the region effect reaches p < 1e-7. Of 96 readings (HD, rate threshold, pairs, rate measure, state), the region effect reaches p < 1e-7 in 12, all among pairs closer than 60 degrees, and in each of them the rate-group effect has p from 4.8e-14 to 0.0013. No reading has region p < 1e-7 together with rate-group p > 0.05. Over all pairs the region effect is not found (smallest p 0.029). The rate group now uses the peak rate of the HD reading's own fit, and the mean rate of the state tested (waking rates as a variant).

In [26]:
print("ensembles:", ENS.groupby("region").size().to_dict())
CO = COH[~COH.ref.str.endswith("_shuffled")]
T3B = CO.pivot_table(index=["region", "ref", "dist"], columns="state", values=["mean", "median"], aggfunc="median")
print("median over ensembles of the per-ensemble summary of coherence:")
print(T3B.round(3).to_string())
lo = CO.groupby(["ref", "dist", "state", "region"])[["mean", "median"]].min()
print("\nminimum over ensembles:")
print(lo.unstack(["state", "region"]).round(3).to_string())
print("ensembles with coherence above 0.05 (fraction), by reading:")
print(CO.assign(ok_mean=CO["mean"] > 0.05, ok_median=CO["median"] > 0.05).groupby(["ref", "dist", "state", "region"])[["ok_mean", "ok_median"]].mean().unstack(["state", "region"]).round(2).to_string())
SH = COH[COH.ref.str.endswith("_shuffled")]
print("\nnegative control: the same packets against the expected packet at decoded angles permuted across time bins;"
      " median over ensembles:")
print(SH.pivot_table(index=["region", "ref", "dist"], columns="state", values=["mean", "median"], aggfunc="median").round(3).to_string())
print("fraction of ensembles whose shuffled coherence exceeds 0.05 (mean summary):")
print(SH.assign(ok=SH["mean"] > 0.05).groupby(["ref", "dist", "region"]).ok.mean().unstack("region").round(2).to_string())
ensembles: {'ADn': 25, 'PoS': 5}
median over ensembles of the per-ensemble summary of coherence:
                      mean               median              
state                  REM    SWS   wake    REM    SWS   wake
region ref     dist                                          
ADn    actual  corr  0.614  0.463  0.750  0.646  0.443  0.820
               euc   0.657  0.532  0.775  0.739  0.552  0.854
       decoded corr  0.322  0.193  0.502  0.249  0.082  0.500
               euc   0.354  0.223  0.502  0.287  0.131  0.501
       random  corr  0.908  0.846  0.959  0.947  0.904  0.976
               euc   0.936  0.909  0.966  0.967  0.946  0.982
PoS    actual  corr  0.548  0.379  0.673  0.538  0.288  0.712
               euc   0.624  0.429  0.747  0.676  0.320  0.852
       decoded corr  0.355  0.332  0.503  0.284  0.394  0.500
               euc   0.378  0.257  0.504  0.320  0.169  0.503
       random  corr  0.825  0.527  0.869  0.911  0.542  0.943
               euc   0.866  0.775  0.914  0.939  0.747  0.962

minimum over ensembles:
               mean                                    median                                   
state           REM           SWS          wake           REM           SWS          wake       
region          ADn    PoS    ADn    PoS    ADn    PoS    ADn    PoS    ADn    PoS    ADn    PoS
ref     dist                                                                                    
actual  corr  0.510  0.504  0.334  0.225  0.687  0.645  0.505  0.501  0.263  0.085  0.738  0.698
        euc   0.534  0.544  0.396  0.382  0.716  0.706  0.572  0.626  0.322  0.250  0.795  0.797
decoded corr  0.198  0.322  0.099  0.292  0.490  0.496  0.095  0.248  0.020  0.315  0.483  0.486
        euc   0.252  0.369  0.142  0.173  0.492  0.497  0.123  0.299  0.041  0.060  0.485  0.494
random  corr  0.836  0.772  0.754  0.378  0.904  0.799  0.908  0.880  0.835  0.155  0.955  0.892
        euc   0.806  0.680  0.748  0.689  0.933  0.835  0.942  0.871  0.869  0.632  0.972  0.926
ensembles with coherence above 0.05 (fraction), by reading:
             ok_mean                          ok_median                          
state            REM       SWS      wake            REM        SWS      wake     
region           ADn  PoS  ADn  PoS  ADn  PoS       ADn  PoS   ADn  PoS  ADn  PoS
ref     dist                                                                     
actual  corr     1.0  1.0  1.0  1.0  1.0  1.0       1.0  1.0  1.00  1.0  1.0  1.0
        euc      1.0  1.0  1.0  1.0  1.0  1.0       1.0  1.0  1.00  1.0  1.0  1.0
decoded corr     1.0  1.0  1.0  1.0  1.0  1.0       1.0  1.0  0.83  1.0  1.0  1.0
        euc      1.0  1.0  1.0  1.0  1.0  1.0       1.0  1.0  0.96  1.0  1.0  1.0
random  corr     1.0  1.0  1.0  1.0  1.0  1.0       1.0  1.0  1.00  1.0  1.0  1.0
        euc      1.0  1.0  1.0  1.0  1.0  1.0       1.0  1.0  1.00  1.0  1.0  1.0

negative control: the same packets against the expected packet at decoded angles permuted across time bins; median over ensembles:
                               mean               median              
state                           REM    SWS   wake    REM    SWS   wake
region ref              dist                                          
ADn    actual_shuffled  corr  0.118  0.114  0.114  0.009  0.011  0.003
                        euc   0.119  0.129  0.122  0.029  0.046  0.017
       decoded_shuffled corr  0.045  0.058  0.045  0.000  0.000  0.000
                        euc   0.030  0.028  0.037  0.000  0.000  0.000
       random_shuffled  corr  0.511  0.515  0.497  0.517  0.533  0.499
                        euc   0.531  0.577  0.499  0.558  0.609  0.499
PoS    actual_shuffled  corr  0.189  0.184  0.200  0.086  0.114  0.082
                        euc   0.237  0.206  0.242  0.139  0.201  0.162
       decoded_shuffled corr  0.111  0.220  0.127  0.000  0.122  0.000
                        euc   0.088  0.113  0.087  0.007  0.013  0.004
       random_shuffled  corr  0.487  0.350  0.497  0.483  0.246  0.498
                        euc   0.514  0.529  0.501  0.490  0.593  0.501
fraction of ensembles whose shuffled coherence exceeds 0.05 (mean summary):
region                  ADn  PoS
ref              dist           
actual_shuffled  corr  1.00  1.0
                 euc   1.00  1.0
decoded_shuffled corr  0.46  1.0
                 euc   0.08  1.0
random_shuffled  corr  1.00  1.0
                 euc   1.00  1.0

Result: reproduced. At the decoder's windows, the median over ensembles of the coherence exceeds 0.05 in both structures and all three states under every reading of distance, reference vectors and summary. The lowest is 0.082 (ADn, SWS, decoded-HD references, correlation distance, median over bins). Every ensemble passes with the mean summary. The shuffled control shows which readings can fail: packets compared with the expected packet at permuted decoded angles still score 0.25 to 0.61 with random references and 0.11 to 0.24 with actual-HD references and the mean summary (medians over ensembles), above 0.05, so those readings cannot fail. With decoded-HD references and the median summary the shuffled control is 0.000 in ADn and 0.000 to 0.122 in PoS, against 0.082 to 0.503 for the actual angles, so the result rests on that reading. Other windows were not run.

Noise correlations and linear decoding: fig4b-noise-correlations, fig4c-noise-adn-vs-pos, fig4d-ole-near-bayesian, fig4e-ole-covariance¶

Noise correlation (Methods, Cross-correlation under the hypothesis of independent firing rate coding): spike-train minus intensity-function cross-correlation, 10 ms bins, 1/N sum of products, waking bins with head direction; readings (n-a) mean over -50 to +50 ms or the 0 lag, (n-b) raw (Hz^2) or divided by the product of mean rates.

In [27]:
rows = []
for rd in ("a", "b"):
    for rate in ("a", "b"):
        P_ = hdpairs(rd, rate)
        for meas in ("noise_avg_raw", "noise_0_raw", "noise_avg_norm", "noise_0_norm"):
            for grp, c in (("ADn-ADn", P_[P_.kind == "ADn-ADn"]), ("pooled", P_)):
                o = c["off_" + rd]
                z = c[o <= 15][meas].dropna(); s60 = c[(o >= 45) & (o <= 75)][meas].dropna(); far = c[o > 90][meas].dropna()
                p0 = stats.wilcoxon(z).pvalue if len(z) > 5 else np.nan
                p6 = stats.wilcoxon(s60).pvalue if len(s60) > 5 else np.nan
                rows.append(dict(hd=rd, rate=rate, measure=meas, pairs=grp, n0=len(z), med0=z.median(), p0=p0,
                                 n60=len(s60), med60=s60.median(), p60=p6, mean_far=far.mean(),
                                 holds=(z.median() > 0) & (p0 < 0.05) & (s60.median() < 0) & (p6 < 0.05)))
F4B = pd.DataFrame(rows)
print(F4B.to_string(index=False, float_format=lambda x: f"{x:.3g}"))
g = F4B.groupby(["hd", "rate", "measure"]).holds.all()
print("\nreadings where both ADn-ADn and pooled pairs hold:", g[g].index.tolist())
hd rate        measure   pairs  n0  med0       p0  n60  med60      p60  mean_far  holds
 a    a  noise_avg_raw ADn-ADn  75  12.3 1.33e-13  170  -4.44  3.3e-24      -1.2   True
 a    a  noise_avg_raw  pooled 102  8.78 1.03e-17  225  -3.56 5.45e-28     -1.04   True
 a    a    noise_0_raw ADn-ADn  75  11.6 3.05e-12  170  -5.17 1.34e-25     -1.62   True
 a    a    noise_0_raw  pooled 102  7.03 1.18e-15  225   -3.9 2.08e-29     -1.35   True
 a    a noise_avg_norm ADn-ADn  75 0.891 1.33e-13  170 -0.301 1.07e-23   -0.0212   True
 a    a noise_avg_norm  pooled 102 0.878 8.15e-18  225 -0.267 9.37e-26   -0.0217   True
 a    a   noise_0_norm ADn-ADn  75 0.817 5.96e-12  170  -0.34 1.24e-24    -0.036   True
 a    a   noise_0_norm  pooled 102 0.811 8.28e-16  225 -0.313 4.53e-26    -0.034   True
 a    b  noise_avg_raw ADn-ADn 101  7.79 1.24e-17  217  -3.54 1.46e-30    -0.982   True
 a    b  noise_avg_raw  pooled 169  4.55 2.28e-26  355  -1.84 1.56e-40    -0.671   True
 a    b    noise_0_raw ADn-ADn 101  5.78 7.17e-16  217  -4.12 1.45e-32     -1.39   True
 a    b    noise_0_raw  pooled 169   3.8  8.7e-23  355  -2.11 3.98e-42    -0.917   True
 a    b noise_avg_norm ADn-ADn 101 0.887 8.49e-18  217 -0.297 2.15e-30   -0.0236   True
 a    b noise_avg_norm  pooled 169 0.796 1.51e-24  355  -0.25 3.15e-37   -0.0123   True
 a    b   noise_0_norm ADn-ADn 101 0.771 1.21e-15  217 -0.339 2.69e-32   -0.0363   True
 a    b   noise_0_norm  pooled 169 0.642 2.42e-20  355   -0.3 1.78e-38   -0.0267   True
 b    a  noise_avg_raw ADn-ADn  91  12.6 1.32e-16  185  -5.67 3.05e-28    -0.975   True
 b    a  noise_avg_raw  pooled 147  7.67 1.46e-25  295  -3.01 9.69e-41    -0.775   True
 b    a    noise_0_raw ADn-ADn  91  10.8    1e-15  185  -6.56 9.09e-29     -1.51   True
 b    a    noise_0_raw  pooled 147  5.95 4.36e-24  295  -3.57 8.52e-41     -1.13   True
 b    a noise_avg_norm ADn-ADn  91 0.905 1.32e-16  185 -0.309 4.01e-28  -0.00637   True
 b    a noise_avg_norm  pooled 147 0.814 2.29e-25  295 -0.257 4.28e-38  -0.00187   True
 b    a   noise_0_norm ADn-ADn  91 0.823 2.54e-15  185  -0.34 3.51e-27   -0.0331   True
 b    a   noise_0_norm  pooled 147 0.735 1.76e-23  295 -0.283 1.84e-36   -0.0209   True
 b    b  noise_avg_raw ADn-ADn 113  9.41 3.56e-20  236     -4 6.09e-36    -0.827   True
 b    b  noise_avg_raw  pooled 236  4.92 4.39e-39  499   -1.1 1.07e-60    -0.464   True
 b    b    noise_0_raw ADn-ADn 113   6.8 4.44e-19  236  -4.42 1.94e-36     -1.33   True
 b    b    noise_0_raw  pooled 236  4.09  4.9e-36  499  -1.29 3.14e-60    -0.722   True
 b    b noise_avg_norm ADn-ADn 113 0.891 3.04e-20  236 -0.306 1.41e-35   -0.0114   True
 b    b noise_avg_norm  pooled 236 0.752 7.84e-38  499 -0.224 2.38e-55   0.00848   True
 b    b   noise_0_norm ADn-ADn 113 0.817 1.41e-18  236 -0.344 1.72e-35   -0.0355   True
 b    b   noise_0_norm  pooled 236  0.64 5.69e-33  499 -0.257 8.37e-52  -0.00798   True

readings where both ADn-ADn and pooled pairs hold: [('a', 'a', 'noise_0_norm'), ('a', 'a', 'noise_0_raw'), ('a', 'a', 'noise_avg_norm'), ('a', 'a', 'noise_avg_raw'), ('a', 'b', 'noise_0_norm'), ('a', 'b', 'noise_0_raw'), ('a', 'b', 'noise_avg_norm'), ('a', 'b', 'noise_avg_raw'), ('b', 'a', 'noise_0_norm'), ('b', 'a', 'noise_0_raw'), ('b', 'a', 'noise_avg_norm'), ('b', 'a', 'noise_avg_raw'), ('b', 'b', 'noise_0_norm'), ('b', 'b', 'noise_0_raw'), ('b', 'b', 'noise_avg_norm'), ('b', 'b', 'noise_avg_raw')]

Result: reproduced. In every reading (HD, rate, lag and scale), the noise correlation is above 0 for pairs within 15 degrees and below 0 for pairs at 60 plus or minus 15 degrees, in ADn-ADn pairs and in pooled pairs. Every Wilcoxon p is below 1e-11. Under hd-a, rate-a and the -50 to +50 ms normalised reading, the ADn-ADn medians are 0.89 and -0.30, and beyond 90 degrees the mean is -0.02.

In [28]:
rows = []
for rd in ("a", "b"):
    for rate in ("a", "b"):
        P_ = hdpairs(rd, rate)
        for meas in ("noise_avg_raw", "noise_0_raw", "noise_avg_norm", "noise_0_norm"):
            for grp, sel in (("0", P_["off_" + rd] <= 15), ("60", (P_["off_" + rd] >= 45) & (P_["off_" + rd] <= 75))):
                c = P_[sel]
                g_ = [c[c.kind == k][meas].dropna() for k in ("ADn-ADn", "ADn-PoS", "PoS-PoS")]
                if min(len(x) for x in g_) < 2:
                    rows.append(dict(hd=rd, rate=rate, measure=meas, group=grp, n=[len(x) for x in g_], p=np.nan))
                    continue
                kw = stats.kruskal(*g_)
                meds = [x.median() for x in g_]
                ext = (np.argmax(meds) == 0) if grp == "0" else (np.argmin(meds) == 0)
                rows.append(dict(hd=rd, rate=rate, measure=meas, group=grp, n=[len(x) for x in g_],
                                 med_adn=meds[0], med_mixed=meds[1], med_pos=meds[2], p=kw.pvalue, adn_most_extreme=ext))
F4C = pd.DataFrame(rows)
print(F4C.to_string(index=False, float_format=lambda x: f"{x:.3g}"))
print("expected pairs at 0 / 60 deg: ADn-ADn 96 / 200, ADn-PoS 77 / 157, PoS-PoS 29 / 57")
ok = F4C.assign(ok=(F4C.p < 0.05) & F4C.adn_most_extreme.fillna(False).astype(bool)).groupby(["hd", "rate", "measure"]).ok.sum()
print("groups (of 2) passing per reading:", ok.to_dict())
hd rate        measure group              n  med_adn  med_mixed  med_pos        p  adn_most_extreme
 a    a  noise_avg_raw     0    [75, 25, 2]     12.3       4.55     1.64  0.00803              True
 a    a  noise_avg_raw    60   [170, 47, 8]    -4.44      -1.07     0.04 7.59e-07              True
 a    a    noise_0_raw     0    [75, 25, 2]     11.6       4.59     1.01   0.0775              True
 a    a    noise_0_raw    60   [170, 47, 8]    -5.17      -1.45   -0.252 7.92e-08              True
 a    a noise_avg_norm     0    [75, 25, 2]    0.891      0.857     1.43    0.954             False
 a    a noise_avg_norm    60   [170, 47, 8]   -0.301     -0.204   0.0229 4.57e-05              True
 a    a   noise_0_norm     0    [75, 25, 2]    0.817      0.741     1.09    0.943             False
 a    a   noise_0_norm    60   [170, 47, 8]    -0.34     -0.199   -0.175 8.41e-06              True
 a    b  noise_avg_raw     0  [101, 49, 19]     7.79       2.94    0.455 8.54e-09              True
 a    b  noise_avg_raw    60 [217, 107, 31]    -3.54     -0.656   -0.147 2.28e-13              True
 a    b    noise_0_raw     0  [101, 49, 19]     5.78       3.46   0.0811  4.7e-07              True
 a    b    noise_0_raw    60 [217, 107, 31]    -4.12     -0.789   -0.245 1.17e-15              True
 a    b noise_avg_norm     0  [101, 49, 19]    0.887       0.58     0.21 0.000395              True
 a    b noise_avg_norm    60 [217, 107, 31]   -0.297     -0.181   -0.171 4.53e-07              True
 a    b   noise_0_norm     0  [101, 49, 19]    0.771      0.543   0.0666 0.000857              True
 a    b   noise_0_norm    60 [217, 107, 31]   -0.339     -0.197   -0.247 3.13e-08              True
 b    a  noise_avg_raw     0   [91, 46, 10]     12.6       4.28     2.71 5.77e-07              True
 b    a  noise_avg_raw    60  [185, 85, 25]    -5.67      -1.33   -0.315 1.83e-13              True
 b    a    noise_0_raw     0   [91, 46, 10]     10.8       3.59     1.77    3e-05              True
 b    a    noise_0_raw    60  [185, 85, 25]    -6.56      -1.37   -0.421 2.04e-14              True
 b    a noise_avg_norm     0   [91, 46, 10]    0.905      0.561    0.558  0.00652              True
 b    a noise_avg_norm    60  [185, 85, 25]   -0.309       -0.2   -0.139 1.06e-08              True
 b    a   noise_0_norm     0   [91, 46, 10]    0.823      0.539    0.324    0.165              True
 b    a   noise_0_norm    60  [185, 85, 25]    -0.34     -0.199   -0.163 2.22e-10              True
 b    b  noise_avg_raw     0  [113, 86, 37]     9.41        4.2     1.05 6.09e-13              True
 b    b  noise_avg_raw    60 [236, 181, 82]       -4     -0.694  -0.0865 5.54e-28              True
 b    b    noise_0_raw     0  [113, 86, 37]      6.8       3.59    0.586 8.05e-11              True
 b    b    noise_0_raw    60 [236, 181, 82]    -4.42     -0.732   -0.214 1.85e-29              True
 b    b noise_avg_norm     0  [113, 86, 37]    0.891      0.553     0.58 2.64e-05              True
 b    b noise_avg_norm    60 [236, 181, 82]   -0.306     -0.175  -0.0897 3.26e-19              True
 b    b   noise_0_norm     0  [113, 86, 37]    0.817      0.528    0.294   0.0024              True
 b    b   noise_0_norm    60 [236, 181, 82]   -0.344      -0.19   -0.128    1e-19              True
expected pairs at 0 / 60 deg: ADn-ADn 96 / 200, ADn-PoS 77 / 157, PoS-PoS 29 / 57
groups (of 2) passing per reading: {('a', 'a', 'noise_0_norm'): 1, ('a', 'a', 'noise_0_raw'): 1, ('a', 'a', 'noise_avg_norm'): 1, ('a', 'a', 'noise_avg_raw'): 2, ('a', 'b', 'noise_0_norm'): 2, ('a', 'b', 'noise_0_raw'): 2, ('a', 'b', 'noise_avg_norm'): 2, ('a', 'b', 'noise_avg_raw'): 2, ('b', 'a', 'noise_0_norm'): 1, ('b', 'a', 'noise_0_raw'): 2, ('b', 'a', 'noise_avg_norm'): 2, ('b', 'a', 'noise_avg_raw'): 2, ('b', 'b', 'noise_0_norm'): 2, ('b', 'b', 'noise_0_raw'): 2, ('b', 'b', 'noise_avg_norm'): 2, ('b', 'b', 'noise_avg_raw'): 2}

Result: reproduced. Under hd-a and rate-b, with every lag and scale reading, the Kruskal-Wallis test across the three pair types gives p < 0.001 at 0 and at 60 degrees, with ADn-ADn pairs the most extreme. The raw 50 ms reading gives p = 8.5e-9 and 2.3e-13. At 0 degrees there are 101 ADn-ADn, 49 ADn-PoS and 19 PoS-PoS pairs, against 96, 77 and 29. At 60 degrees there are 217, 107 and 31, against 200, 157 and 57.

In [29]:
# OLE (hd.ole_fit, hd.ole_errors; assumed estimator, see the claim's criterion):
# covariance OLE, Q = <r r^T> of the smoothed counts; signal OLE, adopted reading
# "sig", Q = <F F^T> of the tuning curves read at the head direction off the
# diagonal, with the observed variances on it (independent neurons, the usual
# signal-only OLE); variant "sig2", Q = <F F^T> throughout, whose decoder errs
# near or beyond chance (90 deg) in some ensembles. Ensembles of HD cells under
# (hd-a) and (hd-b), sessions with at least 6 in a structure.
W_ = hd.OLE_WINDOWS
E4 = ENS_ALL.copy()
for k in ("ole_cov", "ole_sig", "ole_sig2", "bayes"):
    E4[k + "_min"] = E4[[f"{k}_{w}" for w in W_]].min(axis=1)
    E4[k + "_argmin"] = E4[[f"{k}_{w}" for w in W_]].values.argmin(axis=1)
print(E4[["reading", "session", "region", "n_hd", "ole_cov_min", "ole_sig_min", "ole_sig2_min", "bayes_min"]].round(2).to_string(index=False))
print("windows (s):", [float(w) for w in W_])
print("signal OLE readings: sig, Q = <F F^T> off the diagonal with the observed variances on it (adopted); "
      "sig2, Q = <F F^T> throughout (variant)")
rows = []
for rd, er in E4.groupby("reading"):
    for sig in ("ole_sig", "ole_sig2"):
        for reg, e in er.groupby("region"):
            w = stats.wilcoxon(e.ole_cov_min, e[sig + "_min"])
            rows.append(dict(hd=rd, signal=sig, region=reg, n=len(e), cov=e.ole_cov_min.median(), signal_err=e[sig + "_min"].median(),
                             signal_max=e[sig + "_min"].max(), bayes=e.bayes_min.median(),
                             cov_better=int((e.ole_cov_min < e[sig + "_min"]).sum()), wilcoxon_p=w.pvalue,
                             cov_over_bayes=e.ole_cov_min.median() / e.bayes_min.median()))
F4D = pd.DataFrame(rows)
print(F4D.to_string(index=False, float_format=lambda x: f"{x:.3g}"))
for (rd, sig), f in F4D.groupby(["hd", "signal"]):
    first = bool((f.wilcoxon_p < 0.05).all() and (f["cov"] < f.signal_err).all())
    second = bool((f.cov_over_bayes <= 1.25).all())
    print(f"{rd}, {sig}: covariance OLE better with p < 0.05 in both structures {first}; within 25% of Bayes in both {second}")
for (rd, reg), e in E4.groupby(["reading", "region"]):
    print(f"{rd} {reg}: per-ensemble cov / Bayes median {(e.ole_cov_min / e.bayes_min).median():.3f}, range "
          f"{(e.ole_cov_min / e.bayes_min).min():.3f} to {(e.ole_cov_min / e.bayes_min).max():.3f}")
print("expected ensembles: 20 ADn, 8 PoS")
reading        session region  n_hd  ole_cov_min  ole_sig_min  ole_sig2_min  bayes_min
   hd-a Mouse12-120806    ADn    20        12.21        13.44         99.03      12.03
   hd-b Mouse12-120806    ADn    19        12.84        14.15        101.39      12.33
   hd-a Mouse12-120807    ADn    13        13.03        13.22         99.47      10.83
   hd-b Mouse12-120807    ADn    13        13.03        13.22         99.47      10.83
   hd-a Mouse12-120808    ADn    11        10.63        10.86         47.68       7.74
   hd-b Mouse12-120808    ADn    11        10.63        10.86         47.68       7.74
   hd-a Mouse12-120809    ADn    13         9.64         9.50         78.21       8.11
   hd-b Mouse12-120809    ADn    13         9.64         9.50         78.21       8.11
   hd-a Mouse12-120810    ADn     9        20.06        19.38         45.97      11.41
   hd-b Mouse12-120810    ADn    10        17.62        18.56         52.49      11.14
   hd-b Mouse17-130128    ADn     6        26.31        26.16         49.95      16.39
   hd-a Mouse17-130129    ADn     8        15.20        15.39        103.31      11.07
   hd-b Mouse17-130129    ADn     9        15.21        15.41        103.33      11.08
   hd-a Mouse17-130130    ADn    10        13.98        14.40         77.79      12.03
   hd-b Mouse17-130130    ADn    10        13.98        14.40         77.79      12.03
   hd-a Mouse17-130131    ADn     7        18.91        19.20         41.59      13.33
   hd-b Mouse17-130131    ADn     6        18.94        19.06         28.78      13.38
   hd-a Mouse17-130201    ADn     6        15.40        15.56         17.07      12.11
   hd-b Mouse17-130201    ADn     6        15.40        15.56         17.07      12.11
   hd-b Mouse17-130203    ADn     6        24.05        25.42         31.21      14.19
   hd-a Mouse20-130517    ADn     6        14.81        14.74         17.89      11.58
   hd-b Mouse20-130517    ADn     7        14.59        14.50         19.88      10.83
   hd-a Mouse24-131216    ADn     8        18.59        18.53         41.77      13.35
   hd-b Mouse24-131216    ADn     8        18.59        18.53         41.77      13.35
   hd-a Mouse24-131217    ADn     8        16.10        16.78         23.56       9.78
   hd-b Mouse24-131217    ADn     9        14.02        14.31         21.00       8.92
   hd-a Mouse24-131218    ADn     9        15.15        14.99         29.34       8.92
   hd-b Mouse24-131218    ADn     9        15.15        14.99         29.34       8.92
   hd-a Mouse25-140123    PoS     8        15.98        16.80         39.44      14.39
   hd-b Mouse25-140123    PoS     7        17.38        17.66         45.34      15.75
   hd-b Mouse25-140129    PoS     8        31.47        31.36         45.38      16.15
   hd-a Mouse25-140130    ADn     8         9.80         9.99         27.72       6.84
   hd-b Mouse25-140130    ADn     9         9.44         9.55         27.74       6.81
   hd-b Mouse25-140130    PoS     7        18.51        18.71         25.36      13.23
   hd-a Mouse25-140131    ADn     9        11.26        11.43         28.48       8.06
   hd-a Mouse25-140131    PoS     8        20.96        20.96         30.69      14.80
   hd-b Mouse25-140131    ADn     9        11.26        11.43         28.48       8.06
   hd-b Mouse25-140131    PoS    11        18.15        18.18         52.79      11.58
   hd-a Mouse25-140203    ADn     8        10.93        10.86         44.54       8.72
   hd-b Mouse25-140203    ADn     8        10.93        10.86         44.54       8.72
   hd-b Mouse25-140203    PoS     6        27.89        28.94         83.62      16.72
   hd-a Mouse25-140204    ADn    10        10.97        10.66         66.85       8.50
   hd-b Mouse25-140204    ADn    10        10.97        10.66         66.85       8.50
   hd-b Mouse25-140204    PoS     9        23.72        24.04         45.30      13.84
   hd-a Mouse25-140205    ADn     8        12.05        11.98         20.19       9.73
   hd-b Mouse25-140205    ADn     8        12.05        11.98         20.19       9.73
   hd-b Mouse25-140205    PoS     6        28.14        28.37         37.70      23.41
   hd-a Mouse25-140206    ADn     6        13.68        13.18         25.57       9.44
   hd-b Mouse25-140206    ADn     7        13.06        12.94         21.97       8.86
   hd-a Mouse28-140310    ADn    10        14.34        13.84         44.01      10.62
   hd-a Mouse28-140310    PoS     6        37.09        37.14         49.63      28.30
   hd-b Mouse28-140310    ADn    11        14.44        13.86         68.43      10.51
   hd-b Mouse28-140310    PoS     6        31.84        32.16         42.42      26.36
   hd-a Mouse28-140311    ADn    10        12.12        12.45         48.99       9.67
   hd-b Mouse28-140311    ADn    12        12.11        12.18         77.60       9.56
   hd-b Mouse28-140311    PoS     8        30.12        29.75         63.32      14.43
   hd-a Mouse28-140312    ADn    14        12.39        13.03         95.73      10.27
   hd-a Mouse28-140312    PoS    10        27.59        28.04         78.80      25.16
   hd-b Mouse28-140312    ADn    15        12.14        12.69         94.29      10.25
   hd-b Mouse28-140312    PoS    11        27.79        28.39         79.73      23.46
   hd-a Mouse28-140313    ADn    15        10.83        10.71         88.16      10.03
   hd-a Mouse28-140313    PoS     9        18.31        18.86         66.90      13.74
   hd-b Mouse28-140313    ADn    17        10.72        10.87         98.21       9.98
   hd-b Mouse28-140313    PoS    16        15.55        16.12         96.13      11.53
   hd-a Mouse28-140317    ADn    12        12.98        13.54         87.08      12.83
   hd-b Mouse28-140317    ADn    13        13.10        13.81         92.89      12.69
   hd-a Mouse28-140318    ADn    13        12.23        12.31         90.79      12.14
   hd-b Mouse28-140318    ADn    14        12.24        12.44         94.52      12.13
windows (s): [0.01, 0.02, 0.05, 0.1, 0.2, 0.3, 0.5, 1.0]
signal OLE readings: sig, Q = <F F^T> off the diagonal with the observed variances on it (adopted); sig2, Q = <F F^T> throughout (variant)
  hd   signal region  n  cov  signal_err  signal_max  bayes  cov_better  wilcoxon_p  cov_over_bayes
hd-a  ole_sig    ADn 25   13        13.2        19.4   10.3          14       0.156            1.26
hd-a  ole_sig    PoS  5   21          21        37.1   14.8           4       0.125            1.42
hd-a ole_sig2    ADn 25   13          46         103   10.3          25    5.96e-08            1.26
hd-a ole_sig2    PoS  5   21        49.6        78.8   14.8           5      0.0625            1.42
hd-b  ole_sig    ADn 27 13.1        13.8        26.2   10.5          17      0.0187            1.24
hd-b  ole_sig    PoS 11 27.8        28.4        32.2   15.8           9       0.042            1.76
hd-b ole_sig2    ADn 27 13.1        49.9         103   10.5          27    1.49e-08            1.24
hd-b ole_sig2    PoS 11 27.8        45.4        96.1   15.8          11    0.000977            1.76
hd-a, ole_sig: covariance OLE better with p < 0.05 in both structures False; within 25% of Bayes in both False
hd-a, ole_sig2: covariance OLE better with p < 0.05 in both structures False; within 25% of Bayes in both False
hd-b, ole_sig: covariance OLE better with p < 0.05 in both structures True; within 25% of Bayes in both False
hd-b, ole_sig2: covariance OLE better with p < 0.05 in both structures True; within 25% of Bayes in both False
hd-a ADn: per-ensemble cov / Bayes median 1.278, range 1.007 to 1.758
hd-a PoS: per-ensemble cov / Bayes median 1.311, range 1.096 to 1.417
hd-b ADn: per-ensemble cov / Bayes median 1.347, range 1.009 to 1.697
hd-b PoS: per-ensemble cov / Bayes median 1.399, range 1.104 to 2.088
expected ensembles: 20 ADn, 8 PoS

Result: partially reproduced under (hd-b); not reproduced under (hd-a). With the adopted signal OLE (observed variances on the diagonal of Q) and hd-a ensembles, the covariance OLE barely beats the signal OLE (median minimum error 12.98 against 13.22 degrees in ADn, better in 14 of 25 ensembles, Wilcoxon p = 0.16; PoS 20.96 against 20.96, p = 0.13, 5 ensembles), so the first part fails. With hd-b ensembles (27 ADn, 11 PoS) it holds in both structures: 13.06 against 13.81 degrees in ADn (17 of 27, p = 0.019) and 27.79 against 28.37 in PoS (9 of 11, p = 0.042). The covariance OLE errors are 1.26 (ADn) and 1.42 (PoS) times the Bayesian decoder's under hd-a, and 1.24 and 1.76 under hd-b, so the second part fails in PoS under both (ADn is within the margin under hd-b only). With the variant signal Q (tuning curves throughout), whose signal decoder errs by up to 103 degrees under both HD readings, beyond the 90 degrees of chance, the first part holds in ADn under both readings and in PoS under hd-b (p = 0.001) but not under hd-a (p = 0.0625, the floor for 5 pairs). So under (hd-b) the first part holds in both structures with either signal Q, and the criterion makes the claim partially reproduced; under (hd-a) it is not reproduced with either. The outcome is partially reproduced, the change proposed after round 2 and agreed in the third verification round. The gain in ADn is about 1% of the error, far from the paper's "approximately 50%", which fig4e-ole-covariance tests. The outcome rests on the estimator assumed here, as the paper defines none, and on the HD reading.

In [30]:
rows = []
for rd, er in E4.groupby("reading"):
    for sig in ("ole_sig", "ole_sig2"):
        r = er.ole_cov_min / er[sig + "_min"]
        for reg in ("ADn", "PoS"):
            rr = r[er.region == reg]
            print(f"{rd} {sig} {reg}: n {len(rr)}, median ratio cov/signal {rr.median():.3f}, range {rr.min():.3f} to {rr.max():.3f}")
        u = stats.mannwhitneyu(r[er.region == "ADn"], r[er.region == "PoS"], alternative="two-sided")
        print(f"{rd} {sig} Mann-Whitney ADn against PoS: U {u.statistic:.1f}, p {u.pvalue:.3g}; ADn median lower: "
              f"{r[er.region == 'ADn'].median() < r[er.region == 'PoS'].median()}")
print("readings: median ratio 0.5 (0.45 to 0.55) or 0.67 (0.60 to 0.73); expected 20 ADn and 8 PoS ensembles")
print("ensembles:", E4.groupby(["reading", "region"]).size().to_dict())
hd-a ole_sig ADn: n 25, median ratio cov/signal 0.990, range 0.908 to 1.038
hd-a ole_sig PoS: n 5, median ratio cov/signal 0.984, range 0.951 to 1.000
hd-a ole_sig Mann-Whitney ADn against PoS: U 83.0, p 0.275; ADn median lower: False
hd-a ole_sig2 ADn: n 25, median ratio cov/signal 0.247, range 0.123 to 0.902
hd-a ole_sig2 PoS: n 5, median ratio cov/signal 0.405, range 0.274 to 0.747
hd-a ole_sig2 Mann-Whitney ADn against PoS: U 37.0, p 0.169; ADn median lower: True
hd-b ole_sig ADn: n 27, median ratio cov/signal 0.988, range 0.908 to 1.042
hd-b ole_sig PoS: n 11, median ratio cov/signal 0.989, range 0.963 to 1.012
hd-b ole_sig Mann-Whitney ADn against PoS: U 156.0, p 0.822; ADn median lower: True
hd-b ole_sig2 ADn: n 27, median ratio cov/signal 0.245, range 0.109 to 0.902
hd-b ole_sig2 PoS: n 11, median ratio cov/signal 0.476, range 0.162 to 0.751
hd-b ole_sig2 Mann-Whitney ADn against PoS: U 91.0, p 0.0666; ADn median lower: True
readings: median ratio 0.5 (0.45 to 0.55) or 0.67 (0.60 to 0.73); expected 20 ADn and 8 PoS ensembles
ensembles: {('hd-a', 'ADn'): 25, ('hd-a', 'PoS'): 5, ('hd-b', 'ADn'): 27, ('hd-b', 'PoS'): 11}

Result: not reproduced. With the adopted signal OLE (observed variances on the diagonal), the median ratio of covariance to signal OLE error is 0.99 in ADn (range 0.91 to 1.04) and 0.98 in PoS under hd-a, and 0.99 and 0.99 under hd-b: the covariance OLE is about as good as the signal OLE, not 50% better, and ADn and PoS do not differ (Mann-Whitney p = 0.28 and 0.82). With the variant signal Q (tuning curves throughout), the ADn ratio is 0.25 (hd-a) or 0.25 (hd-b), outside both 0.45 to 0.55 and 0.60 to 0.73, as that signal decoder works poorly, and ADn against PoS gives p = 0.17 and 0.067. No reading gives either part. There are 25 ADn and 5 PoS ensembles under hd-a and 27 and 11 under hd-b, against 20 and 8. The outcome rests on the estimator assumed here.

Bayesian decoding: decoding-tracks-hd, fig5b-sleep-tuning-similar, fig5b-adn-decoded-tuning¶

In [31]:
print(ENS[["session", "region", "n_hd", "err_full", "err_cv"]].round(2).to_string(index=False))
for reg, e in ENS.groupby("region"):
    print(f"{reg}: n {len(e)}; median over ensembles of the median absolute error: whole-epoch tuning curves "
          f"{e.err_full.median():.2f} deg (max {e.err_full.max():.2f}), cross-validated {e.err_cv.median():.2f} deg (max {e.err_cv.max():.2f})")
print("threshold 30 deg; chance 90 deg; shifted head direction (data check) gives", piv.median().round(1).to_dict())
EB = ENS_ALL[ENS_ALL.reading == "hd-b"]
print("ensembles of hd-b cells (waking decoding only):")
print(EB[["session", "region", "n_hd", "err_full", "err_cv"]].round(2).to_string(index=False))
for reg, e in EB.groupby("region"):
    print(f"hd-b {reg}: n {len(e)}; median over ensembles of the median absolute error: whole-epoch tuning curves "
          f"{e.err_full.median():.2f} deg (max {e.err_full.max():.2f}), cross-validated {e.err_cv.median():.2f} deg (max {e.err_cv.max():.2f})")
       session region  n_hd  err_full  err_cv
Mouse12-120806    ADn    20     12.17   12.74
Mouse12-120807    ADn    13     10.58   11.20
Mouse12-120808    ADn    11      7.91    8.13
Mouse12-120809    ADn    13      9.52    9.67
Mouse12-120810    ADn     9     11.84   12.01
Mouse17-130129    ADn     8     11.04   11.13
Mouse17-130130    ADn    10     11.69   12.03
Mouse17-130131    ADn     7     12.99   13.33
Mouse17-130201    ADn     6     12.05   12.25
Mouse20-130517    ADn     6     11.36   11.67
Mouse24-131216    ADn     8     13.09   13.35
Mouse24-131217    ADn     8     10.50   10.67
Mouse24-131218    ADn     9      9.62    9.74
Mouse25-140123    PoS     8     13.62   14.70
Mouse25-140130    ADn     8      8.19    8.27
Mouse25-140131    ADn     9      9.42    9.52
Mouse25-140131    PoS     8     14.42   14.80
Mouse25-140203    ADn     8      8.87    8.99
Mouse25-140204    ADn    10      9.11    9.29
Mouse25-140205    ADn     8      9.59   10.00
Mouse25-140206    ADn     6      9.31    9.61
Mouse28-140310    ADn    10      9.45   10.85
Mouse28-140310    PoS     6     25.11   28.30
Mouse28-140311    ADn    10      9.66   10.08
Mouse28-140312    ADn    14     10.17   10.69
Mouse28-140312    PoS    10     23.26   25.48
Mouse28-140313    ADn    15     10.07   10.51
Mouse28-140313    PoS     9     13.23   13.74
Mouse28-140317    ADn    12     12.24   13.12
Mouse28-140318    ADn    13     11.69   12.29
ADn: n 25; median over ensembles of the median absolute error: whole-epoch tuning curves 10.17 deg (max 13.09), cross-validated 10.69 deg (max 13.35)
PoS: n 5; median over ensembles of the median absolute error: whole-epoch tuning curves 14.42 deg (max 25.11), cross-validated 14.80 deg (max 28.30)
threshold 30 deg; chance 90 deg; shifted head direction (data check) gives {-10.0: 75.7, -2.0: 38.4, -0.5: 16.6, 0.0: 10.8, 0.5: 18.0, 2.0: 38.3, 10.0: 77.2}
ensembles of hd-b cells (waking decoding only):
       session region  n_hd  err_full  err_cv
Mouse12-120806    ADn    19     12.35   12.96
Mouse12-120807    ADn    13     10.58   11.20
Mouse12-120808    ADn    11      7.91    8.13
Mouse12-120809    ADn    13      9.52    9.67
Mouse12-120810    ADn    10     11.50   11.70
Mouse17-130128    ADn     6     16.03   16.39
Mouse17-130129    ADn     9     11.05   11.15
Mouse17-130130    ADn    10     11.69   12.03
Mouse17-130131    ADn     6     13.06   13.38
Mouse17-130201    ADn     6     12.05   12.25
Mouse17-130203    ADn     6     13.77   14.19
Mouse20-130517    ADn     7     10.57   10.91
Mouse24-131216    ADn     8     13.09   13.35
Mouse24-131217    ADn     9      9.93   10.09
Mouse24-131218    ADn     9      9.62    9.74
Mouse25-140123    PoS     7     14.97   16.14
Mouse25-140129    PoS     8     15.36   16.15
Mouse25-140130    ADn     9      8.13    8.23
Mouse25-140130    PoS     7     12.77   13.23
Mouse25-140131    ADn     9      9.42    9.52
Mouse25-140131    PoS    11     11.42   11.72
Mouse25-140203    ADn     8      8.87    8.99
Mouse25-140203    PoS     6     16.18   16.72
Mouse25-140204    ADn    10      9.11    9.29
Mouse25-140204    PoS     9     13.50   13.84
Mouse25-140205    ADn     8      9.59   10.00
Mouse25-140205    PoS     6     25.77   26.38
Mouse25-140206    ADn     7      8.84    9.11
Mouse28-140310    ADn    11      9.16   10.70
Mouse28-140310    PoS     6     25.81   27.29
Mouse28-140311    ADn    12      9.48    9.92
Mouse28-140311    PoS     8     13.82   14.43
Mouse28-140312    ADn    15     10.14   10.68
Mouse28-140312    PoS    11     21.53   23.86
Mouse28-140313    ADn    17     10.04   10.49
Mouse28-140313    PoS    16     10.91   11.53
Mouse28-140317    ADn    13     12.20   12.95
Mouse28-140318    ADn    14     11.67   12.25
hd-b ADn: n 27; median over ensembles of the median absolute error: whole-epoch tuning curves 10.14 deg (max 16.03), cross-validated 10.70 deg (max 16.39)
hd-b PoS: n 11; median over ensembles of the median absolute error: whole-epoch tuning curves 14.97 deg (max 25.81), cross-validated 16.14 deg (max 27.29)

Result: reproduced. The median over ensembles of the median absolute decoding error is 10.2 degrees in 25 ADn ensembles (maximum 13.1) and 14.4 degrees in 5 PoS ensembles (maximum 25.1) with whole-epoch tuning curves of hd-a cells. Cross-validated, it is 10.7 and 14.8. With hd-b ensembles (27 ADn, 11 PoS) it is 10.1 and 15.0, or 10.7 and 16.1 cross-validated. All are under 30 degrees, against 76 to 77 degrees with the head direction shifted by 10 s.

In [32]:
D5 = DEC5B[DEC5B.hd_a.astype(bool)]
print(D5.groupby(["decoder", "target_region", "state"]).agg(n=("r_a", "size"), median_r_a=("r_a", "median"),
                                                              median_r_b=("r_b", "median")).round(3).to_string())
print("sessions:", D5.groupby("decoder").session.nunique().to_dict(), "| threshold median r >= 0.5")
print("by session, ADn-decoded PoS cells, median r_a per state:")
print(D5[D5.decoder == "ADn"].groupby(["session", "state"]).r_a.median().unstack().round(2).to_string())
                              n  median_r_a  median_r_b
decoder target_region state                            
ADn     PoS           REM    51       0.922       0.923
                      SWS    51       0.900       0.904
                      wake   64       0.983       0.980
PoS     ADn           REM    43       0.871       0.879
                      SWS    43       0.807       0.801
                      wake   52       0.931       0.928
sessions: {'ADn': 15, 'PoS': 5} | threshold median r >= 0.5
by session, ADn-decoded PoS cells, median r_a per state:
state            REM   SWS  wake
session                         
Mouse24-131216  0.95  0.81  0.99
Mouse24-131217  0.62  0.75  0.96
Mouse24-131218  0.92  0.89  0.99
Mouse25-140130  0.95  0.93  0.99
Mouse25-140131   NaN   NaN  0.99
Mouse25-140203  0.99  0.98  0.98
Mouse25-140204   NaN   NaN  0.99
Mouse25-140205  0.93  0.75  0.94
Mouse25-140206  0.83  0.51  0.85
Mouse28-140310  0.82  0.84  0.97
Mouse28-140311  0.79  0.91  0.99
Mouse28-140312  0.92  0.90  0.97
Mouse28-140313  0.96  0.94  0.99
Mouse28-140317  0.84  0.87  0.97
Mouse28-140318  0.94  0.90  0.91

Result: reproduced. The tuning curves against decoded HD correlate with the waking tuning curves with medians of 0.92 (REM), 0.90 (SWS) and 0.98 (waking) for 51 to 64 PoS HD cells decoded from ADn, and 0.87, 0.81 and 0.93 for 43 to 52 ADn HD cells decoded from PoS. Both bin readings give the same medians within 0.01. Every median is above 0.5.

In [33]:
for col in ("r_a", "r_b"):
    for st in ("wake", "SWS", "REM"):
        A = D5[(D5.decoder == "ADn") & (D5.state == st)][col].dropna()
        B = D5[(D5.decoder == "PoS") & (D5.state == st)][col].dropna()
        if len(A) and len(B):
            u = stats.mannwhitneyu(A, B, alternative="two-sided")
            print(f"{col} {st}: PoS cells (ADn decoded) n {len(A)} median {A.median():.3f}; ADn cells (PoS decoded) n {len(B)} "
                  f"median {B.median():.3f}; Mann-Whitney p {u.pvalue:.3g}")
print("expected 86 PoS and 92 ADn HD cells; paper p: wake < 1e-10, SWS 0.018, REM 3e-6")
r_a wake: PoS cells (ADn decoded) n 64 median 0.983; ADn cells (PoS decoded) n 52 median 0.931; Mann-Whitney p 7.04e-07
r_a SWS: PoS cells (ADn decoded) n 51 median 0.900; ADn cells (PoS decoded) n 43 median 0.807; Mann-Whitney p 0.000495
r_a REM: PoS cells (ADn decoded) n 51 median 0.922; ADn cells (PoS decoded) n 43 median 0.871; Mann-Whitney p 0.039
r_b wake: PoS cells (ADn decoded) n 64 median 0.980; ADn cells (PoS decoded) n 52 median 0.928; Mann-Whitney p 1.48e-07
r_b SWS: PoS cells (ADn decoded) n 51 median 0.904; ADn cells (PoS decoded) n 43 median 0.801; Mann-Whitney p 0.000467
r_b REM: PoS cells (ADn decoded) n 51 median 0.923; ADn cells (PoS decoded) n 43 median 0.879; Mann-Whitney p 0.042
expected 86 PoS and 92 ADn HD cells; paper p: wake < 1e-10, SWS 0.018, REM 3e-6

Result: reproduced. PoS cells decoded from ADn have higher correlations than ADn cells decoded from PoS in every state. Under reading (a), Mann-Whitney p = 7.0e-7 in waking, 5.0e-4 in SWS and 0.039 in REM; reading (b) gives 1.5e-7, 4.7e-4 and 0.042. The counts are 64 and 52 cells in waking, against 86 and 92.

Fast synchrony: fig6a-fast-oscillation, fig6b-adn-synchrony¶

Cross-correlograms of ADn HD cell pairs in 0.5 ms bins to +-50 ms (readings o-a, o-b), z-scored against the jitter null. The mean and s.d. of the jittered cross-correlogram (one train jittered uniformly by +-10 ms) are taken as the cross-correlogram convolved with a 20 ms box and its Poisson s.d. These are the expectation of the paper's 100 jitters, not the 100 jitters themselves (deviation). The power is from a complex Morlet transform (o-c), averaged over lags within +-25 ms.

In [34]:
FA = attach(FAST)
FA = FA[FA.hd_a1.astype(bool) & FA.hd_a2.astype(bool)]
rows = []
for shank in ("different shanks", "all pairs"):
    f = FA if shank == "all pairs" else FA[~FA.same_shank]
    for st, c in f.groupby("state"):
        pw = np.vstack(c.power.values).mean(0)
        sel = hd.FAST_FREQS > 80
        fpk = hd.FAST_FREQS[sel][np.argmax(pw[sel])]
        rows.append(dict(pairs=shank, state=st, n=len(c), peak_freq=fpk, in_117_176=117 <= fpk <= 176,
                         power_at_peak=pw[sel].max(), power_80=pw[hd.FAST_FREQS == 80][0], power_300=pw[-1]))
print(pd.DataFrame(rows).to_string(index=False, float_format=lambda x: f"{x:.3g}"))
fig, ax = plt.subplots(1, 2, figsize=(9, 3))
for i, shank in enumerate(("different shanks", "all pairs")):
    f = FA if shank == "all pairs" else FA[~FA.same_shank]
    for st, c in f.groupby("state"):
        ax[i].plot(hd.FAST_FREQS, np.vstack(c.power.values).mean(0), label=st)
    ax[i].set_title(shank); ax[i].set_xlabel("Hz")
ax[0].set_ylabel("mean power (z units^2)"); ax[0].legend(); plt.tight_layout(); plt.show()
           pairs state    n  peak_freq  in_117_176  power_at_peak  power_80  power_300
different shanks   REM  492        165        True          0.121    0.0537     0.0808
different shanks   SWS  492        175        True          0.476     0.157      0.368
different shanks  wake  492        165        True          0.267    0.0792     0.0878
       all pairs   REM 1239        300       False           0.15    0.0417       0.15
       all pairs   SWS 1239        285       False          0.672     0.181       0.67
       all pairs  wake 1320        300       False          0.225    0.0734      0.225

Result: reproduced. For ADn HD pairs on different shanks (492 per state), the mean power of the z-scored cross-correlograms above 80 Hz peaks at 165 Hz in waking, 175 Hz in SWS and 165 Hz in REM, all within 117 to 176 Hz. With same-shank pairs included, the peak moves to the top of the frequency grid (285 to 300 Hz).

In [35]:
rows = []
for amp in ("zpeak5", "z0"):
    for shank in ("different shanks", "all pairs"):
        f = FA if shank == "all pairs" else FA[~FA.same_shank]
        f = f.assign(grp=np.minimum((f.off_a // 30).astype(int), 5))
        for st in ("wake", "SWS", "REM", "pooled"):
            c = f if st == "pooled" else f[f.state == st]
            g_ = [c[c.grp == k][amp].values for k in range(6)]
            kw = stats.kruskal(*[x for x in g_ if len(x)])
            means = [x.mean() if len(x) else np.nan for x in g_]
            rows.append(dict(amplitude=amp, pairs=shank, state=st, n=len(c), p=kw.pvalue, mean_0_30=means[0],
                             mean_150_180=means[5], falls=means[0] > means[5],
                             monotonic=bool(np.all(np.diff(means) <= 0)), means=np.round(means, 2).tolist()))
print(pd.DataFrame(rows).to_string(index=False, float_format=lambda x: f"{x:.3g}"))
print("criterion: 'falls' is the mean of the first group above that of the last; 'monotonic' (not required) is shown beside it")
print("ADn HD pairs per state:", FA.groupby("state").size().to_dict(), "| expected 970")
amplitude            pairs  state    n        p  mean_0_30  mean_150_180  falls  monotonic                                      means
   zpeak5 different shanks   wake  492 1.38e-05       9.01          3.11   True      False       [9.01, 4.37, 3.18, 2.98, 3.98, 3.11]
   zpeak5 different shanks    SWS  492 5.05e-14       18.3          3.06   True      False      [18.27, 4.83, 3.51, 3.11, 3.88, 3.06]
   zpeak5 different shanks    REM  492  2.2e-06       7.49          2.72   True      False       [7.49, 3.26, 2.55, 2.72, 3.09, 2.72]
   zpeak5 different shanks pooled 1476  2.2e-24       11.6          2.96   True      False      [11.59, 4.15, 3.08, 2.94, 3.65, 2.96]
   zpeak5        all pairs   wake 1320 1.28e-30       7.51           3.2   True      False        [7.51, 4.51, 3.03, 2.86, 3.46, 3.2]
   zpeak5        all pairs    SWS 1239 3.46e-53       12.6          3.22   True      False      [12.59, 5.36, 3.69, 3.25, 3.67, 3.22]
   zpeak5        all pairs    REM 1239 9.35e-18       5.97          2.84   True      False        [5.97, 3.49, 2.76, 2.8, 3.12, 2.84]
   zpeak5        all pairs pooled 3798 2.35e-95       8.67          3.09   True      False       [8.67, 4.46, 3.16, 2.97, 3.42, 3.09]
       z0 different shanks   wake  492 3.97e-10       7.47         0.742   True      False        [7.47, 2.26, 1.3, 1.03, 1.89, 0.74]
       z0 different shanks    SWS  492 2.02e-11       16.5         0.984   True      False       [16.49, 3.03, 1.5, 1.23, 2.24, 0.98]
       z0 different shanks    REM  492 3.95e-08       5.95         0.614   True      False        [5.95, 1.51, 0.45, 0.78, 1.1, 0.61]
       z0 different shanks pooled 1476 7.95e-30       9.97          0.78   True      False       [9.97, 2.27, 1.08, 1.01, 1.74, 0.78]
       z0        all pairs   wake 1320 2.22e-18      -3.78        -0.724  False      False [-3.78, -2.89, -1.49, -0.79, -0.28, -0.72]
       z0        all pairs    SWS 1239  1.7e-12      -7.14         -2.72  False      False [-7.14, -5.55, -4.16, -3.04, -2.21, -2.72]
       z0        all pairs    REM 1239 3.63e-14      -2.21        -0.616  False      False [-2.21, -1.68, -1.25, -0.65, -0.38, -0.62]
       z0        all pairs pooled 3798 2.49e-35      -4.37         -1.34  False      False [-4.37, -3.36, -2.28, -1.48, -0.94, -1.34]
criterion: 'falls' is the mean of the first group above that of the last; 'monotonic' (not required) is shown beside it
ADn HD pairs per state: {'REM': 1239, 'SWS': 1239, 'wake': 1320} | expected 970

Result: reproduced. With the peak z within 5 ms and pairs on different shanks, the three states pooled give Kruskal-Wallis p = 2.2e-24 across 30 degree offset groups. The mean falls from 11.6 (0 to 30 degrees) to 3.0 (150 to 180 degrees), the fall the criterion asks for. In each state p < 0.05 with the same fall (waking p = 1.4e-5, SWS 5.1e-14, REM 2.2e-6). Waking alone does not reach 1e-10. The fall is not monotonic: in every state the mean rises again in the 120 to 150 degree group (for example 2.94 to 3.65 pooled). The zero-lag z of all pairs is negative (same-shank pairs).

ADn to PoS: fig7-adn-pos-connections, fig7c-adn-triggered-pos-lfp, fig7d-same-preferred-direction, fig7e-driven-pos-hd-information, fig7e-interneurons-no-difference¶

hd.mono_test: cross-correlograms of every ADn-PoS pair over the whole recording, 0.5 ms bins; baseline the cross-correlogram convolved with a 10 ms s.d. Gaussian, with (hollow) or without the central bin (m-b), or the jitter expectation (m-d, 20 ms box); two consecutive bins above the 99.9th Poisson percentile at lags of 1 to 10 ms, positive lags ADn to PoS. Sessions with both structures by the files' labels (criterion m-a, "in sessions with both structures"), including Mouse28-140314, which has no head direction (connections need none); the paper's three mice are a variant.

In [36]:
def mono_table(MO_):
    MO_ = MO_.copy()
    key_a, key_p = list(zip(MO_.session, MO_.adn)), list(zip(MO_.session, MO_.pos))
    ka, kp = pd.MultiIndex.from_tuples(key_a), pd.MultiIndex.from_tuples(key_p)
    MO_["adn_hd"] = C_idx.hd_a.reindex(ka).fillna(False).values.astype(bool)
    MO_["pos_hd"] = C_idx.hd_a.reindex(kp).fillna(False).values.astype(bool)
    MO_["pos_cls"] = C_idx.cls.reindex(kp).fillna("und").values
    return MO_
MO_ALL = mono_table(MONO)
MO = MO_ALL[MO_ALL.subject.isin(BOTH)]
rows = []
for sample, M_ in (("files' labels (4 mice)", MO), ("paper's 3 mice", MO[MO.subject.isin(DUAL)]),
                   ("paper's 3 mice, sessions with head direction", MO[MO.subject.isin(DUAL) & MO.session.isin(CELLS.session)])):
    for base in ("c", "h", "j"):
        for pairs in ("all ADn x all PoS", "ADn HD x all PoS"):
            m = M_ if pairs.startswith("all") else M_[M_.adn_hd]
            py = M_[M_.adn_hd & (M_.pos_cls == "pyr")]
            a2p, p2a = m["a2p_" + base].sum(), m["p2a_" + base].sum()
            ya, yp = py["a2p_" + base].sum(), py["p2a_" + base].sum()
            b1 = stats.binomtest(int(ya), int(ya + yp), 0.5).pvalue if ya + yp else np.nan
            b2 = stats.binomtest(int(ya), len(py), yp / len(py)).pvalue if yp else np.nan
            rows.append(dict(sample=sample, baseline=base, pairs=pairs, n=len(m), frac_a2p=a2p / len(m), frac_p2a=p2a / len(m),
                             n_a2p=int(a2p), n_p2a=int(p2a), n_pyr_pairs=len(py), frac_pyr_a2p=ya / len(py),
                             frac_pyr_p2a=yp / len(py), n_pyr_a2p=int(ya), n_pyr_p2a=int(yp), binom_half=b1, binom_prop=b2))
F7 = pd.DataFrame(rows)
print(F7.to_string(index=False, float_format=lambda x: f"{x:.4g}"))
print("expected: 6960 pairs, 4.45% ADn to PoS, 0.35% PoS to ADn; 3394 pyramidal pairs, 0.41% and 0.18%")
print("by mouse (baseline c, all pairs):", MO.groupby("subject")[["a2p_c", "p2a_c"]].mean().round(4).to_dict())
per = MO.groupby("session").agg(pairs=("adn", "size"), a2p=("a2p_c", "sum"), p2a=("p2a_c", "sum"))
per["n_adn_x_n_pos"] = SUM.set_index("session").reindex(per.index).eval("n_adn * n_pos")
print("pairs per session (baseline c):")
print(per.to_string())
print("most ADn x PoS pairs any session of the dandiset can give (sum of n_adn x n_pos over sessions):",
      int((SUM.n_adn * SUM.n_pos).sum()), "| in the paper's 3 mice:", int((SUM.n_adn * SUM.n_pos)[SUM.subject.isin(DUAL)].sum()),
      "| against 6960")
                                      sample baseline             pairs    n  frac_a2p  frac_p2a  n_a2p  n_p2a  n_pyr_pairs  frac_pyr_a2p  frac_pyr_p2a  n_pyr_a2p  n_pyr_p2a  binom_half  binom_prop
                      files' labels (4 mice)        c all ADn x all PoS 4765   0.04113  0.004407    196     21         1583       0.01074      0.004422         17          7     0.06391   0.0009296
                      files' labels (4 mice)        c  ADn HD x all PoS 3038   0.05431  0.005596    165     17         1583       0.01074      0.004422         17          7     0.06391   0.0009296
                      files' labels (4 mice)        h all ADn x all PoS 4765   0.04197  0.004617    200     22         1583       0.01074      0.004422         17          7     0.06391   0.0009296
                      files' labels (4 mice)        h  ADn HD x all PoS 3038    0.0553  0.005925    168     18         1583       0.01074      0.004422         17          7     0.06391   0.0009296
                      files' labels (4 mice)        j all ADn x all PoS 4765   0.04008  0.004197    191     20         1583       0.01137      0.004422         18          7     0.04329   0.0003488
                      files' labels (4 mice)        j  ADn HD x all PoS 3038   0.05267  0.005267    160     16         1583       0.01137      0.004422         18          7     0.04329   0.0003488
                              paper's 3 mice        c all ADn x all PoS 4699   0.04171  0.004469    196     21         1583       0.01074      0.004422         17          7     0.06391   0.0009296
                              paper's 3 mice        c  ADn HD x all PoS 3026   0.05453  0.005618    165     17         1583       0.01074      0.004422         17          7     0.06391   0.0009296
                              paper's 3 mice        h all ADn x all PoS 4699   0.04256  0.004682    200     22         1583       0.01074      0.004422         17          7     0.06391   0.0009296
                              paper's 3 mice        h  ADn HD x all PoS 3026   0.05552  0.005948    168     18         1583       0.01074      0.004422         17          7     0.06391   0.0009296
                              paper's 3 mice        j all ADn x all PoS 4699   0.04065  0.004256    191     20         1583       0.01137      0.004422         18          7     0.04329   0.0003488
                              paper's 3 mice        j  ADn HD x all PoS 3026   0.05288  0.005288    160     16         1583       0.01137      0.004422         18          7     0.04329   0.0003488
paper's 3 mice, sessions with head direction        c all ADn x all PoS 4111   0.04573  0.005108    188     21         1583       0.01074      0.004422         17          7     0.06391   0.0009296
paper's 3 mice, sessions with head direction        c  ADn HD x all PoS 3026   0.05453  0.005618    165     17         1583       0.01074      0.004422         17          7     0.06391   0.0009296
paper's 3 mice, sessions with head direction        h all ADn x all PoS 4111   0.04646  0.005351    191     22         1583       0.01074      0.004422         17          7     0.06391   0.0009296
paper's 3 mice, sessions with head direction        h  ADn HD x all PoS 3026   0.05552  0.005948    168     18         1583       0.01074      0.004422         17          7     0.06391   0.0009296
paper's 3 mice, sessions with head direction        j all ADn x all PoS 4111   0.04451  0.004865    183     20         1583       0.01137      0.004422         18          7     0.04329   0.0003488
paper's 3 mice, sessions with head direction        j  ADn HD x all PoS 3026   0.05288  0.005288    160     16         1583       0.01137      0.004422         18          7     0.04329   0.0003488
expected: 6960 pairs, 4.45% ADn to PoS, 0.35% PoS to ADn; 3394 pyramidal pairs, 0.41% and 0.18%
by mouse (baseline c, all pairs): {'a2p_c': {'Mouse20': 0.0, 'Mouse24': 0.0065, 'Mouse25': 0.0555, 'Mouse28': 0.0427}, 'p2a_c': {'Mouse20': 0.0, 'Mouse24': 0.0, 'Mouse25': 0.0085, 'Mouse28': 0.0039}}
pairs per session (baseline c):
                pairs  a2p  p2a  n_adn_x_n_pos
session                                       
Mouse20-130514     12    0    0             12
Mouse20-130515     14    0    0             14
Mouse20-130520     40    0    0             40
Mouse24-131213     45    0    0             45
Mouse24-131216    130    2    0            130
Mouse24-131217    130    0    0            130
Mouse24-131218    156    1    0            156
Mouse25-140123    133    5    0            133
Mouse25-140124     96    4    3             96
Mouse25-140128     60    0    0             60
Mouse25-140129     19    1    0             19
Mouse25-140130    150   20    5            150
Mouse25-140131    153   18    0            153
Mouse25-140203     80    4    0             80
Mouse25-140204    120    0    0            120
Mouse25-140205     81    0    0             81
Mouse25-140206     45    0    0             45
Mouse28-140310    165   14    0            165
Mouse28-140311    156    4    2            156
Mouse28-140312    756   30    0            756
Mouse28-140313    836   73    9            836
Mouse28-140314    588    8    0            588
Mouse28-140317    360    2    1            360
Mouse28-140318    440   10    1            440
most ADn x PoS pairs any session of the dandiset can give (sum of n_adn x n_pos over sessions): 4765 | in the paper's 3 mice: 4699 | against 6960

Result: not reproduced. The ADn to PoS fraction is within tolerance, but the pair count, the PoS to ADn fraction and the pyramidal fractions are not. Over all 4765 ADn by PoS pairs of the sessions with both structures, 4.11% are connected ADn to PoS (Methods' baseline; 4.01% with the jitter baseline) and 0.44% PoS to ADn, against 0.35% (0.315 to 0.385). 4765 is every ADn by PoS pair the dandiset holds (the sum of n_adn x n_pos over sessions), so 6960 cannot be reached; the paper's three mice give 4699 pairs (4.17% and 0.45%), and without Mouse28-140314, 4111 (4.57% and 0.51%). Among the 1583 pairs of ADn HD and PoS pyramidal cells, 1.07% are connected ADn to PoS and 0.44% PoS to ADn (17 and 7 pairs), against 0.41% and 0.18% over 3394. The direction holds against the PoS to ADn proportion (binomial p = 0.0009) and not against one half (17 of 24, p = 0.064).

In [37]:
for sample, L in (("files' labels (4 mice)", LFP[LFP.subject.isin(BOTH)].copy()), ("paper's 3 mice", LFP[LFP.subject.isin(DUAL)].copy())):
    for ctl in ("jit", "rand"):
        L["ratio_" + ctl] = L.p_sta / L["p_" + ctl]
        w = stats.wilcoxon(L.p_sta, L["p_" + ctl])
        ses = L.groupby("session")["ratio_" + ctl].median()
        print(f"{sample}, control {ctl}: cells {len(L)}, sessions {L.session.nunique()}; median power ratio {L['ratio_' + ctl].median():.2f}; "
              f"cells above control {int((L['ratio_' + ctl] > 1).sum())}; sessions with median ratio > 1: {int((ses > 1).sum())} of {len(ses)}; Wilcoxon p {w.pvalue:.3g}")
L = LFP[LFP.subject.isin(BOTH)].copy()
print("spikes per cell in the window:", int(L.nspk.min()), "to", int(L.nspk.max()))
fig, ax = plt.subplots(1, 1, figsize=(4, 3))
lag = (np.arange(len(L.sta_bp.iloc[0])) - len(L.sta_bp.iloc[0]) // 2) / 1.25
ax.plot(lag, np.vstack(L.sta_bp.values).mean(0)); ax.set_xlabel("lag (ms)"); ax.set_ylabel("80-250 Hz STA (a.u.)")
plt.tight_layout(); plt.show()
print("range of the plotted mean:", float(np.vstack(L.sta_bp.values).mean(0).min()), float(np.vstack(L.sta_bp.values).mean(0).max()))
files' labels (4 mice), control jit: cells 175, sessions 25; median power ratio 2.85; cells above control 126; sessions with median ratio > 1: 21 of 25; Wilcoxon p 2.51e-12
files' labels (4 mice), control rand: cells 175, sessions 25; median power ratio 3.17; cells above control 129; sessions with median ratio > 1: 23 of 25; Wilcoxon p 1.42e-13
paper's 3 mice, control jit: cells 161, sessions 20; median power ratio 2.98; cells above control 118; sessions with median ratio > 1: 18 of 20; Wilcoxon p 1.13e-12
paper's 3 mice, control rand: cells 161, sessions 20; median power ratio 3.30; cells above control 121; sessions with median ratio > 1: 20 of 20; Wilcoxon p 1.09e-13
spikes per cell in the window: 55 to 33267
range of the plotted mean: -2.602742346561213 2.260001140953511

Result: reproduced. Within 5 ms of ADn HD cell spikes, the 80 to 250 Hz PoS LFP has more power than at jittered spike times (median ratio 2.85, 126 of 175 cells, Wilcoxon p = 2.5e-12) and than at random times (3.17, p = 1.4e-13), in the sessions with both structures. The session median ratio exceeds 1 in 21 and 23 of 25 sessions. In the paper's three mice the ratios are 2.98 and 3.30 (18 and 20 of 20 sessions). One 14 minute window per session was read.

In [38]:
ci = C_idx
for sample, M_ in (("files' labels (4 mice)", MO), ("paper's 3 mice", MO[MO.subject.isin(DUAL)])):
    for base in ("c", "h", "j"):
        c = M_[M_["a2p_" + base] & M_.adn_hd & M_.pos_hd]
        pa = ci.loc[list(zip(c.session, c.adn))].pref_a.values
        pp = ci.loc[list(zip(c.session, c.pos))].pref_a.values
        d = hd.circ_diff(pp.astype(float), pa.astype(float))
        if len(d) < 3:
            print(sample, base, "pairs", len(d)); continue
        R = np.abs(np.mean(np.exp(1j * d)))
        pr = hd.rayleigh_p(R, len(d))
        w = stats.wilcoxon(d)
        print(f"{sample}, baseline {base}: connected ADn HD to PoS HD pairs {len(d)}; median difference {np.degrees(np.median(d)):.1f} deg; "
              f"Rayleigh p {pr:.3g}; Wilcoxon against 0 p {w.pvalue:.3g}")
print("expected 12 pairs; paper Rayleigh p 2.4e-4, Wilcoxon p 0.68")
files' labels (4 mice), baseline c: connected ADn HD to PoS HD pairs 11; median difference -8.8 deg; Rayleigh p 0.000298; Wilcoxon against 0 p 0.413
files' labels (4 mice), baseline h: connected ADn HD to PoS HD pairs 11; median difference -8.8 deg; Rayleigh p 0.000298; Wilcoxon against 0 p 0.413
files' labels (4 mice), baseline j: connected ADn HD to PoS HD pairs 11; median difference -8.8 deg; Rayleigh p 0.000298; Wilcoxon against 0 p 0.413
paper's 3 mice, baseline c: connected ADn HD to PoS HD pairs 11; median difference -8.8 deg; Rayleigh p 0.000298; Wilcoxon against 0 p 0.413
paper's 3 mice, baseline h: connected ADn HD to PoS HD pairs 11; median difference -8.8 deg; Rayleigh p 0.000298; Wilcoxon against 0 p 0.413
paper's 3 mice, baseline j: connected ADn HD to PoS HD pairs 11; median difference -8.8 deg; Rayleigh p 0.000298; Wilcoxon against 0 p 0.413
expected 12 pairs; paper Rayleigh p 2.4e-4, Wilcoxon p 0.68

Result: reproduced. The 11 connected ADn HD to PoS HD pairs have unimodal differences of preferred direction (Rayleigh p = 3.0e-4) with no shift from 0 (median -8.8 degrees, Wilcoxon p = 0.41), under every baseline and in both samples of mice (Mouse20 adds no connected pair).

In [39]:
def driven(base, cls, mice):
    pos = CELLS[(CELLS.region == "PoS") & CELLS.subject.isin(mice) & (CELLS.cls == cls)].copy()
    con = set(map(tuple, MO[MO["a2p_" + base] & MO.adn_hd][["session", "pos"]].values))
    pos["connected"] = [(s_, u_) in con for s_, u_ in zip(pos.session, pos.unit)]
    A, B = pos[pos.connected]["info"].dropna(), pos[~pos.connected]["info"].dropna()
    u = stats.mannwhitneyu(A, B, alternative="two-sided") if len(A) and len(B) else None
    print(f"{'4 mice' if len(mice) == 4 else '3 mice'}, baseline {base}, {cls}: connected n {len(A)} median {A.median():.3f}; "
          f"not connected n {len(B)} median {B.median():.3f}; difference {A.median() - B.median():.3f}; "
          f"Mann-Whitney p {u.pvalue if u else np.nan:.3g}")
for mice in (BOTH, DUAL):
    for base in ("c", "h", "j"):
        driven(base, "pyr", mice)
print("expected 11 connected and 170 unconnected pyramidal cells; paper p 0.011")
4 mice, baseline c, pyr: connected n 13 median 1.083; not connected n 164 median 0.583; difference 0.500; Mann-Whitney p 0.0399
4 mice, baseline h, pyr: connected n 13 median 1.083; not connected n 164 median 0.583; difference 0.500; Mann-Whitney p 0.0399
4 mice, baseline j, pyr: connected n 14 median 1.036; not connected n 163 median 0.584; difference 0.452; Mann-Whitney p 0.0751
3 mice, baseline c, pyr: connected n 13 median 1.083; not connected n 164 median 0.583; difference 0.500; Mann-Whitney p 0.0399
3 mice, baseline h, pyr: connected n 13 median 1.083; not connected n 164 median 0.583; difference 0.500; Mann-Whitney p 0.0399
3 mice, baseline j, pyr: connected n 14 median 1.036; not connected n 163 median 0.584; difference 0.452; Mann-Whitney p 0.0751
expected 11 connected and 170 unconnected pyramidal cells; paper p 0.011

Result: reproduced. With the Methods' baseline (with or without the hollow), the 13 PoS pyramidal cells driven by an ADn HD cell carry more HD information than the 164 not connected (medians 1.08 against 0.58 bits per spike, Mann-Whitney p = 0.040), in both samples of mice. The result is fragile: with the jitter baseline variant (14 against 163), p = 0.075.

In [40]:
for mice in (BOTH, DUAL):
    for base in ("c", "h", "j"):
        driven(base, "int", mice)
print("expected 13 connected and 79 unconnected interneurons; paper p 0.38")
4 mice, baseline c, int: connected n 8 median 0.013; not connected n 59 median 0.004; difference 0.009; Mann-Whitney p 0.441
4 mice, baseline h, int: connected n 8 median 0.013; not connected n 59 median 0.004; difference 0.009; Mann-Whitney p 0.441
4 mice, baseline j, int: connected n 7 median 0.013; not connected n 60 median 0.005; difference 0.007; Mann-Whitney p 0.581
3 mice, baseline c, int: connected n 8 median 0.013; not connected n 51 median 0.004; difference 0.009; Mann-Whitney p 0.452
3 mice, baseline h, int: connected n 8 median 0.013; not connected n 51 median 0.004; difference 0.009; Mann-Whitney p 0.452
3 mice, baseline j, int: connected n 7 median 0.013; not connected n 52 median 0.005; difference 0.007; Mann-Whitney p 0.589
expected 13 connected and 79 unconnected interneurons; paper p 0.38

Result: reproduced. The 8 driven PoS putative interneurons do not differ from the 59 not connected (medians 0.013 against 0.004 bits per spike, difference 0.009, Mann-Whitney p = 0.44; jitter baseline p = 0.58); in the paper's three mice, 8 against 51, p = 0.45. With 8 driven cells (13 in the paper) the test has little power.

fig5d-adn-predicts-pos-reliably, fig5e-readout-windows, fig5e-adn-predicts-pos¶

These three claims rest on the GLM of Fig. 5d,e, which runs in glm_peyrache_2015.ipynb. fig5d-adn-predicts-pos-reliably and fig5e-adn-predicts-pos are tested there. fig5e-readout-windows is tested with its dense window grid in glm_windows_peyrache_2015.ipynb.

Summary¶

claim outcome
recording-sample partially reproduced
supptable1-per-animal partially reproduced
hd-cell-fraction not reproduced
hd-fraction-hd-shanks reproduced
ensemble-sizes partially reproduced
sleep-duration reproduced
adn-pos-peak-rate partially reproduced
adn-pos-hd-information reproduced
supfig2a-unimodality reproduced
fig2a-rates-preserved reproduced
fig2b-pair-correlations-preserved reproduced
fig2f-sws-tenfold-faster partially reproduced
fig2e-decoded-speed partially reproduced
fig2f-rem-similar-to-wake reproduced
fig3a-packet-60-degrees partially reproduced
fig3a-adn-stronger-than-pos reproduced
supfig5-rate-independent not reproduced
fig3b-packet-coherence reproduced
fig4b-noise-correlations reproduced
fig4c-noise-adn-vs-pos reproduced
fig4d-ole-near-bayesian partially reproduced (assumed estimator; hd-b ensembles)
fig4e-ole-covariance not reproduced (assumed estimator)
decoding-tracks-hd reproduced
fig5b-sleep-tuning-similar reproduced
fig5b-adn-decoded-tuning reproduced
fig5d-adn-predicts-pos-reliably reproduced (glm_peyrache_2015.ipynb)
fig5e-readout-windows partially reproduced (glm_windows_peyrache_2015.ipynb)
fig5e-adn-predicts-pos reproduced (glm_peyrache_2015.ipynb)
fig6a-fast-oscillation reproduced (assumed jitter null)
fig6b-adn-synchrony reproduced (assumed jitter null)
fig7-adn-pos-connections not reproduced
fig7c-adn-triggered-pos-lfp reproduced (assumed window and measure)
fig7d-same-preferred-direction reproduced
fig7e-driven-pos-hd-information reproduced
fig7e-interneurons-no-difference reproduced

A failure to reproduce here may be a failure of this attempt, not of the paper: see the reasoning and the differences from the paper's method.

How the analysis differs from the paper's.

  • Every session with head direction is used. The paper counted the ADn cells of the three dual mice from a subset of sessions, which the files do not mark. A depth-based reading of the Methods' session rule is shown as a variant for the counts.
  • Units are assigned to structures by the files' labels, so Mouse20's 8 PoS units count as PoS; the paper lists no PoS probe in that mouse.
  • The GLM (glm_peyrache_2015.ipynb) uses HD cells as assembly and targets, 7 readout windows and at most 20 minutes of each state; the readout windows of fig5e-readout-windows (glm_windows_peyrache_2015.ipynb) use 26 windows, 23 of them at 20 per decade from 20 to 251 ms, for PoS targets only.
  • The fast-synchrony null is the expectation of the jittered cross-correlogram, not 100 jitters.
  • The OLE is the standard Salinas and Abbott estimator; the signal OLE takes Q from the tuning curves off the diagonal and the observed variances on it (Q from the tuning curves throughout as a variant). Ensembles are decoded under both HD readings for fig4d,e and decoding-tracks-hd, and under (hd-a) for the other decoding claims.
  • The spike-triggered LFP uses one 14 minute window per session.
  • Two sessions without the paper's sleep scoring enter the waking analyses only, with the open-field epoch as wake.

What was found about the dataset.

  • Mouse28-140314 and both Mouse32 sessions hold no head direction, so Mouse32's cells cannot be classified. Mouse32-140820 also has no epochs or sleep states.
  • Mouse25-140131 and Mouse25-140204 lack the paper's sleep scoring.
  • Mouse20 has 8 units labelled post-subiculum in 3 sessions, on electrode groups labelled 'postsub' of a device the files call the post-subicular probe, though the paper lists no PoS probe in that mouse.
  • In Mouse17-130130, spikes continue 1101 s past the last sub-recording.
  • The wake interval of Mouse12-120808 spans 130 by 97 cm of LED positions, against the 53 by 46 cm arena.
  • Recorded unit counts match Supplementary Table 1 in Mouse12, Mouse17 and Mouse32 and in PoS; Mouse20 has 48 thalamic units against the table's 49.
  • The file's own HD classification agrees with reading (hd-a) for 1007 of 1064 classifiable cells.
  • The scored wake interval coincides with the open-field epochs (overlap 0.9998 to 1 both ways, 37 sessions).