Cody, Kumar & Tzounopoulos (2024) on dandiset 001256¶

Paper. Cody P, Kumar M, Tzounopoulos T (2024). Cortical zinc signaling is necessary for changes in mouse pupil diameter that are evoked by background sounds with different contrasts. J Neurosci 44(11) e0939232024, doi:10.1523/JNEUROSCI.0939-23.2024.

Dataset. DANDI:001256, version 0.241120.2150 (doi:10.48324/dandi.001256/0.241120.2150), streamed from the archive. The paper cites no version (it names no dandiset); 0.241120.2150 is the only published version and the most recent, and the draft has the same 30 assets and size, so it is pinned.

Claims. claims/001256/10.1523-jneurosci.0939-23.2024.yaml, written from the version of record (main text, Methods and figure legends; the paper has no supplement and links no code).

Claim Tested
fig1f-tone-response-inverse-u tested
fig1g-reliability-intermediate tested
fig1h-cgc-largest-intermediate tested
fig1h-cgc-evident-all-bins tested
fig1i-baseline-contrast-interaction tested
fig1i-contrast-effect-intermediate-only tested
fig2b-evoked-pd-whole-drc tested
fig2c-evoked-pd-1-2s tested; blocked (readings disagree, as the criterion says)
fig2e-drc-responses-no-difference tested
fig3b-lme-coefficients tested
fig3c-lme-likelihood-ratio tested
fig4c-wt-contrast-zx1-effects tested
fig4-wt-posthoc tested
fig4f-ko-no-contrast-effect tested; blocked (readings disagree, as the criterion says)
fig4f-ko-zx1-slope tested
fig5-contralateral-zx1-increases blocked, data missing (no widefield imaging in the dandiset)
fig5-ipsilateral-zx1-reduces blocked, data missing
fig5c-no-dye-in-other-hemisphere blocked, data missing
fig6a-baseline-pd-drift tested
fig6b-acsf-contrast-effect tested
fig6c-no-baseline-evoked-correlation tested; blocked (no listed reading matches the count, and they disagree)
methods-baseline-evoked-correlation tested; blocked (no reading matches the counts, and they disagree)
fig6d-ko-reduced-high-contrast tested
discussion-zx1-wt-like-ko tested

Where a method detail is not in the claims file it is taken from the paper's Methods, cited in the helper module zinc_pupil.py. No random numbers are used. Loading takes about one to two minutes.

Revised after the first verification round: the pupil cleaning also drops trials with tracking-failure steps (Data check), the growth curve fits use several optimizers and print their diagnostics, and variants for the cleaning and for group A without its ZnT3-WT mouse are at the end. Revised after the second round: a variant with the step rule counted after the spike filter, the Fig. 6a overlap under every ZX1 reading and cleaning, the Fig. 4c criterion per reading and cleaning, and two proposed changes of outcome (fig4c-wt-contrast-zx1-effects and fig4-wt-posthoc). The third verification round agreed with both, and the two outcomes were changed after it.

In [1]:
import time
import warnings

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import statsmodels.formula.api as smf
from scipy import stats

import zinc_pupil as zp

warnings.filterwarnings("ignore")
pd.set_option("display.width", 200)
pd.set_option("display.max_columns", 30)
pd.set_option("display.max_rows", 200)
T0 = time.time()
print("dandiset", zp.DANDISET_ID, "version", zp.DANDISET_VERSION)
dandiset 001256 version 0.241120.2150
In [2]:
assets = zp.list_assets()
meta, trials = zp.load_all(assets)
print(f"{len(assets)} files, {len(trials)} trials read in {time.time() - T0:.0f} s")
30 files, 3598 trials read in 112 s

Data check¶

What was loaded, by subject, with the analysis labels the files carry in session_description. The groups of the claims file are taken from these labels (A: pupilPTinContrast; C: pupil_contrast_ZnT3WT; D: pupil_contrast_ZnT3KO; F: pupil_contrast_ACSF), and group B (Fig. 2d, e, cells before and after ZX1) as the mice with CGC-assay trials both before and after ZX1, which no label names.

In [3]:
meta["labels"] = meta.session_description.str.split(" | ")
lab = meta.set_index("subject").labels
def in_label(name):
    return sorted(s for s, l in lab.items() if name in l)

GROUPS = {
    "A": in_label("pupilPTinContrast"),
    "C": in_label("pupil_contrast_ZnT3WT"),
    "D": in_label("pupil_contrast_ZnT3KO"),
    "F": in_label("pupil_contrast_ACSF"),
    "ZX1_drift": in_label("ZX1_uBasePupilPctMax_wEpoch"),
    "ACSF_drift": in_label("ACSF_uBasePupilPctMax_wEpoch"),
    "base_vs_evoked": in_label("pupilBaseline_vs_evoked"),
}
trials["treat"] = trials.treatment.map({"none": "CTRL", "preZX1": "CTRL", "preACSF": "CTRL",
                                        "postZX1": "ZX1", "postACSF": "ACSF"})
pt_tab = pd.crosstab(trials[trials.kind == "pt"].subject, trials[trials.kind == "pt"].treat)
GROUPS["B"] = sorted(pt_tab.index[(pt_tab.get("CTRL", 0) > 0) & (pt_tab.get("ZX1", 0) > 0)])
summary = meta[["subject", "genotype", "sex", "age"]].set_index("subject")
for g, subs in GROUPS.items():
    summary[g] = summary.index.isin(subs).astype(int)
print(summary.sort_index().to_string())
for g, subs in GROUPS.items():
    sx = summary.loc[subs, "sex"].value_counts().to_dict()
    gt = summary.loc[subs, "genotype"].value_counts().to_dict()
    print(f"group {g}: {len(subs)} mice, sex {sx}, genotype {gt}")
print()
print("trials by kind and treatment")
print(pd.crosstab(trials.kind, trials.treat))
print()
print("trials by contrast of the first DRC block (kind pt and drc)")
print(pd.crosstab(trials[trials.kind.isin(["pt", "drc"])].kind, trials.contrast))
print("stimDelay values (s):", trials.groupby("kind").stimDelay.unique().to_dict())
print("2P frame rates:", trials.frameRate.unique(), "frames per trial:", trials.groupby("kind").nFrames.unique().to_dict())
st = trials.starting_time.astype(float)
ft = pd.to_datetime(trials.fileTimeInstantiate)
off = (ft - ft.groupby(trials.subject).transform(lambda x: x[st.loc[x.index] == 0].min())).dt.total_seconds()
print("trials whose table starting_time differs from their .tif creation time (relative to the reference .tif) by more than 1 s:",
      int(((st - off).abs() > 1).sum()), "; by subject:", trials[(st - off).abs() > 1].subject.value_counts().to_dict())
print("  of these, starting_time - (creation time offset) in hours:", sorted(((st - off)[(st - off).abs() > 1] / 3600).round(2).unique().tolist())[:5])
print("pure-tone frequencies of the CGC assay:", trials[trials.kind == "pt"].pulseSets.str.extract(r"(\d+Hz)")[0].value_counts().to_dict())
         genotype sex   age  A  C  D  F  ZX1_drift  ACSF_drift  base_vs_evoked  B
subject                                                                          
AA0304   C57BL6/J   F  P49D  1  0  0  0          0           0               0  0
AA0308   C57BL6/J   F  P41D  1  0  0  0          0           0               0  0
AA0310   C57BL6/J   M  P45D  1  0  0  0          0           0               0  0
AA0312   C57BL6/J   M  P44D  1  0  0  0          0           0               0  1
AA0314   C57BL6/J   F  P47D  1  0  0  0          1           0               1  1
AA0315   C57BL6/J   M  P42D  1  0  0  0          1           0               1  1
AA0317   C57BL6/J   F  P45D  0  0  0  0          1           0               1  1
AA0318   C57BL6/J   F  P46D  1  0  0  0          1           0               1  1
AA0319   C57BL6/J   M  P47D  0  0  0  0          1           0               1  1
AA0320   C57BL6/J   M  P48D  0  0  0  1          0           1               0  0
AA0322   C57BL6/J   F  P50D  0  0  0  1          0           1               0  0
AA0323     ZnT3WT   M  P41D  0  1  0  0          1           0               1  0
AA0325     ZnT3WT   M  P44D  0  1  0  0          1           0               1  1
AA0326     ZnT3KO   M  P48D  0  0  1  0          0           0               0  1
AA0327     ZnT3KO   M  P50D  0  0  1  0          0           0               0  0
AA0328     ZnT3KO   F  P51D  0  0  1  0          0           0               0  0
AA0330     ZnT3WT   M  P41D  0  1  0  0          1           0               1  0
AA0331     ZnT3WT   M  P42D  0  1  0  0          0           0               0  0
AA0332     ZnT3WT   F  P44D  0  1  0  0          0           0               0  0
AA0333     ZnT3WT   F  P45D  0  1  0  0          0           0               0  0
AA0334     ZnT3WT   F  P46D  0  1  0  0          1           0               1  1
AA0335     ZnT3WT   M  P44D  1  1  0  0          1           0               1  1
AA0336     ZnT3WT   F  P46D  0  1  0  0          1           0               1  1
AA0337     ZnT3WT   F  P48D  0  1  0  0          0           0               0  0
AA0339     ZnT3KO   M  P53D  0  0  1  0          0           0               0  0
AA0340     ZnT3KO   F  P54D  0  0  1  0          0           0               0  1
AA0341     ZnT3KO   F  P55D  0  0  1  0          0           0               0  0
AA0350   C57BL6/J   M  P44D  1  0  0  1          0           1               0  0
AA0351   C57BL6/J   M  P45D  0  0  0  1          0           1               0  0
AA0353   C57BL6/J   M  P47D  1  0  0  0          0           0               0  0
group A: 10 mice, sex {'M': 6, 'F': 4}, genotype {'C57BL6/J': 9, 'ZnT3WT': 1}
group C: 10 mice, sex {'M': 5, 'F': 5}, genotype {'ZnT3WT': 10}
group D: 6 mice, sex {'M': 3, 'F': 3}, genotype {'ZnT3KO': 6}
group F: 4 mice, sex {'M': 3, 'F': 1}, genotype {'C57BL6/J': 4}
group ZX1_drift: 11 mice, sex {'M': 6, 'F': 5}, genotype {'ZnT3WT': 6, 'C57BL6/J': 5}
group ACSF_drift: 4 mice, sex {'M': 3, 'F': 1}, genotype {'C57BL6/J': 4}
group base_vs_evoked: 11 mice, sex {'M': 6, 'F': 5}, genotype {'ZnT3WT': 6, 'C57BL6/J': 5}
group B: 12 mice, sex {'M': 6, 'F': 6}, genotype {'C57BL6/J': 6, 'ZnT3WT': 4, 'ZnT3KO': 2}

trials by kind and treatment
treat  ACSF  CTRL  ZX1
kind                  
drc     148   842  586
led       0    75   11
map       0  1288    0
pt       34   360  254

trials by contrast of the first DRC block (kind pt and drc)
contrast  HIGH  LOW
kind               
drc        778  798
pt         321  327
stimDelay values (s): {'drc': array([ 4, 10], dtype=uint8), 'led': array([10], dtype=uint8), 'map': array([3], dtype=uint8), 'pt': array([4], dtype=uint8)}
2P frame rates: [5.] frames per trial: {'drc': array([170]), 'led': array([150]), 'map': array([715]), 'pt': array([120])}
trials whose table starting_time differs from their .tif creation time (relative to the reference .tif) by more than 1 s: 84 ; by subject: {'AA0322': 19, 'AA0320': 16, 'AA0318': 16, 'AA0330': 16, 'AA0319': 8, 'AA0327': 8, 'AA0333': 1}
  of these, starting_time - (creation time offset) in hours: [24.0]
pure-tone frequencies of the CGC assay: {'10000Hz': 541, '5946Hz': 55, '7071Hz': 52}

Checks of the metadata against the values:

  • Pupil series: two video frames per two-photon frame (10 and 5 Hz) is expected. Pupil series whose length does not match their trial (a series of a mapping trial's length attached to a DRC trial) are counted and left out. Every pupil series's description names TwoPhotonSeries_036 (or the file's last series); the series is matched to its trial by the .tif file named in its comments.
  • Units: the pupil radius is in "na" (pixels, judged from the values) and the fluorescence in "lumens" (raw intensity); both analyses use ratios, so the units do not enter.
  • Raw pupil traces hold dropped frames (NaN) and tracking failures.
In [4]:
snd = trials[trials.kind.isin(["pt", "drc"])].copy()
snd["has_pupil"] = snd.pupil.notna()
snd["len_ok"] = [p is not None and len(p) == 2 * int(n) for p, n in zip(snd.pupil, snd.nFrames)]
print("sound trials:", len(snd), "with pupil:", snd.has_pupil.sum(), "pupil length = 2 x frames:", snd.len_ok.sum())
print("mismatched pupil lengths by subject:", snd[snd.has_pupil & ~snd.len_ok].subject.value_counts().to_dict())
raw = snd[snd.len_ok]
nan_frac = raw.pupil.map(lambda p: np.isnan(p).mean())
print(f"fraction of pupil frames missing per trial: median {nan_frac.median():.3f}, "
      f"trials all missing {int((nan_frac == 1).sum())}")
rmax = raw.pupil.map(lambda p: np.nanmax(p) if np.isfinite(p).any() else np.nan)
rmed = raw.pupil.map(lambda p: np.nanmedian(p) if np.isfinite(p).any() else np.nan)
print(f"raw radius: median of trial medians {rmed.median():.1f}, range of trial medians "
      f"{rmed.min():.1f} to {rmed.max():.1f}; trials whose maximum exceeds 3 x their median: "
      f"{int((rmax > 3 * rmed).sum())} (largest raw value {np.nanmax(rmax):.3g})")

# Pupil cleaning: the paper's single pass, and the pass repeated with a spike filter (main).
single = zp.pupil_measures(trials, jump_ratio=None, max_pass=1, spike_filter=False, max_missing=1.0)
prev = zp.pupil_measures(trials, jump_ratio=None)  # round-1 cleaning: no trial dropped for jumps
tr = zp.pupil_measures(trials)
# narrower form of the step rule (variant): steps counted after the spike filter
narrow = zp.pupil_measures(trials, jump_after_filter=True)
print(f"trials with a usable pupil: single pass {len(single)}, round-1 cleaning {len(prev)}, main cleaning {len(tr)}")
print("trials dropped for a step by more than a factor 2 between consecutive tracked frames:",
      int((prev.n_jumps > 0).sum()), "; by subject:", prev[prev.n_jumps > 0].subject.value_counts().to_dict())
print(f"trials dropped for a step, {int((prev.n_jumps > 0).sum())} in "
      f"{prev[prev.n_jumps > 0].subject.nunique()} mice; counting steps after the spike filter (variant): "
      f"{len(prev) - len(narrow)} in {prev[~prev.trial_id.isin(narrow.trial_id)].subject.nunique()} mice, by subject:",
      prev[~prev.trial_id.isin(narrow.trial_id)].subject.value_counts().to_dict())
amax = pd.DataFrame({
    "max_single_pass": single.groupby("subject").pclean.apply(lambda s: max(np.max(x) for x in s)),
    "max_round1": prev.groupby("subject").pclean.apply(lambda s: max(np.max(x) for x in s)),
    "max_main": tr.groupby("subject").pclean.apply(lambda s: max(np.max(x) for x in s)),
    "max_narrow": narrow.groupby("subject").pclean.apply(lambda s: max(np.max(x) for x in s)),
    "median_main": tr.groupby("subject").pclean.apply(lambda s: np.median(np.concatenate(list(s)))),
    "trials_main": tr.groupby("subject").size(),
})
print(amax.round(1).to_string())
# residual artifacts: the five largest cleaned trial maxima per animal, each with its trial's median
tm = tr.assign(tmax=tr.pclean.map(np.max), tmed=tr.pclean.map(np.median)).sort_values("tmax", ascending=False)
top5 = tm.groupby("subject").head(5).groupby("subject").apply(
    lambda g: ", ".join(f"{a:.0f}/{b:.0f}" for a, b in zip(g.tmax, g.tmed)))
print("five largest trial maxima / that trial's median, main cleaning:")
print(top5.to_string())
print("largest ratio of a trial's maximum to the animal's median:",
      (tm.tmax / tm.subject.map(amax.median_main)).max().round(2))
print("baseline PD (% animal max), main cleaning: range", tr.base_pct_max.min().round(1), "to",
      tr.base_pct_max.max().round(1), "; below 50%:", int((tr.base_pct_max < 50).sum()), "of", len(tr))
sound trials: 2224 with pupil: 2223 pupil length = 2 x frames: 2198
mismatched pupil lengths by subject: {'AA0320': 4, 'AA0318': 4, 'AA0322': 4, 'AA0319': 4, 'AA0327': 4, 'AA0330': 4, 'AA0333': 1}
fraction of pupil frames missing per trial: median 0.000, trials all missing 13
raw radius: median of trial medians 37.6, range of trial medians 8.3 to 157.5; trials whose maximum exceeds 3 x their median: 68 (largest raw value 1.52e+06)
trials with a usable pupil: single pass 2180, round-1 cleaning 2113, main cleaning 1995
trials dropped for a step by more than a factor 2 between consecutive tracked frames: 118 ; by subject: {'AA0319': 21, 'AA0351': 19, 'AA0334': 15, 'AA0341': 13, 'AA0320': 11, 'AA0330': 9, 'AA0353': 9, 'AA0337': 6, 'AA0314': 3, 'AA0336': 3, 'AA0340': 3, 'AA0322': 2, 'AA0323': 2, 'AA0310': 1, 'AA0350': 1}
trials dropped for a step, 118 in 15 mice; counting steps after the spike filter (variant): 39 in 6 mice, by subject: {'AA0351': 17, 'AA0319': 9, 'AA0334': 9, 'AA0336': 2, 'AA0320': 1, 'AA0341': 1}
         max_single_pass  max_round1  max_main  max_narrow  median_main  trials_main
subject                                                                             
AA0304             114.6       113.2     113.2       113.2         88.5           31
AA0308              86.4        86.4      86.4        86.4         45.1           48
AA0310              93.0        93.0      93.0        93.0         43.6           55
AA0312             121.3       120.0     120.0       120.0         81.3           75
AA0314              95.3        80.4      80.4        80.4         46.7           78
AA0315             104.2       101.8     101.8       101.8         73.9           96
AA0317              91.1        90.8      90.8        90.8         39.0          110
AA0318             125.6       123.3     123.3       123.3         96.5          107
AA0319          545522.9       332.7      78.3        78.3         28.0           83
AA0320          547173.3        85.1      85.1        85.1         39.8           51
AA0322             118.6       116.1     116.1       116.1         59.0           65
AA0323             102.7       100.2     100.2       100.2         53.7           57
AA0325              84.0        83.5      83.5        83.5         27.0           96
AA0326              83.4        83.4      83.4        83.4         37.8           92
AA0327              72.8        72.6      72.6        72.6         32.8           59
AA0328              77.1        77.1      77.1        77.1         39.2           72
AA0330              90.2        68.5      68.5        68.5         22.9           50
AA0331              79.5        77.3      77.3        77.3         42.6           32
AA0332              90.6        90.6      90.6        90.6         51.1           26
AA0333              45.6        42.1      42.1        42.1         19.0           24
AA0334             213.9       162.1      70.9        70.9         27.7           72
AA0335              92.5        92.5      92.5        92.5         39.1           99
AA0336             367.3        77.5      77.5        77.5         31.7           76
AA0337             255.8        82.9      82.9        82.9         32.1           82
AA0339              84.6        80.5      80.5        80.5         44.1           23
AA0340              61.6        61.6      61.6        61.6         20.0           95
AA0341              72.2        57.6      57.6        57.6         32.3           55
AA0350             101.7       101.8     101.8       101.8         33.4           79
AA0351           79723.6        89.9      89.9        89.9         56.0           30
AA0353             203.2        90.1      90.1        90.1         29.2           77
five largest trial maxima / that trial's median, main cleaning:
subject
AA0304       113/101, 112/110, 111/92, 108/95, 107/97
AA0308              86/69, 75/72, 73/66, 72/60, 71/52
AA0310              93/83, 92/80, 91/70, 88/69, 84/79
AA0312          120/96, 104/74, 101/74, 100/87, 99/96
AA0314              80/51, 80/60, 79/57, 76/58, 76/54
AA0315            102/90, 101/89, 99/93, 99/95, 99/86
AA0317              91/83, 83/66, 82/73, 76/66, 74/64
AA0318    123/103, 117/104, 116/111, 114/110, 114/104
AA0319              78/66, 69/57, 67/50, 67/63, 60/55
AA0320              85/64, 75/58, 74/45, 73/60, 72/61
AA0322       116/102, 116/101, 115/95, 111/97, 109/90
AA0323             100/79, 99/90, 96/87, 93/78, 93/82
AA0325              84/41, 76/49, 73/61, 72/51, 72/38
AA0326              83/60, 81/56, 80/49, 77/53, 77/50
AA0327              73/53, 72/49, 70/46, 69/45, 63/51
AA0328              77/57, 77/54, 76/44, 75/49, 73/40
AA0330              69/24, 67/28, 57/24, 53/31, 52/26
AA0331              77/47, 77/58, 77/55, 70/51, 69/44
AA0332              91/74, 88/71, 87/60, 85/64, 82/56
AA0333              42/21, 41/21, 37/20, 35/19, 30/22
AA0334              71/52, 67/60, 66/45, 65/37, 63/46
AA0335              93/79, 84/71, 80/72, 79/61, 78/63
AA0336              77/60, 75/56, 73/50, 72/38, 71/43
AA0337              83/47, 81/49, 79/61, 78/53, 77/55
AA0339              81/42, 75/57, 72/52, 72/48, 70/54
AA0340              62/34, 58/38, 57/38, 56/38, 55/40
AA0341              58/40, 56/40, 55/39, 53/35, 53/39
AA0350            102/95, 101/95, 97/89, 96/91, 94/78
AA0351              90/84, 90/80, 85/72, 84/70, 83/75
AA0353              90/79, 90/79, 86/80, 82/74, 80/70
largest ratio of a trial's maximum to the animal's median: 3.09
baseline PD (% animal max), main cleaning: range 12.6 to 97.4 ; below 50%: 1055 of 1995

With one pass, several animals keep pupil "maxima" of 200 to 550000 pixels, against medians of 20 to 100, so a baseline in % of the animal's maximum would be near 0 for every trial of those animals. The round-1 cleaning (Hampel spike filter, the derivative step repeated, and trials with more than half of their frames missing dropped) still left tracking failures in two mice: in AA0319 and AA0334 the failures come as runs at a second level (130 to 160, against a pupil of about 25), which set their maxima at 332.7 and 162.1. The main cleaning also drops every trial whose raw trace steps by more than a factor 2 between consecutive tracked frames (118 trials, 15 mice); a pupil does not double or halve its radius in 100 ms. This changes the maximum of those two mice only (78.3 and 70.9), and the largest trial maximum is now at most 3.1 times its animal's median. The rule reads the raw trace, before the spike filter, so it also drops trials whose only fault is a single-frame spike that the filter removes: it is broader than the two mice need. Counting the steps after the spike filter drops 39 trials in 6 mice and gives the same animal maxima (max_narrow); it is run as a variant at the end. Where an outcome differs between the two, the difference comes from the 79 trials in other mice that only the broad rule drops. All three steps are assumptions; the paper's own DeepLabCut points and likelihoods, which would let the frames be dropped as it describes, are not in the files. The other cleanings are run as variants at the end of the notebook.

Clock check. The pupil series start at their trial's start time (asserted on loading). Sound onset is stimDelay after the first frame. If this is right, the population calcium response should rise at the pure tone (2 s after onset, in both contrasts) and not at other times, and the pupil should dilate after onset, not before. Shifting the assumed onset by whole seconds moves the tone response away from 2 s. The DRC structure (sound-onset delays, which contrast comes first, mapping trials) is printed after the duplicate check.

In [5]:
ptr = trials[trials.kind == "pt"]
pop = []
for _, r in ptr.iterrows():
    d, t = zp.dff(np.asarray(r.F, float), r.stimDelay)
    pop.append(np.nanmean(d, 1))
pop = np.nanmean(np.vstack(pop), 0)
t = zp.frame_times(len(pop), 4)
print("population mean dF/F (%) of CGC-assay trials by time from sound onset:")
print(pd.Series(pop.round(2), index=t.round(1)).loc[-1.2:4.0].to_string())
d1 = np.diff(pop)
k = np.argmax(d1[(t[:-1] >= 0.5)]) + np.sum(t[:-1] < 0.5)
print(f"largest frame-to-frame rise after 0.5 s: from {t[k]:.1f} to {t[k+1]:.1f} s (tone at 2.0 s)")
ev = tr[tr.kind.isin(["pt", "drc"])]
m = np.nanmean(np.vstack([x[:200] for x in ev.ev_trace]), 0)
tp = np.arange(200) / 10 - 4
print("mean pupil (% baseline) over trials: -4 to 0 s", m[(tp >= -4) & (tp < 0)].mean().round(2),
      "; 0 to 1 s", m[(tp >= 0) & (tp < 1)].mean().round(2), "; 1 to 2 s", m[(tp >= 1) & (tp < 2)].mean().round(2),
      "; 2 to 4 s", m[(tp >= 2) & (tp < 4)].mean().round(2))
fig, ax = plt.subplots(1, 2, figsize=(9, 3))
ax[0].plot(t, pop); ax[0].axvline(0, c="k", ls=":"); ax[0].axvline(2, c="g", ls=":")
ax[0].set(xlabel="time from sound onset (s)", ylabel="mean dF/F (%)", title="CGC assay, all cells")
ax[1].plot(tp, m); ax[1].axvline(0, c="k", ls=":")
ax[1].set(xlabel="time from sound onset (s)", ylabel="pupil (% baseline)", title="all sound trials")
plt.tight_layout(); plt.show()
print("plotted ranges: dF/F", pop.min().round(2), "to", pop.max().round(2), "; pupil", m.min().round(2), "to", m.max().round(2))
population mean dF/F (%) of CGC-assay trials by time from sound onset:
-1.2    0.26
-1.0    0.07
-0.8    0.02
-0.6   -0.04
-0.4   -0.13
-0.2    0.08
 0.0    1.51
 0.2    1.50
 0.4    1.00
 0.6    0.38
 0.8    0.19
 1.0   -0.17
 1.2   -0.42
 1.4   -0.47
 1.6   -0.42
 1.8    0.66
 2.0    6.99
 2.2    9.89
 2.4    6.67
 2.6    3.79
 2.8    2.01
 3.0    0.91
 3.2    0.27
 3.4   -0.07
 3.6   -0.23
 3.8   -0.25
 4.0   -0.19
largest frame-to-frame rise after 0.5 s: from 1.8 to 2.0 s (tone at 2.0 s)
mean pupil (% baseline) over trials: -4 to 0 s 100.08 ; 0 to 1 s 103.79 ; 1 to 2 s 107.31 ; 2 to 4 s 106.74
No description has been provided for this image
plotted ranges: dF/F -0.47 to 9.89 ; pupil 99.96 to 107.48
In [6]:
# Recordings deposited twice: identical pupil traces or fluorescence across trials.
import hashlib
def h(a):
    a = np.asarray(a, float)
    return None if not np.isfinite(a).any() else hashlib.md5(np.nan_to_num(a).tobytes()).hexdigest()
hp = raw.pupil.map(h).dropna()
hf = ptr.F.map(h)
print("identical pupil traces (excluding all-missing):", int(hp.duplicated().sum()),
      "; identical fluorescence arrays:", int(hf.duplicated().sum()))
print("subjects:", meta.subject.nunique(), "files:", len(meta))
identical pupil traces (excluding all-missing): 0 ; identical fluorescence arrays: 0
subjects: 30 files: 30
In [7]:
# DRC trial structure: sound-onset delay, first block, and mapping trials, by subject
snd_all = trials[trials.kind.isin(["pt", "drc"])]
first_block = snd_all.pulseNames.str.extract(r"(\d\d-\d\ddB_to_\d\d-\d\ddB)")[0].fillna("one contrast")
print("trials by kind, stimDelay and first-block order (all subjects):")
print(pd.crosstab([snd_all.kind, snd_all.stimDelay], first_block).to_string())
drc_all = trials[trials.kind == "drc"]
print("DRC trials (no tone) by subject, treatment and contrast of the first block:")
print(pd.crosstab(drc_all.subject, [drc_all.treat, drc_all.contrast]).to_string())
print("DRC trials with stimDelay = 10 s by subject and treatment:",
      drc_all[drc_all.stimDelay == 10].groupby(["subject", "treat"]).size().to_dict())
print("FRA mapping trials by subject:", trials[trials.kind == "map"].subject.value_counts().to_dict())
print("  of these, group A mice:", sorted(set(trials[trials.kind == "map"].subject) & set(GROUPS["A"])))
# Clock check for the stimDelay = 10 s trials: the pupil should dilate after the onset taken from stimDelay
# (10 s), not after 4 s, the onset of the other DRC trials.
d10 = tr[(tr.kind == "drc") & (tr.stimDelay == 10)]
for onset in (10, 4):
    m10 = np.nanmean(np.vstack(list(d10.pclean)), 0)
    tt = np.arange(len(m10)) / 10 - onset
    b = m10[(tt >= -4) & (tt < 0)].mean()
    print(f"stimDelay-10 DRC trials ({len(d10)}), onset taken at {onset} s: mean pupil (% of -4 to 0 s) over 0 to 2 s "
          f"{100 * m10[(tt >= 0) & (tt < 2)].mean() / b:.2f}, over 2 to 4 s {100 * m10[(tt >= 2) & (tt < 4)].mean() / b:.2f}")
trials by kind, stimDelay and first-block order (all subjects):
0               40-70dB_to_50-60dB  50-60dB_to_40-70dB  one contrast
kind stimDelay                                                      
drc  4                         762                 782             0
     10                         16                  16             0
pt   4                           0                   0           648
DRC trials (no tone) by subject, treatment and contrast of the first block:
treat    ACSF     CTRL      ZX1    
contrast HIGH LOW HIGH LOW HIGH LOW
subject                            
AA0304      0   0    6   8    0   0
AA0308      0   0   11  11    0   0
AA0310      0   0   13  13    0   0
AA0312      0   0   10  12   12  10
AA0314      0   0   12  13   13  12
AA0315      0   0   13  13   13  14
AA0317      0   0   13  14   16  17
AA0318      0   0   14  14   16  15
AA0319      0   0   14  14   14  15
AA0320     17  17   16  16    0   0
AA0322     19  20   16  16    0   0
AA0323      0   0   13  15   16  15
AA0325      0   0   16  16   16  16
AA0326      0   0   16  15   16  15
AA0327      0   0   16  16   16  16
AA0328      0   0   19  17   18  18
AA0330      0   0   16  16   18  21
AA0331      0   0   16  16    0   0
AA0332      0   0   12  14    0   0
AA0333      0   0   12  13    0   0
AA0334      0   0   12  14   14  13
AA0335      0   0   12  13   12  12
AA0336      0   0   12  13   12  12
AA0337      0   0   29  28   29  29
AA0339      0   0   12  12   12  12
AA0340      0   0   12  12   12  13
AA0341      0   0   16  16   17  19
AA0350     12  12   11  13    0   0
AA0351     11  14   12  12    0   0
AA0353     12  14   13  12    0   0
DRC trials with stimDelay = 10 s by subject and treatment: {('AA0327', 'ZX1'): 32}
FRA mapping trials by subject: {'AA0320': 184, 'AA0318': 184, 'AA0322': 184, 'AA0319': 184, 'AA0327': 184, 'AA0330': 184, 'AA0333': 184}
  of these, group A mice: ['AA0318']
stimDelay-10 DRC trials (32), onset taken at 10 s: mean pupil (% of -4 to 0 s) over 0 to 2 s 103.24, over 2 to 4 s 102.05
stimDelay-10 DRC trials (32), onset taken at 4 s: mean pupil (% of -4 to 0 s) over 0 to 2 s 100.92, over 2 to 4 s 98.21

Figure 1: pure-tone responses, reliability and contrast scaling across baseline PD (group A)¶

Group A is the ten mice the files label pupilPTinContrast (the paper gives eight, four F and four M; the files give ten, four F and six M, one of them ZnT3-WT). Keeping the ZnT3-WT mouse AA0335, as the label does, is an assumption; group A without it is a variant at the end, and the Fig. 2b and Fig. 3b outcomes rest on this choice. CTRL trials of the CGC assay (DRC with the pure tone) are used. Per trial: the pure-tone response trace (dF/F minus its 1-2 s mean), the peak in each window, and the trial's baseline PD in % of the animal's maximum.

Readings run (claims file, shared methods): cell inclusion, SD over time of the trial-averaged trace (time) or across trials (trials), and responsive in both contrasts (both) or with contrasts pooled (pooled); peak window 2-2.8 s or 2-3.2 s; peak as the maximum of the cell's trial-averaged trace in the bin (avgmax) or the mean of its trial maxima (meanmax); bin 1 all trials below 21% (open) or 10 to 21% (10-21). The FRA-mapping reading of inclusion (claims file, (b)) cannot be run: mapping trials are in 7 of 30 files and only one group A mouse (AA0318; counts by subject in the Data check).

In [8]:
A = GROUPS["A"]
pt_ctrl = trials[(trials.kind == "pt") & (trials.treat == "CTRL") & trials.subject.isin(A)]
ct = zp.cell_trial_table(pt_ctrl)
base = tr.set_index("trial_id").base_pct_max
ct["base"] = ct.trial.map(base)
print("group A CTRL CGC-assay trials:", pt_ctrl.trial_id.nunique(), "; with a usable pupil:",
      int(pt_ctrl.trial_id.isin(base.index).sum()))
print("cells (ROIs) in group A:", ct.cell.nunique(), "; by mouse:", ct.groupby("subject").cell.nunique().to_dict())
INCL = {}
for sd in ("time", "trials"):
    for both in (True, False):
        INCL[(sd, "both" if both else "pooled")] = zp.responsive(ct, (2.0, 2.8), sd=sd, by_contrast=both)
print("tone-responsive cells under each inclusion reading (paper: 295 from eight mice):")
for k, v in INCL.items():
    print(f"  SD {k[0]:6s} {k[1]:6s}: {len(v)} cells")
ctb = ct[ct.base.notna()].copy()
print("cell-trials without a usable pupil (dropped):", int(ct.base.isna().sum()), "of", len(ct))

def bin_values(d, peak_col, window, mode, lower, by=("cell", "bin")):
    """Average peak per cell and bin (and contrast when in `by`)."""
    d = d.copy()
    d["bin"] = zp.pd_bin(d.base.values, 10 if lower == "10-21" else None)
    d = d[d.bin >= 0]
    out = []
    for key, g in d.groupby(list(by)):
        if mode == "meanmax":
            v = g[peak_col].mean()
        else:
            tr_ = np.vstack(g.trace.values).mean(0)
            t_ = g.t.iloc[0]
            v = tr_[(t_ >= window[0]) & (t_ < window[1])].max()
        out.append(dict(zip(by, key if isinstance(key, tuple) else (key,)), value=v, n=len(g)))
    return pd.DataFrame(out)

def kw(df):
    groups = [g.value.values for _, g in df.groupby("bin")]
    H, p = stats.kruskal(*groups)
    means = df.groupby("bin").value.mean()
    return H, p, int(means.idxmax()), means

WINDOWS = {"2-2.8": (2.0, 2.8), "2-3.2": (2.0, 3.2)}
rows = []
for (sd, bc), cells in INCL.items():
    d0 = ctb[ctb.cell.isin(cells)]
    for wn, w in WINDOWS.items():
        for mode in ("avgmax", "meanmax"):
            for lower in ("open", "10-21"):
                v = bin_values(d0, f"peak_{w[0]}_{w[1]}", w, mode, lower)
                H, p, top, means = kw(v)
                rows.append({"SD": sd, "contrasts": bc, "window": wn, "peak": mode, "bin1": lower,
                             "cells": v.cell.nunique(), "cell_bins": len(v), "H": round(H, 2), "p": p,
                             "top_bin": zp.BIN_LABELS[top], "inverse_U": 0 < top < 6,
                             **{f"m{b}": round(means.get(b, np.nan), 2) for b in range(7)}})
F1F = pd.DataFrame(rows)
print(F1F.to_string())
print("readings with p < 0.05 and an interior top bin:", int(((F1F.p < 0.05) & F1F.inverse_U).sum()), "of", len(F1F))
group A CTRL CGC-assay trials: 211 ; with a usable pupil: 209
cells (ROIs) in group A: 344 ; by mouse: {'AA0304': 37, 'AA0308': 46, 'AA0310': 54, 'AA0312': 25, 'AA0314': 36, 'AA0315': 27, 'AA0318': 41, 'AA0335': 12, 'AA0350': 43, 'AA0353': 23}
tone-responsive cells under each inclusion reading (paper: 295 from eight mice):
  SD time   both  : 318 cells
  SD time   pooled: 339 cells
  SD trials both  : 215 cells
  SD trials pooled: 241 cells
cell-trials without a usable pupil (dropped): 59 of 7404
        SD contrasts window     peak   bin1  cells  cell_bins      H             p top_bin  inverse_U     m0     m1     m2     m3     m4     m5     m6
0     time      both  2-2.8   avgmax   open    318       1270  51.83  2.014498e-09   21-32       True   8.12  15.88  15.53  12.82  12.65  10.96  13.08
1     time      both  2-2.8   avgmax  10-21    318       1270  51.83  2.014498e-09   21-32       True   8.12  15.88  15.53  12.82  12.65  10.96  13.08
2     time      both  2-2.8  meanmax   open    318       1270  46.22  2.680397e-08   21-32       True   8.68  16.18  16.08  13.31  13.37  11.65  13.71
3     time      both  2-2.8  meanmax  10-21    318       1270  46.22  2.680397e-08   21-32       True   8.68  16.18  16.08  13.31  13.37  11.65  13.71
4     time      both  2-3.2   avgmax   open    318       1270  51.57  2.279515e-09   21-32       True   8.13  15.88  15.57  12.83  12.67  10.99  13.12
5     time      both  2-3.2   avgmax  10-21    318       1270  51.57  2.279515e-09   21-32       True   8.13  15.88  15.57  12.83  12.67  10.99  13.12
6     time      both  2-3.2  meanmax   open    318       1270  44.04  7.265488e-08   21-32       True   8.78  16.26  16.16  13.38  13.48  11.90  13.81
7     time      both  2-3.2  meanmax  10-21    318       1270  44.04  7.265488e-08   21-32       True   8.78  16.26  16.16  13.38  13.48  11.90  13.81
8     time    pooled  2-2.8   avgmax   open    339       1338  53.23  1.053468e-09   21-32       True   7.88  15.65  15.28  12.17  12.10  10.78  12.96
9     time    pooled  2-2.8   avgmax  10-21    339       1338  53.23  1.053468e-09   21-32       True   7.88  15.65  15.28  12.17  12.10  10.78  12.96
10    time    pooled  2-2.8  meanmax   open    339       1338  46.76  2.093262e-08   21-32       True   8.48  15.96  15.83  12.67  12.81  11.47  13.56
11    time    pooled  2-2.8  meanmax  10-21    339       1338  46.76  2.093262e-08   21-32       True   8.48  15.96  15.83  12.67  12.81  11.47  13.56
12    time    pooled  2-3.2   avgmax   open    339       1338  53.00  1.171071e-09   21-32       True   7.89  15.65  15.32  12.18  12.12  10.80  12.99
13    time    pooled  2-3.2   avgmax  10-21    339       1338  53.00  1.171071e-09   21-32       True   7.89  15.65  15.32  12.18  12.12  10.80  12.99
14    time    pooled  2-3.2  meanmax   open    339       1338  44.56  5.720883e-08   21-32       True   8.59  16.03  15.91  12.74  12.92  11.72  13.66
15    time    pooled  2-3.2  meanmax  10-21    339       1338  44.56  5.720883e-08   21-32       True   8.59  16.03  15.91  12.74  12.92  11.72  13.66
16  trials      both  2-2.8   avgmax   open    215        883  51.47  2.386135e-09   21-32       True  10.34  19.63  18.62  15.33  15.53  13.28  17.47
17  trials      both  2-2.8   avgmax  10-21    215        883  51.47  2.386135e-09   21-32       True  10.34  19.63  18.62  15.33  15.53  13.28  17.47
18  trials      both  2-2.8  meanmax   open    215        883  46.90  1.958316e-08   21-32       True  10.87  19.86  19.14  15.73  16.17  13.90  17.98
19  trials      both  2-2.8  meanmax  10-21    215        883  46.90  1.958316e-08   21-32       True  10.87  19.86  19.14  15.73  16.17  13.90  17.98
20  trials      both  2-3.2   avgmax   open    215        883  51.41  2.448794e-09   21-32       True  10.34  19.63  18.62  15.33  15.53  13.29  17.47
21  trials      both  2-3.2   avgmax  10-21    215        883  51.41  2.448794e-09   21-32       True  10.34  19.63  18.62  15.33  15.53  13.29  17.47
22  trials      both  2-3.2  meanmax   open    215        883  45.65  3.473641e-08   21-32       True  10.92  19.93  19.14  15.78  16.23  14.07  18.01
23  trials      both  2-3.2  meanmax  10-21    215        883  45.65  3.473641e-08   21-32       True  10.92  19.93  19.14  15.78  16.23  14.07  18.01
24  trials    pooled  2-2.8   avgmax   open    241        978  58.25  1.020020e-10   21-32       True   9.99  18.97  18.52  14.96  14.73  12.61  16.40
25  trials    pooled  2-2.8   avgmax  10-21    241        978  58.25  1.020020e-10   21-32       True   9.99  18.97  18.52  14.96  14.73  12.61  16.40
26  trials    pooled  2-2.8  meanmax   open    241        978  52.46  1.510299e-09   21-32       True  10.49  19.21  19.14  15.37  15.36  13.24  16.92
27  trials    pooled  2-2.8  meanmax  10-21    241        978  52.46  1.510299e-09   21-32       True  10.49  19.21  19.14  15.37  15.36  13.24  16.92
28  trials    pooled  2-3.2   avgmax   open    241        978  58.22  1.033172e-10   21-32       True   9.99  18.97  18.52  14.96  14.73  12.62  16.41
29  trials    pooled  2-3.2   avgmax  10-21    241        978  58.22  1.033172e-10   21-32       True   9.99  18.97  18.52  14.96  14.73  12.62  16.41
30  trials    pooled  2-3.2  meanmax   open    241        978  50.80  3.242179e-09   21-32       True  10.54  19.28  19.15  15.41  15.42  13.44  16.99
31  trials    pooled  2-3.2  meanmax  10-21    241        978  50.80  3.242179e-09   21-32       True  10.54  19.28  19.15  15.41  15.42  13.44  16.99
readings with p < 0.05 and an interior top bin: 32 of 32
In [9]:
# Main reading (first listed): SD over time, both contrasts, 2-2.8 s, avgmax, bin 1 open; by mouse.
main_cells = INCL[("time", "both")]
v = bin_values(ctb[ctb.cell.isin(main_cells)], "peak_2.0_2.8", (2.0, 2.8), "avgmax", "open")
v["subject"] = v.cell.str.split("/").str[0]
print("cell-bins per bin:", v.groupby("bin").size().to_dict())
print("mean peak (% dF/F) by mouse and bin:")
print(v.pivot_table(index="subject", columns="bin", values="value", aggfunc="mean").round(1).to_string())
print("cells and bins per mouse:", v.groupby("subject").cell.nunique().to_dict())
fig, ax = plt.subplots(figsize=(4, 3))
mm = v.groupby("bin").value.agg(["mean", "sem"])
ax.errorbar([zp.BIN_LABELS[i] for i in mm.index], mm["mean"], mm["sem"], marker="o")
ax.set(xlabel="baseline PD (% animal max)", ylabel="peak pure-tone dF/F (%)"); plt.xticks(rotation=45); plt.tight_layout(); plt.show()
print("plotted means range", mm["mean"].min().round(2), "to", mm["mean"].max().round(2))
cell-bins per bin: {0: 74, 1: 174, 2: 174, 3: 196, 4: 254, 5: 225, 6: 173}
mean peak (% dF/F) by mouse and bin:
bin         0     1     2     3     4     5     6
subject                                          
AA0304    NaN   NaN   NaN   NaN   6.7   4.5   4.4
AA0308    NaN  17.2  19.7   9.0   7.4   6.0   NaN
AA0310    NaN  23.6  22.9  21.3  20.9  14.9  22.1
AA0312    NaN   NaN   NaN  21.1  17.9  19.0   NaN
AA0314    NaN   NaN   NaN   6.1   6.3   NaN  14.7
AA0315    NaN   NaN   NaN   NaN  16.0  15.3  12.7
AA0318    NaN   NaN   NaN   NaN  11.1   8.7   7.4
AA0335    7.6  10.1   5.9   2.3   7.8   NaN   NaN
AA0350   10.0  11.1   7.3   6.7   NaN   NaN   NaN
AA0353    4.8   6.0   9.0   NaN   NaN   NaN   NaN
cells and bins per mouse: {'AA0304': 32, 'AA0308': 46, 'AA0310': 54, 'AA0312': 25, 'AA0314': 19, 'AA0315': 27, 'AA0318': 41, 'AA0335': 10, 'AA0350': 42, 'AA0353': 22}
No description has been provided for this image
plotted means range 8.12 to 15.88
In [10]:
print("trials with baseline PD below 10% of animal max:", int((ctb.drop_duplicates("trial").base < 10).sum()),
      "; so the two bin-1 readings are the same here")
trials with baseline PD below 10% of animal max: 0 ; so the two bin-1 readings are the same here

Result: reproduced. Under the main reading (SD over time, both contrasts, 2-2.8 s, maximum of the averaged trace) 318 cells are tone-responsive, within the tolerance of 295 (265.5 to 324.5); the other inclusion readings give 339, 215 and 241. Peak responses differ across the seven baseline PD bins (Kruskal-Wallis H = 51.83, p = 2.0e-09), with the largest mean in the 21-32% bin (15.88% dF/F) against 8.12 in the lowest bin and 13.08 in the highest. All 32 readings give p < 0.05 (1.0e-10 to 7.3e-08) and the largest mean in the 21-32% bin. The bins are not independent of mouse: the lowest bin holds cells of three mice only (AA0335, AA0350, AA0353) and the highest of five. Under the other cleanings, and without the ZnT3-WT mouse AA0335, the main reading gives p = 2.8e-10 to 3.2e-06 with an interior top bin (variants at the end).

Reliability (Fig. 1g)¶

Per cell and bin, the mean over all pairs of the cell's trials in the bin of the zero-lag correlation of the pure-tone response traces at 2 to 3.2 s (six frames at 5 Hz): (a) Pearson, (b) normalized without mean removal.

In [11]:
def reliability(d, how):
    d = d.copy()
    d["bin"] = zp.pd_bin(d.base.values)
    out = []
    for (cell, b), g in d.groupby(["cell", "bin"]):
        if len(g) < 2:
            continue
        t_ = g.t.iloc[0]
        X = np.vstack(g.trace.values)[:, (t_ >= 2.0) & (t_ < 3.2)]
        if how == "pearson":
            X = X - X.mean(1, keepdims=True)
        nrm = np.linalg.norm(X, axis=1)
        ok = nrm > 0
        X = X[ok] / nrm[ok, None]
        if len(X) < 2:
            continue
        C = X @ X.T
        iu = np.triu_indices(len(X), 1)
        out.append({"cell": cell, "bin": b, "value": C[iu].mean(), "n": len(X)})
    return pd.DataFrame(out)

rows = []
for (sd, bc), cells in INCL.items():
    for how in ("pearson", "no_mean_removal"):
        v = reliability(ctb[ctb.cell.isin(cells)], how)
        H, p, top, means = kw(v)
        rows.append({"SD": sd, "contrasts": bc, "cc": how, "cells": v.cell.nunique(), "cell_bins": len(v),
                     "H": round(H, 2), "p": p, "top_bin": zp.BIN_LABELS[top], "interior": 0 < top < 6,
                     **{f"m{b}": round(means.get(b, np.nan), 3) for b in range(7)}})
F1G = pd.DataFrame(rows)
print(F1G.to_string())
print("cell-bins with fewer than two trials have no value")
       SD contrasts               cc  cells  cell_bins      H             p top_bin  interior     m0     m1     m2     m3     m4     m5     m6
0    time      both          pearson    318       1099  53.07  1.136506e-09   21-32      True  0.633  0.766  0.749  0.698  0.676  0.638  0.590
1    time      both  no_mean_removal    318       1099  42.90  1.220634e-07   21-32      True  0.631  0.818  0.770  0.730  0.737  0.700  0.739
2    time    pooled          pearson    339       1152  51.52  2.333179e-09   21-32      True  0.615  0.753  0.742  0.668  0.658  0.627  0.577
3    time    pooled  no_mean_removal    339       1152  40.74  3.261450e-07   21-32      True  0.609  0.804  0.755  0.704  0.711  0.688  0.721
4  trials      both          pearson    215        774  43.11  1.111813e-07   21-32      True  0.747  0.836  0.819  0.805  0.781  0.749  0.709
5  trials      both  no_mean_removal    215        774  39.32  6.192544e-07   21-32      True  0.776  0.895  0.863  0.840  0.831  0.794  0.841
6  trials    pooled          pearson    241        858  51.91  1.946013e-09   21-32      True  0.735  0.823  0.809  0.800  0.773  0.724  0.671
7  trials    pooled  no_mean_removal    241        858  42.17  1.704910e-07   21-32      True  0.764  0.883  0.855  0.825  0.810  0.777  0.818
cell-bins with fewer than two trials have no value

Result: reproduced. Reliability differs across bins under all eight readings (Kruskal-Wallis p = 1.1e-09 to 6.2e-07), and the bin with the highest mean is 21-32% in every reading (Pearson, main inclusion: 0.766 against 0.633 in the lowest bin and 0.590 in the highest).

Contrast scaling factor (Fig. 1h)¶

Per cell (responsive in both contrasts) and bin with trials of both contrasts: average peak in LOW divided by average peak in HIGH, under both peak readings and windows.

In [12]:
def scaling(d, w, mode):
    vals = bin_values(d, f"peak_{w[0]}_{w[1]}", w, mode, "open", by=("cell", "bin", "contrast"))
    pv = vals.pivot_table(index=["cell", "bin"], columns="contrast", values="value").dropna()
    pv["value"] = pv.LOW / pv.HIGH
    return pv.reset_index()

rows, SCAL = [], {}
for sd in ("time", "trials"):
    cells = INCL[(sd, "both")]
    for wn, w in WINDOWS.items():
        for mode in ("avgmax", "meanmax"):
            v = scaling(ctb[ctb.cell.isin(cells)], w, mode)
            SCAL[(sd, wn, mode)] = v
            H, p, top, means = kw(v)
            med = v.groupby("bin").value.median()
            rows.append({"SD": sd, "window": wn, "peak": mode, "cells": v.cell.nunique(), "cell_bins": len(v),
                         "H": round(H, 2), "p": p, "top_bin(mean)": zp.BIN_LABELS[top], "interior": 0 < top < 6,
                         "HIGH<=0": int((v.HIGH <= 0).sum()),
                         **{f"mean{b}": round(means.get(b, np.nan), 2) for b in range(7)},
                         **{f"med{b}": round(med.get(b, np.nan), 2) for b in range(7)}})
F1H = pd.DataFrame(rows)
print(F1H.to_string())
v = SCAL[("time", "2-2.8", "avgmax")]
print("main reading: range of factors", v.value.min().round(2), "to", v.value.max().round(2))
       SD window     peak  cells  cell_bins      H             p top_bin(mean)  interior  HIGH<=0  mean0  mean1  mean2  mean3  mean4  mean5  mean6  med0  med1  med2  med3  med4  med5  med6
0    time  2-2.8   avgmax    318        915  64.50  5.456808e-12         54-65      True        5   1.38   1.23   1.03   0.62   1.49   1.32   1.21  1.06  1.11  0.92  1.21  1.34  1.04  1.24
1    time  2-2.8  meanmax    318        915  53.13  1.105688e-09         54-65      True        4   1.22   1.21   1.04   0.96   1.39   1.37   1.15  1.05  1.11  0.98  1.21  1.29  1.09  1.19
2    time  2-3.2   avgmax    318        915  68.67  7.665810e-13         54-65      True        4   1.40   1.22   1.03   0.87   1.50   1.32   1.21  1.06  1.10  0.92  1.22  1.34  1.05  1.24
3    time  2-3.2  meanmax    318        915  57.56  1.408619e-10         43-54      True        3   1.20   1.21   1.03   1.72   1.39   1.38   1.14  1.05  1.10  0.98  1.23  1.29  1.14  1.19
4  trials  2-2.8   avgmax    215        621  90.39  2.518580e-17         54-65      True        0   1.16   1.13   1.01   1.45   1.49   1.30   1.37  0.96  1.03  0.95  1.21  1.31  0.95  1.32
5  trials  2-2.8  meanmax    215        621  75.03  3.791037e-14         54-65      True        0   1.12   1.15   1.02   1.45   1.46   1.35   1.32  0.95  1.04  0.97  1.23  1.29  1.01  1.29
6  trials  2-3.2   avgmax    215        621  89.24  4.365466e-17         54-65      True        0   1.16   1.13   1.01   1.47   1.49   1.30   1.37  0.96  1.03  0.95  1.21  1.31  0.96  1.32
7  trials  2-3.2  meanmax    215        621  69.77  4.565342e-13         54-65      True        0   1.11   1.15   1.02   1.46   1.47   1.39   1.32  0.95  1.04  0.97  1.23  1.28  1.04  1.29
main reading: range of factors -109.53 to 37.83

Result: reproduced. The contrast scaling factor differs across bins under all eight readings (Kruskal-Wallis p = 2.5e-17 to 1.1e-09), and the bin with the highest mean is 54-65% in seven readings and 43-54% in one, never the first or last. The means are pulled by a few cells whose HIGH peak is near or below 0 (factors from -109.5 to 37.8 in the main reading; 0 to 5 cell-bins with a HIGH peak at or below 0 per reading); the medians also peak in the 54-65% bin (1.34) in the main reading. The paper's figure has its maximum in the 43-54% bin, which the main reading gives when AA0335 is left out (variants at the end).

In [13]:
rows = []
for key, v in SCAL.items():
    for b, g in v.groupby("bin"):
        x = g.value.values
        rows.append({"SD": key[0], "window": key[1], "peak": key[2], "bin": zp.BIN_LABELS[b], "n": len(x),
                     "mean": x.mean().round(3), "median": np.median(x).round(3),
                     "wilcoxon_2s": stats.wilcoxon(x - 1).pvalue,
                     "wilcoxon_1s": stats.wilcoxon(x - 1, alternative="greater").pvalue,
                     "t_2s": stats.ttest_1samp(x, 1).pvalue,
                     "t_1s": stats.ttest_1samp(x, 1, alternative="greater").pvalue})
F1HE = pd.DataFrame(rows)
F1HE["all_sig"] = (F1HE[["wilcoxon_2s", "wilcoxon_1s", "t_2s", "t_1s"]] < 0.05).all(1) & (F1HE["mean"] > 1)
print(F1HE.round(4).to_string())
print(F1HE.groupby(["SD", "window", "peak"]).all_sig.sum().rename("bins significant under all four tests (of 7)").to_string())
for test in ["wilcoxon_2s", "wilcoxon_1s", "t_2s", "t_1s"]:
    print(test, "bins with p < 0.05 and mean > 1, by reading:",
          F1HE.assign(ok=(F1HE[test] < 0.05) & (F1HE["mean"] > 1)).groupby(["SD", "window", "peak"]).ok.sum().to_dict())
        SD window     peak    bin    n   mean  median  wilcoxon_2s  wilcoxon_1s    t_2s    t_1s  all_sig
0     time  2-2.8   avgmax    <21   74  1.375   1.063       0.0091       0.0045  0.0015  0.0008     True
1     time  2-2.8   avgmax  21-32  128  1.230   1.114       0.0000       0.0000  0.0000  0.0000     True
2     time  2-2.8   avgmax  32-43  110  1.033   0.920       0.5302       0.7349  0.4395  0.2198    False
3     time  2-2.8   avgmax  43-54  129  0.619   1.207       0.0000       0.0000  0.6844  0.6578    False
4     time  2-2.8   avgmax  54-65  203  1.492   1.337       0.0000       0.0000  0.0000  0.0000     True
5     time  2-2.8   avgmax  65-76  171  1.318   1.042       0.0009       0.0005  0.0000  0.0000     True
6     time  2-2.8   avgmax    >76  100  1.214   1.242       0.0014       0.0007  0.0012  0.0006     True
7     time  2-2.8  meanmax    <21   74  1.219   1.050       0.0155       0.0077  0.0563  0.0282    False
8     time  2-2.8  meanmax  21-32  128  1.213   1.111       0.0000       0.0000  0.0000  0.0000     True
9     time  2-2.8  meanmax  32-43  110  1.035   0.984       0.9370       0.5315  0.3446  0.1723    False
10    time  2-2.8  meanmax  43-54  129  0.957   1.211       0.0000       0.0000  0.9632  0.5184    False
11    time  2-2.8  meanmax  54-65  203  1.391   1.288       0.0000       0.0000  0.0005  0.0003     True
12    time  2-2.8  meanmax  65-76  171  1.367   1.086       0.0000       0.0000  0.0000  0.0000     True
13    time  2-2.8  meanmax    >76  100  1.153   1.192       0.0051       0.0025  0.0028  0.0014     True
14    time  2-3.2   avgmax    <21   74  1.398   1.063       0.0091       0.0045  0.0014  0.0007     True
15    time  2-3.2   avgmax  21-32  128  1.225   1.096       0.0001       0.0000  0.0000  0.0000     True
16    time  2-3.2   avgmax  32-43  110  1.030   0.920       0.4496       0.7752  0.4736  0.2368    False
17    time  2-3.2   avgmax  43-54  129  0.867   1.225       0.0000       0.0000  0.8838  0.5581    False
18    time  2-3.2   avgmax  54-65  203  1.500   1.338       0.0000       0.0000  0.0000  0.0000     True
19    time  2-3.2   avgmax  65-76  171  1.316   1.047       0.0004       0.0002  0.0000  0.0000     True
20    time  2-3.2   avgmax    >76  100  1.207   1.239       0.0031       0.0016  0.0018  0.0009     True
21    time  2-3.2  meanmax    <21   74  1.203   1.050       0.0174       0.0087  0.0800  0.0400    False
22    time  2-3.2  meanmax  21-32  128  1.211   1.105       0.0000       0.0000  0.0000  0.0000     True
23    time  2-3.2  meanmax  32-43  110  1.035   0.976       0.8826       0.5587  0.3499  0.1750    False
24    time  2-3.2  meanmax  43-54  129  1.715   1.229       0.0000       0.0000  0.0171  0.0086     True
25    time  2-3.2  meanmax  54-65  203  1.392   1.294       0.0000       0.0000  0.0011  0.0006     True
26    time  2-3.2  meanmax  65-76  171  1.384   1.139       0.0000       0.0000  0.0000  0.0000     True
27    time  2-3.2  meanmax    >76  100  1.141   1.185       0.0100       0.0050  0.0064  0.0032     True
28  trials  2-2.8   avgmax    <21   40  1.157   0.959       0.9841       0.5133  0.0946  0.0473    False
29  trials  2-2.8   avgmax  21-32   89  1.134   1.032       0.0410       0.0205  0.0163  0.0082     True
30  trials  2-2.8   avgmax  32-43   80  1.006   0.951       0.6045       0.6978  0.8711  0.4355    False
31  trials  2-2.8   avgmax  43-54   95  1.451   1.206       0.0000       0.0000  0.0000  0.0000     True
32  trials  2-2.8   avgmax  54-65  148  1.488   1.311       0.0000       0.0000  0.0000  0.0000     True
33  trials  2-2.8   avgmax  65-76  111  1.298   0.948       0.2176       0.1088  0.0058  0.0029    False
34  trials  2-2.8   avgmax    >76   58  1.373   1.319       0.0000       0.0000  0.0000  0.0000     True
35  trials  2-2.8  meanmax    <21   40  1.125   0.948       0.8785       0.5660  0.1372  0.0686    False
36  trials  2-2.8  meanmax  21-32   89  1.146   1.038       0.0159       0.0079  0.0152  0.0076     True
37  trials  2-2.8  meanmax  32-43   80  1.018   0.971       0.9426       0.4713  0.5886  0.2943    False
38  trials  2-2.8  meanmax  43-54   95  1.449   1.226       0.0000       0.0000  0.0000  0.0000     True
39  trials  2-2.8  meanmax  54-65  148  1.460   1.290       0.0000       0.0000  0.0001  0.0000     True
40  trials  2-2.8  meanmax  65-76  111  1.351   1.014       0.0292       0.0146  0.0016  0.0008     True
41  trials  2-2.8  meanmax    >76   58  1.318   1.287       0.0000       0.0000  0.0000  0.0000     True
42  trials  2-3.2   avgmax    <21   40  1.157   0.959       0.9841       0.5133  0.0946  0.0473    False
43  trials  2-3.2   avgmax  21-32   89  1.134   1.032       0.0410       0.0205  0.0163  0.0082     True
44  trials  2-3.2   avgmax  32-43   80  1.006   0.951       0.6045       0.6978  0.8711  0.4355    False
45  trials  2-3.2   avgmax  43-54   95  1.474   1.207       0.0000       0.0000  0.0000  0.0000     True
46  trials  2-3.2   avgmax  54-65  148  1.488   1.311       0.0000       0.0000  0.0000  0.0000     True
47  trials  2-3.2   avgmax  65-76  111  1.303   0.958       0.1553       0.0776  0.0051  0.0026    False
48  trials  2-3.2   avgmax    >76   58  1.373   1.319       0.0000       0.0000  0.0000  0.0000     True
49  trials  2-3.2  meanmax    <21   40  1.114   0.948       0.8368       0.5868  0.1654  0.0827    False
50  trials  2-3.2  meanmax  21-32   89  1.155   1.038       0.0118       0.0059  0.0106  0.0053     True
51  trials  2-3.2  meanmax  32-43   80  1.015   0.971       0.9312       0.5344  0.6445  0.3222    False
52  trials  2-3.2  meanmax  43-54   95  1.459   1.229       0.0000       0.0000  0.0000  0.0000     True
53  trials  2-3.2  meanmax  54-65  148  1.470   1.283       0.0000       0.0000  0.0001  0.0000     True
54  trials  2-3.2  meanmax  65-76  111  1.387   1.038       0.0019       0.0009  0.0005  0.0003     True
55  trials  2-3.2  meanmax    >76   58  1.316   1.287       0.0000       0.0000  0.0000  0.0000     True
SD      window  peak   
time    2-2.8   avgmax     5
                meanmax    4
        2-3.2   avgmax     5
                meanmax    5
trials  2-2.8   avgmax     4
                meanmax    5
        2-3.2   avgmax     4
                meanmax    5
wilcoxon_2s bins with p < 0.05 and mean > 1, by reading: {('time', '2-2.8', 'avgmax'): 5, ('time', '2-2.8', 'meanmax'): 5, ('time', '2-3.2', 'avgmax'): 5, ('time', '2-3.2', 'meanmax'): 6, ('trials', '2-2.8', 'avgmax'): 4, ('trials', '2-2.8', 'meanmax'): 5, ('trials', '2-3.2', 'avgmax'): 4, ('trials', '2-3.2', 'meanmax'): 5}
wilcoxon_1s bins with p < 0.05 and mean > 1, by reading: {('time', '2-2.8', 'avgmax'): 5, ('time', '2-2.8', 'meanmax'): 5, ('time', '2-3.2', 'avgmax'): 5, ('time', '2-3.2', 'meanmax'): 6, ('trials', '2-2.8', 'avgmax'): 4, ('trials', '2-2.8', 'meanmax'): 5, ('trials', '2-3.2', 'avgmax'): 4, ('trials', '2-3.2', 'meanmax'): 5}
t_2s bins with p < 0.05 and mean > 1, by reading: {('time', '2-2.8', 'avgmax'): 5, ('time', '2-2.8', 'meanmax'): 4, ('time', '2-3.2', 'avgmax'): 5, ('time', '2-3.2', 'meanmax'): 5, ('trials', '2-2.8', 'avgmax'): 5, ('trials', '2-2.8', 'meanmax'): 5, ('trials', '2-3.2', 'avgmax'): 5, ('trials', '2-3.2', 'meanmax'): 5}
t_1s bins with p < 0.05 and mean > 1, by reading: {('time', '2-2.8', 'avgmax'): 5, ('time', '2-2.8', 'meanmax'): 5, ('time', '2-3.2', 'avgmax'): 5, ('time', '2-3.2', 'meanmax'): 6, ('trials', '2-2.8', 'avgmax'): 6, ('trials', '2-2.8', 'meanmax'): 5, ('trials', '2-3.2', 'avgmax'): 6, ('trials', '2-3.2', 'meanmax'): 5}

Result: not reproduced. Under no reading are all seven bins significantly above 1. The 32-43% bin has a mean factor of 1.006 to 1.035 and p >= 0.17 under every reading and test. The best readings have six bins significant under some of the tests (for example SD over time, 2-3.2 s, mean of trial maxima, under both Wilcoxon tests and the one-sided t test). Under the main reading the 43-54% bin has a mean of 0.619 (median 1.207) and five bins pass all four tests.

Two-way ANOVA of peak responses by bin and contrast (Fig. 1i)¶

In [14]:
import statsmodels.api as sm
def anova_1i(d, w, mode, pairing):
    vals = bin_values(d, f"peak_{w[0]}_{w[1]}", w, mode, "open", by=("cell", "bin", "contrast"))
    if pairing == "both":
        pv = vals.pivot_table(index=["cell", "bin"], columns="contrast", values="value").dropna()
        keep = set(pv.index)
        vals = vals[[k in keep for k in zip(vals.cell, vals.bin)]]
    m = smf.ols("value ~ C(bin) * C(contrast)", data=vals).fit()
    a = sm.stats.anova_lm(m, typ=2)
    return vals, m, a

rows, ANOVA = [], {}
for (sd, bc), cells in INCL.items():
    for wn, w in WINDOWS.items():
        for mode in ("avgmax", "meanmax"):
            for pairing in ("all", "both"):
                vals, m, a = anova_1i(ctb[ctb.cell.isin(cells)], w, mode, pairing)
                ANOVA[(sd, bc, wn, mode, pairing)] = (vals, m, a)
                rows.append({"SD": sd, "contrasts": bc, "window": wn, "peak": mode, "values_in": pairing,
                             "n_values": len(vals), "df_err": int(m.df_resid),
                             "F_bin": a.loc["C(bin)", "F"].round(2), "p_bin": a.loc["C(bin)", "PR(>F)"],
                             "F_int": a.loc["C(bin):C(contrast)", "F"].round(2),
                             "p_int": a.loc["C(bin):C(contrast)", "PR(>F)"],
                             "F_contrast": a.loc["C(contrast)", "F"].round(2), "p_contrast": a.loc["C(contrast)", "PR(>F)"]})
F1I = pd.DataFrame(rows)
F1I["count_ok"] = (F1I.n_values - 1885).abs() <= 188.5
print(F1I.to_string())
print("paper: 1885 values (error df 1871), F_bin = 10.74, F_int = 6.01")
        SD contrasts window     peak values_in  n_values  df_err  F_bin         p_bin  F_int     p_int  F_contrast  p_contrast  count_ok
0     time      both  2-2.8   avgmax       all      2185    2171  21.77  5.583381e-25   4.81  0.000069        6.22    0.012679     False
1     time      both  2-2.8   avgmax      both      1830    1816  40.33  2.713717e-46   2.88  0.008423       11.65    0.000656      True
2     time      both  2-2.8  meanmax       all      2185    2171  20.35  2.751987e-23   4.52  0.000145        6.66    0.009934     False
3     time      both  2-2.8  meanmax      both      1830    1816  38.62  2.367051e-44   2.21  0.039700       12.15    0.000502      True
4     time      both  2-3.2   avgmax       all      2185    2171  21.67  7.397435e-25   4.89  0.000057        6.20    0.012820     False
5     time      both  2-3.2   avgmax      both      1830    1816  40.23  3.533306e-46   2.96  0.006998       11.64    0.000658      True
6     time      both  2-3.2  meanmax       all      2185    2171  19.83  1.151979e-22   4.57  0.000130        7.29    0.006983     False
7     time      both  2-3.2  meanmax      both      1830    1816  38.07  1.008206e-43   2.26  0.035184       13.04    0.000313      True
8     time    pooled  2-2.8   avgmax       all      2304    2290  22.23  1.450212e-25   4.89  0.000057        8.04    0.004625     False
9     time    pooled  2-2.8   avgmax      both      1932    1918  41.12  2.411825e-47   2.94  0.007389       13.66    0.000225      True
10    time    pooled  2-2.8  meanmax       all      2304    2290  20.76  8.227215e-24   4.61  0.000115        8.30    0.003999     False
11    time    pooled  2-2.8  meanmax      both      1932    1918  39.29  2.982023e-45   2.29  0.033048       14.01    0.000187      True
12    time    pooled  2-3.2   avgmax       all      2304    2290  22.14  1.831305e-25   4.97  0.000046        7.97    0.004803     False
13    time    pooled  2-3.2   avgmax      both      1932    1918  41.03  3.078645e-47   3.02  0.006117       13.60    0.000233      True
14    time    pooled  2-3.2  meanmax       all      2304    2290  20.25  3.345601e-23   4.65  0.000105        8.87    0.002922     False
15    time    pooled  2-3.2  meanmax      both      1932    1918  38.71  1.344692e-44   2.34  0.029818       14.80    0.000124      True
16  trials      both  2-2.8   avgmax       all      1504    1490  14.72  2.151537e-16   2.85  0.009299        8.81    0.003048     False
17  trials      both  2-2.8   avgmax      both      1242    1228  26.41  1.096819e-29   2.72  0.012647       10.60    0.001160     False
18  trials      both  2-2.8  meanmax       all      1504    1490  13.90  1.983061e-15   2.56  0.017942        9.44    0.002157     False
19  trials      both  2-2.8  meanmax      both      1242    1228  25.17  2.770381e-28   2.14  0.046137       11.30    0.000801     False
20  trials      both  2-3.2   avgmax       all      1504    1490  14.66  2.534508e-16   2.83  0.009606        8.88    0.002928     False
21  trials      both  2-3.2   avgmax      both      1242    1228  26.35  1.297940e-29   2.70  0.012974       10.68    0.001112     False
22  trials      both  2-3.2  meanmax       all      1504    1490  13.56  4.970274e-15   2.45  0.023100       10.19    0.001444     False
23  trials      both  2-3.2  meanmax      both      1242    1228  24.84  6.543394e-28   2.09  0.052010       12.23    0.000488     False
24  trials    pooled  2-2.8   avgmax       all      1669    1655  18.45  7.627729e-21   2.93  0.007515        7.73    0.005491     False
25  trials    pooled  2-2.8   avgmax      both      1382    1368  33.56  6.327967e-38   3.06  0.005578       11.10    0.000889     False
26  trials    pooled  2-2.8  meanmax       all      1669    1655  17.48  1.062862e-19   2.63  0.015422        8.14    0.004373     False
27  trials    pooled  2-2.8  meanmax      both      1382    1368  32.13  2.523486e-36   2.43  0.024285       11.64    0.000664     False
28  trials    pooled  2-3.2   avgmax       all      1669    1655  18.30  1.135746e-20   2.92  0.007729        7.79    0.005305     False
29  trials    pooled  2-3.2   avgmax      both      1382    1368  33.34  1.116258e-37   3.05  0.005793       11.13    0.000872     False
30  trials    pooled  2-3.2  meanmax       all      1669    1655  16.98  4.118338e-19   2.56  0.018070        8.79    0.003071     False
31  trials    pooled  2-3.2  meanmax      both      1382    1368  31.47  1.373048e-35   2.39  0.026537       12.44    0.000434     False
paper: 1885 values (error df 1871), F_bin = 10.74, F_int = 6.01

Result: reproduced. The readings that keep only cell-bins with both contrasts give 1830 (SD over time, both contrasts) and 1932 values (contrasts pooled), within the tolerance of 1885. In these, the bin effect is F = 38.07 to 41.12 (p <= 1.0e-43) and the bin by contrast interaction F = 2.21 to 3.02 (p = 0.0061 to 0.040), so both are significant. Keeping every cell-bin-contrast gives 2185 or 2304 values and the interaction F = 4.52 to 4.97 (p <= 0.00015). The bin effect is larger than the paper's F = 10.74 in every reading. Without AA0335 the main reading gives an interaction p of 0.0046; with the single cleaning pass it gives p = 0.17 (variants at the end).

In [15]:
def posthoc(vals, m):
    mse = m.mse_resid; df = m.df_resid
    g = vals.groupby(["bin", "contrast"]).value.agg(["mean", "count"])
    rows = []
    for b in range(7):
        if (b, "LOW") not in g.index or (b, "HIGH") not in g.index:
            continue
        lo, hi = g.loc[(b, "LOW")], g.loc[(b, "HIGH")]
        tval = (lo["mean"] - hi["mean"]) / np.sqrt(mse * (1 / lo["count"] + 1 / hi["count"]))
        p = 2 * stats.t.sf(abs(tval), df)
        rows.append({"bin": zp.BIN_LABELS[b], "LOW": round(lo["mean"], 2), "HIGH": round(hi["mean"], 2),
                     "t": round(tval, 2), "p_raw": p, "p_bonf7": min(1, p * 7), "p_bonf91": min(1, p * 91)})
    return pd.DataFrame(rows)

rows = []
for key, (vals, m, a) in ANOVA.items():
    ph = posthoc(vals, m)
    for fam in ("p_bonf7", "p_bonf91"):
        sig = ph.loc[ph[fam] < 0.05, "bin"].tolist()
        rows.append({"SD": key[0], "contrasts": key[1], "window": key[2], "peak": key[3], "values_in": key[4],
                     "family": fam, "significant_bins": sig, "only_43_54": sig == ["43-54"],
                     "p_43_54": ph.set_index("bin").loc["43-54", fam]})
F1IP = pd.DataFrame(rows)
print(F1IP.to_string())
allp = F1IP[(F1IP.values_in == "all") & (F1IP.family == "p_bonf91")]
for sd, g in allp.groupby("SD"):
    n = F1I[(F1I.SD == sd) & (F1I.values_in == "all")].n_values.unique().tolist()
    print(f"values_in = all, SD over {sd} ({n} values): 43-54 the only significant bin with 91 comparisons "
          f"in {int(g.only_43_54.sum())} of {len(g)} readings")
key = ("time", "both", "2-2.8", "avgmax", "all")
print("reading with every cell-bin-contrast (SD over time, both contrasts, 2-2.8 s, avgmax; 2185 values, "
      "outside the count tolerance), per bin:")
print(posthoc(*ANOVA[key][:2]).to_string())
        SD contrasts window     peak values_in    family significant_bins  only_43_54   p_43_54
0     time      both  2-2.8   avgmax       all   p_bonf7   [43-54, 54-65]       False  0.000162
1     time      both  2-2.8   avgmax       all  p_bonf91          [43-54]        True  0.002101
2     time      both  2-2.8   avgmax      both   p_bonf7          [54-65]       False  0.214417
3     time      both  2-2.8   avgmax      both  p_bonf91          [54-65]       False  1.000000
4     time      both  2-2.8  meanmax       all   p_bonf7   [43-54, 54-65]       False  0.000135
5     time      both  2-2.8  meanmax       all  p_bonf91          [43-54]        True  0.001760
6     time      both  2-2.8  meanmax      both   p_bonf7          [54-65]       False  0.208012
7     time      both  2-2.8  meanmax      both  p_bonf91          [54-65]       False  1.000000
8     time      both  2-3.2   avgmax       all   p_bonf7   [43-54, 54-65]       False  0.000167
9     time      both  2-3.2   avgmax       all  p_bonf91   [43-54, 54-65]       False  0.002171
10    time      both  2-3.2   avgmax      both   p_bonf7          [54-65]       False  0.218165
11    time      both  2-3.2   avgmax      both  p_bonf91          [54-65]       False  1.000000
12    time      both  2-3.2  meanmax       all   p_bonf7   [43-54, 54-65]       False  0.000123
13    time      both  2-3.2  meanmax       all  p_bonf91          [43-54]        True  0.001597
14    time      both  2-3.2  meanmax      both   p_bonf7          [54-65]       False  0.197161
15    time      both  2-3.2  meanmax      both  p_bonf91          [54-65]       False  1.000000
16    time    pooled  2-2.8   avgmax       all   p_bonf7   [43-54, 54-65]       False  0.000063
17    time    pooled  2-2.8   avgmax       all  p_bonf91   [43-54, 54-65]       False  0.000825
18    time    pooled  2-2.8   avgmax      both   p_bonf7          [54-65]       False  0.095452
19    time    pooled  2-2.8   avgmax      both  p_bonf91          [54-65]       False  1.000000
20    time    pooled  2-2.8  meanmax       all   p_bonf7   [43-54, 54-65]       False  0.000057
21    time    pooled  2-2.8  meanmax       all  p_bonf91          [43-54]        True  0.000747
22    time    pooled  2-2.8  meanmax      both   p_bonf7          [54-65]       False  0.098373
23    time    pooled  2-2.8  meanmax      both  p_bonf91          [54-65]       False  1.000000
24    time    pooled  2-3.2   avgmax       all   p_bonf7   [43-54, 54-65]       False  0.000069
25    time    pooled  2-3.2   avgmax       all  p_bonf91   [43-54, 54-65]       False  0.000898
26    time    pooled  2-3.2   avgmax      both   p_bonf7          [54-65]       False  0.101242
27    time    pooled  2-3.2   avgmax      both  p_bonf91          [54-65]       False  1.000000
28    time    pooled  2-3.2  meanmax       all   p_bonf7   [43-54, 54-65]       False  0.000054
29    time    pooled  2-3.2  meanmax       all  p_bonf91          [43-54]        True  0.000706
30    time    pooled  2-3.2  meanmax      both   p_bonf7          [54-65]       False  0.095956
31    time    pooled  2-3.2  meanmax      both  p_bonf91          [54-65]       False  1.000000
32  trials      both  2-2.8   avgmax       all   p_bonf7   [43-54, 54-65]       False  0.001822
33  trials      both  2-2.8   avgmax       all  p_bonf91          [43-54]        True  0.023687
34  trials      both  2-2.8   avgmax      both   p_bonf7          [54-65]       False  0.261947
35  trials      both  2-2.8   avgmax      both  p_bonf91          [54-65]       False  1.000000
36  trials      both  2-2.8  meanmax       all   p_bonf7   [43-54, 54-65]       False  0.001491
37  trials      both  2-2.8  meanmax       all  p_bonf91          [43-54]        True  0.019383
38  trials      both  2-2.8  meanmax      both   p_bonf7          [54-65]       False  0.230784
39  trials      both  2-2.8  meanmax      both  p_bonf91          [54-65]       False  1.000000
40  trials      both  2-3.2   avgmax       all   p_bonf7   [43-54, 54-65]       False  0.001786
41  trials      both  2-3.2   avgmax       all  p_bonf91          [43-54]        True  0.023215
42  trials      both  2-3.2   avgmax      both   p_bonf7          [54-65]       False  0.258364
43  trials      both  2-3.2   avgmax      both  p_bonf91          [54-65]       False  1.000000
44  trials      both  2-3.2  meanmax       all   p_bonf7   [43-54, 54-65]       False  0.001402
45  trials      both  2-3.2  meanmax       all  p_bonf91          [43-54]        True  0.018230
46  trials      both  2-3.2  meanmax      both   p_bonf7          [54-65]       False  0.221617
47  trials      both  2-3.2  meanmax      both  p_bonf91          [54-65]       False  1.000000
48  trials    pooled  2-2.8   avgmax       all   p_bonf7   [43-54, 54-65]       False  0.001431
49  trials    pooled  2-2.8   avgmax       all  p_bonf91          [43-54]        True  0.018598
50  trials    pooled  2-2.8   avgmax      both   p_bonf7          [54-65]       False  0.191805
51  trials    pooled  2-2.8   avgmax      both  p_bonf91          [54-65]       False  1.000000
52  trials    pooled  2-2.8  meanmax       all   p_bonf7   [43-54, 54-65]       False  0.001241
53  trials    pooled  2-2.8  meanmax       all  p_bonf91          [43-54]        True  0.016134
54  trials    pooled  2-2.8  meanmax      both   p_bonf7          [54-65]       False  0.177710
55  trials    pooled  2-2.8  meanmax      both  p_bonf91          [54-65]       False  1.000000
56  trials    pooled  2-3.2   avgmax       all   p_bonf7   [43-54, 54-65]       False  0.001399
57  trials    pooled  2-3.2   avgmax       all  p_bonf91          [43-54]        True  0.018181
58  trials    pooled  2-3.2   avgmax      both   p_bonf7          [54-65]       False  0.189051
59  trials    pooled  2-3.2   avgmax      both  p_bonf91          [54-65]       False  1.000000
60  trials    pooled  2-3.2  meanmax       all   p_bonf7   [43-54, 54-65]       False  0.001164
61  trials    pooled  2-3.2  meanmax       all  p_bonf91          [43-54]        True  0.015126
62  trials    pooled  2-3.2  meanmax      both   p_bonf7          [54-65]       False  0.170724
63  trials    pooled  2-3.2  meanmax      both  p_bonf91          [54-65]       False  1.000000
values_in = all, SD over time ([2185, 2304] values): 43-54 the only significant bin with 91 comparisons in 5 of 8 readings
values_in = all, SD over trials ([1504, 1669] values): 43-54 the only significant bin with 91 comparisons in 8 of 8 readings
reading with every cell-bin-contrast (SD over time, both contrasts, 2-2.8 s, avgmax; 2185 values, outside the count tolerance), per bin:
     bin    LOW   HIGH     t     p_raw   p_bonf7  p_bonf91
0    <21   8.80   7.82  0.55  0.579915  1.000000  1.000000
1  21-32  15.98  15.52  0.36  0.718639  1.000000  1.000000
2  32-43  17.92  17.61  0.24  0.812524  1.000000  1.000000
3  43-54  15.54  10.43  4.24  0.000023  0.000162  0.002101
4  54-65  14.99  11.47  3.45  0.000579  0.004051  0.052669
5  65-76   9.84  10.88 -0.94  0.348296  1.000000  1.000000
6    >76   9.85  12.45 -1.96  0.050199  0.351393  1.000000

Result: not reproduced. On the ANOVAs whose count of values is within tolerance (fig1i-baseline-contrast-interaction), the 43-54% bin is not significant under either Bonferroni family (corrected p = 0.095 to 0.22 with seven comparisons, 1 with 91), and the 54-65% bin is the only significant one under both families. Keeping every cell-bin-contrast (2185 or 2304 values, outside the tolerance), the 43-54% bin is significant (main reading LOW 15.54 against HIGH 10.43% dF/F, corrected p = 0.00016 with seven comparisons and 0.0021 with 91); with 91 comparisons it is the only one in 5 of the 8 such readings with SD over time (2185 or 2304 values) and in 8 of 8 with SD across trials (1504 or 1669 values, also outside the tolerance), as the paper reports, while with seven the 54-65% bin is significant too.

Figure 2: evoked PD in high and low contrast (CGC-assay trials)¶

Per trial, the mean evoked PD (% baseline) over 0 to 8 s and over 1 to 2 s from DRC onset; trials with baseline PD < 50% of animal max; CTRL trials of the CGC assay. Mice readings: (a) group A, (b) group B before ZX1, (c) all mice with CTRL CGC-assay trials (A and B pooled; they share five mice). Unit: (a) trials, (b) per-mouse means per contrast. Two-sided Wilcoxon rank sum, high against low.

In [16]:
ptp = tr[(tr.kind == "pt") & (tr.treat == "CTRL")]
MICE2 = {"A": GROUPS["A"], "B": GROUPS["B"], "A+B": sorted(set(GROUPS["A"]) | set(GROUPS["B"]))}
print("mice shared by A and B:", sorted(set(GROUPS["A"]) & set(GROUPS["B"])))
def fig2_test(col):
    rows = []
    for name, mice in MICE2.items():
        d = ptp[ptp.subject.isin(mice) & (ptp.base_pct_max < 50)]
        hi, lo = d[d.contrast == "HIGH"][col], d[d.contrast == "LOW"][col]
        r = stats.ranksums(hi, lo)
        pm = d.groupby(["subject", "contrast"])[col].mean().unstack()
        r2 = stats.ranksums(pm.HIGH.dropna(), pm.LOW.dropna())
        rows.append({"mice": name, "n_mice": d.subject.nunique(), "unit": "trials", "n_HIGH": len(hi), "n_LOW": len(lo),
                     "median_HIGH": hi.median().round(2), "median_LOW": lo.median().round(2),
                     "z": round(r.statistic, 3), "p": r.pvalue})
        rows.append({"mice": name, "n_mice": d.subject.nunique(), "unit": "mouse means", "n_HIGH": pm.HIGH.notna().sum(),
                     "n_LOW": pm.LOW.notna().sum(), "median_HIGH": pm.HIGH.median().round(2),
                     "median_LOW": pm.LOW.median().round(2), "z": round(r2.statistic, 3), "p": r2.pvalue})
    return pd.DataFrame(rows)
F2B = fig2_test("ev_0_8")
print(F2B.to_string())
d = ptp[ptp.subject.isin(GROUPS["A"]) & (ptp.base_pct_max < 50)]
print("group A, mean evoked PD 0-8 s by mouse and contrast (trials < 50%):")
print(d.groupby(["subject", "contrast"]).ev_0_8.agg(["mean", "count"]).unstack().round(1).to_string())
print("range of values:", d.ev_0_8.min().round(1), "to", d.ev_0_8.max().round(1))
print("CGC-assay CTRL trials of group A with a usable pupil:", int(ptp.subject.isin(GROUPS["A"]).sum()),
      "; below 50%:", len(d))
# variant without the 50% limit
dd = ptp[ptp.subject.isin(GROUPS["A"])]
r = stats.ranksums(dd[dd.contrast == "HIGH"].ev_0_8, dd[dd.contrast == "LOW"].ev_0_8)
print(f"variant, group A, all trials: z = {r.statistic:.3f}, p = {r.pvalue:.4f}")
mice shared by A and B: ['AA0312', 'AA0314', 'AA0315', 'AA0318', 'AA0335']
  mice  n_mice         unit  n_HIGH  n_LOW  median_HIGH  median_LOW      z         p
0    A       6       trials      42     40       109.10      105.05  1.336  0.181597
1    A       6  mouse means       6      6       114.35      108.55  0.641  0.521839
2    B       9       trials      67     73       104.41      101.95  0.836  0.402949
3    B       9  mouse means       9      9       113.86      109.56  0.221  0.825283
4  A+B      13       trials      95    102       107.23      103.05  1.931  0.053521
5  A+B      13  mouse means      13     13       114.84      109.56  1.051  0.293129
group A, mean evoked PD 0-8 s by mouse and contrast (trials < 50%):
           mean        count    
contrast   HIGH    LOW  HIGH LOW
subject                         
AA0308    112.3  110.0     7   4
AA0310    119.0  120.0     4  10
AA0314    113.9  130.9     1   1
AA0335    102.2  104.7    13  10
AA0350    125.1  100.7     8   8
AA0353    114.8  107.0     9   7
range of values: 86.8 to 185.4
CGC-assay CTRL trials of group A with a usable pupil: 209 ; below 50%: 82
variant, group A, all trials: z = 2.747, p = 0.0060

Result: not reproduced. Evoked PD over 0 to 8 s is higher in HIGH than LOW under every reading, but not significantly (group A trials, medians 109.10 against 105.05%, z = 1.336, p = 0.18; group B trials p = 0.40; A and B pooled p = 0.054; per-mouse means p = 0.29 to 0.83). Only 82 of 209 group A trials have a baseline below 50% of animal max, from six mice. Without the 50% limit group A gives z = 2.747, p = 0.0060 (a variant). Without AA0335, group A trials give p = 0.028, while B and the pooled trials stay above 0.05 (variants at the end), so the readings would disagree and the criterion would give methods_underspecified: the outcome rests on keeping AA0335 in group A, as the files' label does (an assumption). With the narrower step rule the trial readings give p = 0.088 to 0.54.

In [17]:
F2C = fig2_test("ev_1_2")
print(F2C.to_string())
dd = ptp[ptp.subject.isin(GROUPS["A"])]
r = stats.ranksums(dd[dd.contrast == "HIGH"].ev_1_2, dd[dd.contrast == "LOW"].ev_1_2)
print(f"variant, group A, all trials: z = {r.statistic:.3f}, p = {r.pvalue:.4f}")
  mice  n_mice         unit  n_HIGH  n_LOW  median_HIGH  median_LOW      z         p
0    A       6       trials      42     40       110.37      108.10  1.651  0.098684
1    A       6  mouse means       6      6       115.22      110.29  0.641  0.521839
2    B       9       trials      67     73       107.48      103.49  1.420  0.155502
3    B       9  mouse means       9      9       113.74      107.72  0.574  0.565992
4  A+B      13       trials      95    102       109.10      104.47  2.558  0.010515
5  A+B      13  mouse means      13     13       113.74      109.69  1.205  0.228154
variant, group A, all trials: z = 1.848, p = 0.0646

Result: blocked (methods_underspecified). The readings disagree: with group A and B mice pooled, trials as units, HIGH exceeds LOW (medians 109.10 against 104.47%, z = 2.558, p = 0.011), while group A alone (p = 0.099), group B alone (p = 0.16) and every per-mouse reading (p = 0.23 to 0.57) are not significant. The criterion asks for agreement and blocks the claim otherwise. Without the 50% limit, group A gives p = 0.065. The readings also disagree without AA0335 (group A trials p = 0.008), under the round-1 cleaning (pooled p = 0.0098), the single pass (pooled p = 0.037) and the narrower step rule (pooled p = 0.010; variants at the end).

DRC responses of cells before and after ZX1 (Fig. 2d, e; group B)¶

Per cell and contrast, the mean over 0 to 2 s of the trial-averaged dF/F; tone-responsive cells under each inclusion reading, determined within each condition (the files segment cells separately before and after ZX1 in most mice). Two-sided Wilcoxon rank sum, low against high, in CTRL and in ZX1.

In [18]:
ptB = trials[(trials.kind == "pt") & trials.subject.isin(GROUPS["B"]) & trials.treat.isin(["CTRL", "ZX1"])]
ctB = zp.cell_trial_table(ptB)
print("group B mice:", GROUPS["B"], "; genotypes:", summary.loc[GROUPS["B"], "genotype"].value_counts().to_dict())
print("planes by condition:", ctB.groupby("treat").plane.unique().map(list).to_dict())
rows = []
for sd in ("time", "trials"):
    for both in (True, False):
        for mice_name, mice in (("B", GROUPS["B"]), ("B without ZnT3-KO", [m for m in GROUPS["B"] if summary.loc[m, "genotype"] != "ZnT3KO"]),
                                ("B C57BL6/J only", [m for m in GROUPS["B"] if summary.loc[m, "genotype"] == "C57BL6/J"])):
            for cond in ("CTRL", "ZX1"):
                d = ctB[(ctB.treat == cond) & ctB.subject.isin(mice)]
                cells = zp.responsive(d, (2.0, 2.8), sd=sd, by_contrast=both)
                v = d[d.cell.isin(cells)].groupby(["cell", "contrast"]).drc_0_2.mean().unstack()
                r = stats.ranksums(v.LOW.dropna(), v.HIGH.dropna())
                rows.append({"SD": sd, "contrasts": "both" if both else "pooled", "mice": mice_name, "condition": cond,
                             "cells": len(cells), "median_LOW": v.LOW.median().round(3), "median_HIGH": v.HIGH.median().round(3),
                             "median_diff_LOW-HIGH": (v.LOW - v.HIGH).median().round(3), "z": round(r.statistic, 4), "p": r.pvalue})
F2E = pd.DataFrame(rows)
print(F2E.to_string())
print("paper: 520 cells from 14 mice; CTRL z = 0.0073, p = 0.9942; ZX1 z = -1.2425, p = 0.2141")
group B mice: ['AA0312', 'AA0314', 'AA0315', 'AA0317', 'AA0318', 'AA0319', 'AA0325', 'AA0326', 'AA0334', 'AA0335', 'AA0336', 'AA0340'] ; genotypes: {'C57BL6/J': 6, 'ZnT3WT': 4, 'ZnT3KO': 2}
planes by condition: {'CTRL': ['PlaneSegmentation_all', 'PlaneSegmentation_preZX1'], 'ZX1': ['PlaneSegmentation_all', 'PlaneSegmentation_postZX1']}
        SD contrasts               mice condition  cells  median_LOW  median_HIGH  median_diff_LOW-HIGH       z             p
0     time      both                  B      CTRL    359      -0.798        0.397                -1.270 -6.8749  6.202634e-12
1     time      both                  B       ZX1    363      -0.906        0.255                -1.230 -6.9276  4.279204e-12
2     time      both  B without ZnT3-KO      CTRL    303      -0.791        0.511                -1.310 -6.8170  9.299241e-12
3     time      both  B without ZnT3-KO       ZX1    311      -0.769        0.616                -1.506 -7.5701  3.729342e-14
4     time      both    B C57BL6/J only      CTRL    216      -0.922        0.094                -1.046 -5.2370  1.632097e-07
5     time      both    B C57BL6/J only       ZX1    222      -0.878        0.638                -1.818 -6.5160  7.218404e-11
6     time    pooled                  B      CTRL    375      -0.770        0.487                -1.279 -6.5885  4.443094e-11
7     time    pooled                  B       ZX1    375      -0.915        0.243                -1.187 -6.8315  8.401224e-12
8     time    pooled  B without ZnT3-KO      CTRL    319      -0.766        0.551                -1.332 -6.4852  8.859302e-11
9     time    pooled  B without ZnT3-KO       ZX1    319      -0.769        0.612                -1.506 -7.5223  5.383940e-14
10    time    pooled    B C57BL6/J only      CTRL    228      -0.794        0.270                -1.055 -4.9430  7.691062e-07
11    time    pooled    B C57BL6/J only       ZX1    227      -0.861        0.654                -1.779 -6.3704  1.885015e-10
12  trials      both                  B      CTRL    250      -0.752        0.545                -1.280 -6.0463  1.481684e-09
13  trials      both                  B       ZX1    225      -0.717        0.645                -1.324 -6.0937  1.103079e-09
14  trials      both  B without ZnT3-KO      CTRL    209      -0.717        0.654                -1.296 -5.8652  4.484834e-09
15  trials      both  B without ZnT3-KO       ZX1    211      -0.637        0.704                -1.492 -6.1070  1.015223e-09
16  trials      both    B C57BL6/J only      CTRL    161      -0.873        0.228                -1.275 -5.0863  3.651809e-07
17  trials      both    B C57BL6/J only       ZX1    149      -0.791        0.936                -2.028 -5.7418  9.367962e-09
18  trials    pooled                  B      CTRL    288      -0.762        0.485                -1.273 -6.1831  6.285159e-10
19  trials    pooled                  B       ZX1    255      -0.769        0.558                -1.322 -6.4173  1.387406e-10
20  trials    pooled  B without ZnT3-KO      CTRL    242      -0.732        0.535                -1.303 -6.0345  1.594799e-09
21  trials    pooled  B without ZnT3-KO       ZX1    237      -0.717        0.622                -1.499 -6.5311  6.528047e-11
22  trials    pooled    B C57BL6/J only      CTRL    187      -0.798        0.228                -1.105 -5.0007  5.713406e-07
23  trials    pooled    B C57BL6/J only       ZX1    168      -0.793        0.858                -2.007 -6.1384  8.334659e-10
paper: 520 cells from 14 mice; CTRL z = 0.0073, p = 0.9942; ZX1 z = -1.2425, p = 0.2141

Result: not reproduced. DRC responses over 0 to 2 s differ between contrasts under every reading, in CTRL and after ZX1: LOW is below HIGH (median cell difference -1.05 to -2.03% dF/F; Wilcoxon rank sum z = -4.94 to -7.57, p = 3.7e-14 to 7.7e-07). Under the main inclusion reading 359 cells in CTRL and 363 after ZX1 from 12 mice, against the paper's 520 from 14; the counts are outside the tolerance under every reading (149 to 375). With the six C57BL6/J mice of group B only, the result is the same (p <= 7.7e-07).

Figure 3: LME of pure-tone responses on baseline and evoked PD (group A)¶

Rows are cell by trial (CTRL CGC-assay trials of group A), with the trial's peak pure-tone response (2-2.8 s window; 2-3.2 s as a variant), its baseline PD (% animal max), contrast, and the trial's mean evoked PD over 1 to 2 s (% baseline). The Methods' random intercepts for baseline_PD and pupil_at_1-2s group rows by their values, which are values of the trial, so each is a random intercept per trial; the two give the same grouping and are fitted as one trial intercept nested in subject. Fitted by maximum likelihood with statsmodels MixedLM; the fixed effects are tested with Wald z tests (statsmodels has no Satterthwaite F; the paper's denominator df are about 165, where t and z p-values differ little).

In [19]:
import statsmodels.regression.mixed_linear_model as mlm
def fit_fig3(d, formula):
    """ML fit; tries several optimizers and keeps the best likelihood (the fits are fragile)."""
    m = smf.mixedlm(formula, d, groups=d["subject"], re_formula="1", vc_formula={"trial": "0 + C(trial)"})
    best = None
    for method in ("lbfgs", "bfgs", "nm", "powell"):
        try:
            r = m.fit(reml=False, method=method, maxiter=2000)
        except Exception:
            continue
        if np.isfinite(r.llf) and (best is None or r.llf > best.llf):
            best = r
    return best

ct3 = ctb.copy()
# predictors centred (baseline at 50%, evoked PD at 100%) to help the optimizer; slopes are unchanged
ct3["pupil12"] = ct3.trial.map(tr.set_index("trial_id").ev_1_2) - 100
ct3["base"] = ct3["base"] - 50
ct3["HIGH"] = (ct3.contrast == "HIGH").astype(float)
rows, FITS3 = [], {}
for cells_name, cells in (("both contrasts, SD time", INCL[("time", "both")]), ("all tone-responsive, SD time", INCL[("time", "pooled")]),
                          ("both contrasts, SD trials", INCL[("trials", "both")]), ("all tone-responsive, SD trials", INCL[("trials", "pooled")])):
    for trials_name in ("all", "<50%"):
        for wn, w in WINDOWS.items():
            d = ct3[ct3.cell.isin(cells)]
            if trials_name == "<50%":
                d = d[d.base < 0]  # base is centred at 50%
            d = d.rename(columns={f"peak_{w[0]}_{w[1]}": "peak"})[["peak", "base", "HIGH", "pupil12", "subject", "trial"]].dropna()
            full = fit_fig3(d, "peak ~ base + HIGH * pupil12")
            null = fit_fig3(d, "peak ~ base")
            FITS3[(cells_name, trials_name, wn)] = (full, null, d)
            lr = 2 * (full.llf - null.llf)
            rows.append({"cells": cells_name, "trials": trials_name, "window": wn, "rows": len(d),
                         "n_cells": d.shape[0] and ctb[ctb.cell.isin(cells)].cell.nunique(), "n_trials": d.trial.nunique(),
                         "b_base": full.params["base"], "p_base": full.pvalues["base"],
                         "b_pupil12": full.params["pupil12"], "p_pupil12": full.pvalues["pupil12"],
                         "b_HIGHxpupil12": full.params["HIGH:pupil12"], "p_HIGHxpupil12": full.pvalues["HIGH:pupil12"],
                         "b_HIGH": full.params["HIGH"], "p_HIGH": full.pvalues["HIGH"],
                         "var_subject": full.cov_re.iloc[0, 0], "var_trial": full.vcomp[0], "var_resid": full.scale,
                         "LR": lr, "LR_df": 3, "p_LRT": stats.chi2.sf(lr, 3), "converged": full.converged and null.converged})
F3 = pd.DataFrame(rows)
print(F3.to_string())
print("paper: baseline PD p = 3.64e-3; evoked PD p = 0.108; interaction p = 0.756; LRT p = 0.330")
                             cells trials window  rows  n_cells  n_trials    b_base    p_base  b_pupil12  p_pupil12  b_HIGHxpupil12  p_HIGHxpupil12    b_HIGH    p_HIGH  var_subject  var_trial   var_resid         LR  LR_df     p_LRT  converged
0          both contrasts, SD time    all  2-2.8  6957      318       209 -0.103918  0.000172  -0.004791   0.922317       -0.069683        0.292190 -1.505503  0.043928    31.469525  15.263462   74.482471  14.410369      3  0.002397       True
1          both contrasts, SD time    all  2-3.2  6957      318       209 -0.106936  0.000121  -0.008717   0.859947       -0.076631        0.249364 -1.414027  0.059843    31.176941  15.428175   75.486330  14.660799      3  0.002131       True
2          both contrasts, SD time   <50%  2-2.8  2554      318        82 -0.175996  0.010274  -0.051800   0.429001       -0.036034        0.700219 -1.716158  0.245281    36.899219  16.127003  103.991442   7.677636      3  0.053166       True
3          both contrasts, SD time   <50%  2-3.2  2554      318        82 -0.181209  0.008647  -0.047737   0.469048       -0.058137        0.537142 -1.318450  0.375037    36.777906  16.358671  104.833707   7.682975      3  0.053039       True
4     all tone-responsive, SD time    all  2-2.8  7280      339       209 -0.100101  0.000284  -0.006986   0.886463       -0.066480        0.312621 -1.614850  0.030091    32.185850  15.451360   72.332967  15.464475      3  0.001460       True
5     all tone-responsive, SD time    all  2-3.2  7280      339       209 -0.103374  0.000192  -0.010870   0.825059       -0.073980        0.263590 -1.511898  0.043340    31.885653  15.602049   73.271826  15.659035      3  0.001332       True
6     all tone-responsive, SD time   <50%  2-2.8  2656      339        82 -0.172255  0.010296  -0.051705   0.424479       -0.032861        0.720502 -1.868067  0.197287    37.868222  15.985700  100.680296   8.251510      3  0.041090       True
7     all tone-responsive, SD time   <50%  2-3.2  2656      339        82 -0.178734  0.008168  -0.047928   0.462061       -0.055737        0.546562 -1.447680  0.320735    37.799386  16.213012  101.475188   8.209312      3  0.041878       True
8        both contrasts, SD trials    all  2-2.8  4860      215       209 -0.115274  0.000902   0.017727   0.770547       -0.095562        0.248613 -1.492105  0.109494    25.613997  21.941421   90.907630  10.465445      3  0.014997       True
9        both contrasts, SD trials    all  2-3.2  4860      215       209 -0.117448  0.000727   0.014617   0.810168       -0.102282        0.217551 -1.432433  0.124861    25.115566  21.987037   91.294348  10.845341      3  0.012592       True
10       both contrasts, SD trials   <50%  2-2.8  1685      215        82 -0.191066  0.030044  -0.047190   0.534899       -0.054179        0.635742 -1.338278  0.475243    35.672707  20.388167  131.881825   5.020197      3  0.170324       True
11       both contrasts, SD trials   <50%  2-3.2  1685      215        82 -0.190681  0.030598  -0.042828   0.574192       -0.074916        0.513554 -0.992053  0.597269    34.695248  20.503874  132.184146   5.186308      3  0.158652       True
12  all tone-responsive, SD trials    all  2-2.8  5418      241       209 -0.113376  0.000604   0.010349   0.859161       -0.090050        0.254637 -1.439157  0.106746    25.430042  20.542864   85.932508  10.871685      3  0.012440       True
13  all tone-responsive, SD trials    all  2-3.2  5418      241       209 -0.115150  0.000498   0.007344   0.899858       -0.097569        0.217528 -1.342923  0.132560    24.835311  20.541839   86.717830  11.110940      3  0.011141       True
14  all tone-responsive, SD trials   <50%  2-2.8  1827      241        82 -0.187329  0.031268  -0.045849   0.544114       -0.055745        0.619703 -1.327157  0.472239    34.613284  20.550541  127.649285   5.206607      3  0.157279       True
15  all tone-responsive, SD trials   <50%  2-3.2  1827      241        82 -0.186995  0.031810  -0.041831   0.580876       -0.075696        0.501513 -0.980954  0.595904    33.709731  20.671977  127.944060   5.357544      3  0.147412       True
paper: baseline PD p = 3.64e-3; evoked PD p = 0.108; interaction p = 0.756; LRT p = 0.330

Result: reproduced. In all sixteen fits (four cell inclusion readings, two trial readings, two peak windows) the baseline PD coefficient is negative and significant (b = -0.100 to -0.191% dF/F per % of max, p = 1.2e-04 to 0.032), while evoked PD at 1-2 s (p = 0.42 to 0.92) and its interaction with contrast (p = 0.22 to 0.72) are not, as the paper reports. All fits converged; the subject and trial variances are printed. The paper does not give the sign of the baseline coefficient. Without AA0335, the baseline coefficient is not significant in the trials below 50% (p = 0.087, one fit, variants at the end), which would make the outcome partially reproduced: the outcome rests on keeping AA0335 in group A, as the files' label does (an assumption).

In [20]:
print(F3[["cells", "trials", "window", "rows", "LR", "LR_df", "p_LRT", "b_HIGH", "p_HIGH"]].to_string())
print("paper: likelihood ratio test p = 0.330")
                             cells trials window  rows         LR  LR_df     p_LRT    b_HIGH    p_HIGH
0          both contrasts, SD time    all  2-2.8  6957  14.410369      3  0.002397 -1.505503  0.043928
1          both contrasts, SD time    all  2-3.2  6957  14.660799      3  0.002131 -1.414027  0.059843
2          both contrasts, SD time   <50%  2-2.8  2554   7.677636      3  0.053166 -1.716158  0.245281
3          both contrasts, SD time   <50%  2-3.2  2554   7.682975      3  0.053039 -1.318450  0.375037
4     all tone-responsive, SD time    all  2-2.8  7280  15.464475      3  0.001460 -1.614850  0.030091
5     all tone-responsive, SD time    all  2-3.2  7280  15.659035      3  0.001332 -1.511898  0.043340
6     all tone-responsive, SD time   <50%  2-2.8  2656   8.251510      3  0.041090 -1.868067  0.197287
7     all tone-responsive, SD time   <50%  2-3.2  2656   8.209312      3  0.041878 -1.447680  0.320735
8        both contrasts, SD trials    all  2-2.8  4860  10.465445      3  0.014997 -1.492105  0.109494
9        both contrasts, SD trials    all  2-3.2  4860  10.845341      3  0.012592 -1.432433  0.124861
10       both contrasts, SD trials   <50%  2-2.8  1685   5.020197      3  0.170324 -1.338278  0.475243
11       both contrasts, SD trials   <50%  2-3.2  1685   5.186308      3  0.158652 -0.992053  0.597269
12  all tone-responsive, SD trials    all  2-2.8  5418  10.871685      3  0.012440 -1.439157  0.106746
13  all tone-responsive, SD trials    all  2-3.2  5418  11.110940      3  0.011141 -1.342923  0.132560
14  all tone-responsive, SD trials   <50%  2-2.8  1827   5.206607      3  0.157279 -1.327157  0.472239
15  all tone-responsive, SD trials   <50%  2-3.2  1827   5.357544      3  0.147412 -0.980954  0.595904
paper: likelihood ratio test p = 0.330

Result: not reproduced. With all trials, the likelihood ratio test of the full model against the null model is significant in all eight fits (chi-squared on 3 df, p = 0.0013 to 0.015), against the paper's p = 0.330; with the trials below 50% it gives p = 0.041 to 0.17. The criterion asks for p >= 0.05 under each trial reading. The full model also carries the contrast main effect, which is significant in some all-trial fits (b = -1.41 to -1.61, p = 0.030 to 0.060 with SD over time) and accounts for part of the difference.

Figure 4: growth curve analysis of evoked PD in ZnT3-WT and ZnT3-KO mice¶

DRC trials without the tone (contrastChange), CTRL and ZX1, baseline PD < 50% of animal max; pupil (% baseline) at the 21 samples from 0 to 2 s; orthogonal time polynomials with unit-norm columns over those samples (R poly()). LME with a random intercept per mouse, fitted by REML (statsmodels MixedLM; lmer's default) with several optimizers, keeping the converged fit of highest likelihood (zp.fit_lme; lbfgs alone stopped at a degenerate point with an infinite likelihood and a zero intercept in some fits). The optimizer, convergence, subject variance and whether it is on the boundary (0) are printed for each fit. Readings: model (a) the written formula plus contrast:treatment, (b) the full factorial; coding (a) reference (LOW, CTRL), (b) sum coding (±1). Terms tested with Wald z (the paper's Satterthwaite F have about 4500 to 7900 denominator df, where z and t agree).

In [21]:
drc = tr[(tr.kind == "drc")].copy()
drc["is_high"] = (drc.contrast == "HIGH").astype(float)
FORMS = {"written+cxt": "pupil ~ (tPoly1 + tPoly2) * c + (tPoly1 + tPoly2) * x + c:x",
         "full factorial": "pupil ~ (tPoly1 + tPoly2) * c * x"}
def code(long, factor_col, level, coding):
    v = (long[factor_col] == level).astype(float)
    return v if coding == "reference" else 2 * v - 1

def gca(trs, factor="treat", level="ZX1", forms=FORMS, codings=("reference", "sum")):
    long = zp.gca_long(trs)
    long["c"] = 0.0
    out, fits = [], {}
    for coding in codings:
        long["c"] = code(long, "contrast", "HIGH", coding)
        long["x"] = code(long, factor, level, coding)
        for fname, f in forms.items():
            m, diag = zp.fit_lme(f, long, "subject", reml=True)
            fits[(fname, coding)] = (m, long.copy())
            row = {"model": fname, "coding": coding, "rows": len(long), "trials": long.trial.nunique(),
                   "mice": long.subject.nunique(), **diag, "intercept": m.params["Intercept"]}
            for term, lab in (("c", "contrast_int"), ("tPoly1:c", "contrast_slope"), ("x", "x_int"),
                              ("tPoly1:x", "x_slope"), ("c:x", "c_x")):
                if term in m.params:
                    row[f"{lab}_b"] = m.params[term]; row[f"{lab}_z"] = m.tvalues[term]; row[f"{lab}_p"] = m.pvalues[term]
            out.append(row)
    return pd.DataFrame(out), fits, long

GC, GD = GROUPS["C"], GROUPS["D"]  # not C: patsy formulas use C()
wt = drc[drc.subject.isin(GC) & drc.treat.isin(["CTRL", "ZX1"]) & (drc.base_pct_max < 50)]
print("ZnT3-WT DRC trials with a usable pupil:", int((drc.subject.isin(GC)).sum()), "; below 50%:", len(wt))
print(pd.crosstab([wt.subject], [wt.treat, wt.contrast]).to_string())
F4C, FITS_WT, long_wt = gca(wt)
pd.set_option("display.float_format", lambda x: f"{x:.4g}")
print(F4C.to_string())
print("paper (WT): contrast intercept F = 19.48 p = 1.03e-5; contrast slope F = 26.54 p = 2.64e-7;"
      " ZX1 intercept F = 4.47 p = 0.0344; ZX1 slope F = 40.45 p = 2.13e-10; contrast x ZX1 F = 24.2 p = 8.85e-7; df about 7920")
terms = ["contrast_int_p", "contrast_slope_p", "x_int_p", "x_slope_p", "c_x_p"]
print("terms with p < 0.05 per reading:", (F4C[terms] < 0.05).sum(1).tolist())
ZnT3-WT DRC trials with a usable pupil: 473 ; below 50%: 328
treat    CTRL      ZX1    
contrast HIGH LOW HIGH LOW
subject                   
AA0323     12  14    0   2
AA0325     15  15    8  13
AA0330      6   8   17  16
AA0331      3   5    0   0
AA0332      2   8    0   0
AA0333      9  10    0   0
AA0334      5   6   11  11
AA0335     12  12    9   4
AA0336     11  13    7   7
AA0337     12  14   15  16
            model     coding  rows  trials  mice optimizer  converged  group_var  boundary  warnings  intercept  contrast_int_b  contrast_int_z  contrast_int_p  contrast_slope_b  contrast_slope_z  contrast_slope_p  x_int_b  x_int_z  x_int_p  x_slope_b  x_slope_z  x_slope_p  c_x_b  c_x_z     c_x_p
0     written+cxt  reference  6888     328    10    powell       True      28.09     False         0      107.7           2.479           5.809         6.3e-09             2.913             1.966           0.04933    1.248    2.573  0.01009     -8.243     -5.492  3.982e-08 -2.756 -4.176 2.967e-05
1  full factorial  reference  6888     328    10        nm       True      28.09     False         0      107.7           2.479           5.811       6.223e-09             5.785             2.983          0.002855    1.248    2.574  0.01006     -4.961     -2.393    0.01672 -2.756 -4.177 2.947e-05
2     written+cxt        sum  6888     328    10    powell       True      28.09     False         0      108.9          0.5507           3.337       0.0008463             1.456             1.966           0.04933 -0.06522  -0.3542   0.7232     -4.122     -5.492  3.982e-08 -0.689 -4.176 2.967e-05
3  full factorial        sum  6888     328    10        nm       True      28.09     False         0      108.9          0.5507           3.338       0.0008427             1.169             1.557            0.1195 -0.06522  -0.3543   0.7231     -4.204     -5.597  2.185e-08 -0.689 -4.177 2.947e-05
paper (WT): contrast intercept F = 19.48 p = 1.03e-5; contrast slope F = 26.54 p = 2.64e-7; ZX1 intercept F = 4.47 p = 0.0344; ZX1 slope F = 40.45 p = 2.13e-10; contrast x ZX1 F = 24.2 p = 8.85e-7; df about 7920
terms with p < 0.05 per reading: [5, 5, 4, 3]
In [22]:
# mean traces (0-2 s) by condition, and per-mouse mean evoked PD over 0-2 s
mt = long_wt.groupby(["treat", "contrast", "time"]).pupil.mean().unstack(["treat", "contrast"])
print(mt.iloc[::4].round(2).to_string())
print(wt.groupby(["subject", "treat", "contrast"]).ev_0_2.mean().unstack(["treat", "contrast"]).round(1).to_string())
fig, ax = plt.subplots(figsize=(4, 3))
for c in mt.columns:
    ax.plot(mt.index, mt[c], label=" ".join(c))
ax.legend(); ax.set(xlabel="time (s)", ylabel="pupil (% baseline)", title="ZnT3-WT"); plt.tight_layout(); plt.show()
print("plotted range", np.nanmin(mt.values).round(1), "to", np.nanmax(mt.values).round(1))
treat     CTRL         ZX1      
contrast  HIGH   LOW  HIGH   LOW
time                            
0        100.5 100.3 101.6 102.8
0.4      104.8 103.6   106   106
0.8      110.5 108.8 110.2 109.5
1.2      112.5   110 109.8 109.8
1.6      113.1 109.2 108.2 108.8
2        113.2 108.5 106.9 109.1
treat     CTRL         ZX1      
contrast  HIGH   LOW   LOW  HIGH
subject                         
AA0323   110.9 108.5 111.5   NaN
AA0325   102.2 103.8 106.5   103
AA0330   114.8 105.9 108.1 108.6
AA0331   114.1 119.8   NaN   NaN
AA0332   108.1 101.8   NaN   NaN
AA0333   108.1 109.4   NaN   NaN
AA0334   116.7 114.1 106.4 109.7
AA0335   102.5 102.2  99.2 105.5
AA0336   122.8 110.4 122.6 112.6
AA0337   104.9 104.4 105.2 106.5
No description has been provided for this image
plotted range 100.3 to 113.2

Result: partially reproduced. 328 ZnT3-WT trials below 50% (6888 rows, against the paper's denominator df of about 7920). Under reference coding all five terms are significant in both models: contrast intercept (b = 2.48, z = 5.81, p = 6.3e-09), contrast slope (p = 0.049 written model, 0.0029 full factorial), ZX1 intercept (b = 1.25, p = 0.010), ZX1 slope (b = -8.24 and -4.96, p = 4.0e-08 and 0.017) and contrast by ZX1 (b = -2.76, z = -4.18, p = 3.0e-05). Under sum coding the ZX1 intercept is not significant (p = 0.72) and, in the full factorial, nor is the contrast slope (p = 0.12), so four and three terms pass. Every reading meets the partial condition (the interaction and at least two main terms; 4 of 4 in the variants table), and two also meet the full one. The readings thus agree on partially reproduced and differ only on whether the full condition also holds, so the criterion's partial clause, read as applying under every reading as its full clause does, gives partially reproduced. Reference coding is the default of both fitlme and lmer. The mean traces show the expected order in CTRL (HIGH 113.2 against LOW 108.5% at 2 s) and a reversed one after ZX1 (106.9 against 109.1). All fits converged with a subject variance away from 0.

The outcome rests on the cleaning (an assumption): the partial condition holds under all four readings with the main cleaning, with the narrower step rule (three or four terms, interaction p <= 0.00093) and with the round-1 cleaning without AA0319 and AA0334, and under none with the round-1 cleaning (interaction p = 0.25) or the single pass (p = 0.56; variants at the end). This revision had kept the outcome blocked and proposed partially reproduced; the third verification round agreed, and the outcome was changed.

In [23]:
def emmeans_tukey(m, long, coding):
    """Cell means at tPoly1 = tPoly2 = 0 for the 4 contrast x treatment cells, Tukey-adjusted pairs."""
    names = m.fe_params.index
    cov = m.cov_params().loc[names, names].values
    lv = {"reference": (0.0, 1.0), "sum": (-1.0, 1.0)}[coding]
    cells = {}
    for cn, cv in (("LOW", lv[0]), ("HIGH", lv[1])):
        for xn, xv in (("CTRL", lv[0]), ("X", lv[1])):
            L = np.zeros(len(names))
            for i, n in enumerate(names):
                if n == "Intercept": L[i] = 1
                elif n == "c": L[i] = cv
                elif n == "x": L[i] = xv
                elif n == "c:x": L[i] = cv * xv
            cells[(cn, xn)] = L
    df_ = len(long) - len(names)
    rows = []
    keys = list(cells)
    for i in range(4):
        for j in range(i + 1, 4):
            L = cells[keys[i]] - cells[keys[j]]
            est = L @ m.fe_params.values
            se = np.sqrt(L @ cov @ L)
            tval = est / se
            p = stats.studentized_range.sf(abs(tval) * np.sqrt(2), 4, df_)
            rows.append({"pair": f"{keys[i][0]} {keys[i][1]} - {keys[j][0]} {keys[j][1]}", "estimate": est, "z": tval, "p_tukey": p})
    return pd.DataFrame(rows), {k: v @ m.fe_params.values for k, v in cells.items()}

def posthoc_summary(fits):
    rows = []
    for key, (m, long) in fits.items():
        ph, means = emmeans_tukey(m, long, key[1])
        p = ph.set_index("pair").p_tukey; e = ph.set_index("pair").estimate
        rows.append({"model": key[0], "coding": key[1],
                     "HIGH-LOW CTRL": e["LOW CTRL - HIGH CTRL"] * -1, "p": p["LOW CTRL - HIGH CTRL"],
                     "HIGH-LOW X": e["LOW X - HIGH X"] * -1, "p ": p["LOW X - HIGH X"],
                     "X-CTRL HIGH": e["HIGH CTRL - HIGH X"] * -1, "p  ": p["HIGH CTRL - HIGH X"],
                     "X-CTRL LOW": e["LOW CTRL - LOW X"] * -1, "p   ": p["LOW CTRL - LOW X"],
                     **{f"mean {k[0]} {k[1]}": v for k, v in means.items()}})
    return pd.DataFrame(rows)
PH_WT = posthoc_summary(FITS_WT)
print(PH_WT.to_string())
ok = ((PH_WT["HIGH-LOW CTRL"] > 0) & (PH_WT["p"] < 0.05) & ~(PH_WT["p "] < 0.05) & (PH_WT["X-CTRL HIGH"] < 0)
      & (PH_WT["p  "] < 0.05) & ~(PH_WT["p   "] < 0.05))
print("criterion met per reading:", ok.tolist())
print(emmeans_tukey(*FITS_WT[("written+cxt", "reference")], "reference")[0].to_string())
            model     coding  HIGH-LOW CTRL         p  HIGH-LOW X     p   X-CTRL HIGH     p    X-CTRL LOW    p     mean LOW CTRL  mean LOW X  mean HIGH CTRL  mean HIGH X
0     written+cxt  reference          2.479 3.944e-08     -0.2766 0.9467       -1.508  0.0147       1.248 0.04959          107.7         109           110.2        108.7
1  full factorial  reference          2.479 3.895e-08     -0.2766 0.9466       -1.508 0.01465       1.248 0.04947          107.7         109           110.2        108.7
2     written+cxt        sum          2.479 3.944e-08     -0.2766 0.9467       -1.508  0.0147       1.248 0.04959          107.7         109           110.2        108.7
3  full factorial        sum          2.479 3.895e-08     -0.2766 0.9466       -1.508 0.01465       1.248 0.04947          107.7         109           110.2        108.7
criterion met per reading: [False, False, False, False]
                   pair  estimate      z   p_tukey
0      LOW CTRL - LOW X    -1.248 -2.573   0.04959
1  LOW CTRL - HIGH CTRL    -2.479 -5.809 3.944e-08
2     LOW CTRL - HIGH X   -0.9709 -1.973    0.1981
3     LOW X - HIGH CTRL    -1.232 -2.478   0.06343
4        LOW X - HIGH X    0.2766 0.5495    0.9467
5    HIGH CTRL - HIGH X     1.508  2.994    0.0147

Result: not reproduced. At the cell means, HIGH exceeds LOW in CTRL by 2.48% (Tukey p = 3.9e-08) and not after ZX1 (-0.28, p = 0.95), and ZX1 lowers HIGH (-1.51, p = 0.015), as the paper reports, but ZX1 also raises LOW (1.25, p = 0.0496), which the criterion requires not to be significant, and the ZX1 effect on HIGH is weaker than the paper's p < 0.0001. Three of the four parts hold; the fourth fails at the threshold, and the criterion has no partial level, so it is not met. The same numbers come out under all four model and coding readings.

The result also turns with the cleaning (variants table, written model with reference coding): with the round-1 cleaning HIGH minus LOW in CTRL is not significant (p = 0.078) and ZX1 changes neither contrast (p = 0.83 and 0.89); with the round-1 cleaning without AA0319 and AA0334 ZX1 changes LOW (p = 0.00011) and not HIGH (p = 0.31), the reverse of the paper; with the single pass HIGH and LOW differ after ZX1 too (p = 0.0045). Only with the narrower step rule are all four parts met (p = 1.7e-05, 0.98, 0.00036 and 0.99). The outcome therefore rests on the main cleaning (an assumption) and on a p-value at the threshold. This revision had kept the outcome partially reproduced and proposed not reproduced; the third verification round agreed, and the outcome was changed.

In [24]:
ko = drc[drc.subject.isin(GD) & drc.treat.isin(["CTRL", "ZX1"]) & (drc.base_pct_max < 50)]
print("ZnT3-KO DRC trials with a usable pupil:", int((drc.subject.isin(GD)).sum()), "; below 50%:", len(ko))
print(pd.crosstab([ko.subject], [ko.treat, ko.contrast]).to_string())
F4F, FITS_KO, long_ko = gca(ko)
print(F4F.to_string())
print("paper (KO): contrast intercept p = 0.255; ZX1 intercept p = 0.147; contrast x ZX1 p = 0.589;"
      " contrast slope p = 0.190; ZX1 slope p = 0.0129 (weight -0.64); df about 4500")
absent = ["contrast_int_p", "x_int_p", "c_x_p", "contrast_slope_p"]
print("absence terms all p >= 0.05 per reading:", (F4F[absent] >= 0.05).all(1).tolist())
mt = long_ko.groupby(["treat", "contrast", "time"]).pupil.mean().unstack(["treat", "contrast"])
print(mt.iloc[::4].round(2).to_string())
ZnT3-KO DRC trials with a usable pupil: 315 ; below 50%: 176
treat    CTRL      ZX1    
contrast HIGH LOW HIGH LOW
subject                   
AA0326     15  14    9   6
AA0327      7   8   12   9
AA0328     11  13    7   8
AA0339      1   1    2   1
AA0340      9  11    8  13
AA0341      4   2    3   2
            model     coding  rows  trials  mice optimizer  converged  group_var  boundary  warnings  intercept  contrast_int_b  contrast_int_z  contrast_int_p  contrast_slope_b  contrast_slope_z  contrast_slope_p  x_int_b  x_int_z  x_int_p  x_slope_b  x_slope_z  x_slope_p   c_x_b   c_x_z  c_x_p
0     written+cxt  reference  3696     176     6    powell       True      14.76     False         0      107.6         -0.1688         -0.3276          0.7432             4.511             2.595          0.009452   0.6135    1.125   0.2606     -1.699    -0.9733     0.3304 -0.4277 -0.5596 0.5757
1  full factorial  reference  3696     176     6    powell       True      14.77     False         0      107.6         -0.1688         -0.3276          0.7432              3.17             1.347            0.1781   0.6135    1.125   0.2606      -3.18     -1.286     0.1986 -0.4277 -0.5595 0.5758
2     written+cxt        sum  3696     176     6    powell       True      14.76     False         0      107.7         -0.1913         -0.9958          0.3193             2.255             2.595          0.009452   0.1998     1.03    0.303    -0.8493    -0.9733     0.3304 -0.1069 -0.5596 0.5757
3  full factorial        sum  3696     176     6    powell       True      14.77     False         0      107.7         -0.1913         -0.9956          0.3194             2.323             2.661          0.007792   0.1998     1.03   0.3031    -0.8524    -0.9766     0.3288 -0.1069 -0.5595 0.5758
paper (KO): contrast intercept p = 0.255; ZX1 intercept p = 0.147; contrast x ZX1 p = 0.589; contrast slope p = 0.190; ZX1 slope p = 0.0129 (weight -0.64); df about 4500
absence terms all p >= 0.05 per reading: [False, True, False, False]
treat     CTRL         ZX1      
contrast  HIGH   LOW  HIGH   LOW
time                            
0        100.5   102 101.6 103.4
0.4      106.7 107.2 106.6 107.9
0.8      110.8 111.2 109.8 110.5
1.2        111   111 110.8 109.8
1.6      110.3 109.6 110.2 108.7
2        109.8 108.7   110 108.6

Result: blocked (methods_underspecified). 176 ZnT3-KO trials below 50% (3696 rows, against about 4500 in the paper). The contrast intercept (p = 0.32 to 0.74), ZX1 intercept (p = 0.26 to 0.30) and contrast by ZX1 (p = 0.58) terms are not significant under any reading, but the contrast slope is significant in three of four readings (z = 2.60 to 2.66, p = 0.0078 to 0.0095) and not under the full factorial with reference coding (p = 0.18). The criterion treats a disagreement between model readings as methods_underspecified.

In [25]:
cmp = pd.DataFrame({"model": F4F.model, "coding": F4F.coding,
                    "KO ZX1 slope b": F4F.x_slope_b, "KO p": F4F.x_slope_p, "WT ZX1 slope b": F4C.x_slope_b, "WT p": F4C.x_slope_p})
cmp["KO < half WT"] = cmp["KO ZX1 slope b"].abs() < 0.5 * cmp["WT ZX1 slope b"].abs()
cmp["KO in -0.64±0.064"] = (cmp["KO ZX1 slope b"] + 0.64).abs() <= 0.064
cmp["WT in -1.41±0.141"] = (cmp["WT ZX1 slope b"] + 1.41).abs() <= 0.141
cmp["criterion met"] = (cmp["KO ZX1 slope b"] < 0) & (cmp["KO p"] < 0.05) & cmp["KO < half WT"]
print(cmp.to_string())
print("readings meeting the criterion (KO term negative with p < 0.05 and KO weight < half WT):", int(cmp["criterion met"].sum()), "of", len(cmp))
            model     coding  KO ZX1 slope b   KO p  WT ZX1 slope b      WT p  KO < half WT  KO in -0.64±0.064  WT in -1.41±0.141  criterion met
0     written+cxt  reference          -1.699 0.3304          -8.243 3.982e-08          True              False              False          False
1  full factorial  reference           -3.18 0.1986          -4.961   0.01672         False              False              False          False
2     written+cxt        sum         -0.8493 0.3304          -4.122 3.982e-08          True              False              False          False
3  full factorial        sum         -0.8524 0.3288          -4.204 2.185e-08          True              False              False          False
readings meeting the criterion (KO term negative with p < 0.05 and KO weight < half WT): 0 of 4

Result: not reproduced. The criterion is met when, under one model and coding reading, the KO ZX1 slope term is negative with p < 0.05 and the KO weight is less than half the WT weight in magnitude. It is evaluated under each of the four readings, and none meets it: the KO term is negative but not significant under any (b = -0.85 to -3.18, p = 0.20 to 0.33). The KO weight is less than half the WT weight in three readings (for example -1.70 against -8.24, written model with reference coding). Neither weight is near the expected values (-0.64 and -1.41): with unit-norm polynomials over the 21 samples the WT weight is -4.12 to -8.24, so the paper's polynomial scaling is not this one. The disagreement that blocks fig4f-ko-no-contrast-effect does not bear on this claim, since its criterion fails under every reading.

Figure 5¶

The three Figure 5 claims (fig5-contralateral-zx1-increases, fig5-ipsilateral-zx1-reduces, fig5c-no-dye-in-other-hemisphere) need the widefield imaging of right A1 in three mice with a cannula in the left auditory cortex, before and after contralateral and ipsilateral ZX1, and the red-channel images. All 30 files hold two-photon imaging and pupillometry (above); no file holds widefield imaging or cannula experiments, so these claims are blocked (data_missing).

Figure 6: baseline PD drift, ACSF control, baseline against evoked PD, and genotype¶

Baseline PD against recording time (Fig. 6a)¶

Per trial (CGC-assay and DRC trials, all treatments), baseline PD in % animal max against the time of sound onset in minutes from the experiment's first trial; ordinary least squares pooled over mice. ZX1 readings: (a) groups C and D, (b) group C, (c) groups B, C and D, and (d) the eleven mice the files label ZX1_uBasePupilPctMax_wEpoch. ACSF: group F (the files' ACSF_uBasePupilPctMax_wEpoch label names the same four mice).

In [26]:
snd_tr = tr[tr.kind.isin(["pt", "drc"])]
def drift(mice, label):
    d = snd_tr[snd_tr.subject.isin(mice)]
    r = stats.linregress(d.rec_min, d.base_pct_max)
    tcrit = stats.t.ppf(0.975, len(d) - 2)
    return {"set": label, "mice": d.subject.nunique(), "trials": len(d), "slope": r.slope,
            "ci_low": r.slope - tcrit * r.stderr, "ci_high": r.slope + tcrit * r.stderr, "p": r.pvalue,
            "minutes": f"{d.rec_min.min():.0f} to {d.rec_min.max():.0f}"}
rows = [drift(GC + GD, "ZX1 (a) C+D"), drift(GC, "ZX1 (b) C"), drift(sorted(set(GROUPS["B"]) | set(GC) | set(GD)), "ZX1 (c) B+C+D"),
        drift(GROUPS["ZX1_drift"], "ZX1 (d) labelled"), drift(GROUPS["F"], "ACSF F")]
F6A = pd.DataFrame(rows)
print(F6A.to_string())
acsf = F6A.iloc[-1]
for _, r in F6A.iloc[:-1].iterrows():
    print(f"{r['set']}: slope > 0 and p < 0.05: {r.slope > 0 and r.p < 0.05}; CI overlaps ACSF CI: "
          f"{max(r.ci_low, acsf.ci_low) <= min(r.ci_high, acsf.ci_high)}")
print("ACSF: slope > 0 and p < 0.05:", acsf.slope > 0 and acsf.p < 0.05)
print("paper: ZX1 CI (0.0798, 0.183), p = 1.26e-6; ACSF CI (0.0159, 0.279), p = 0.0282")
print("per-mouse slopes (% per min):", snd_tr.groupby("subject").apply(lambda g: stats.linregress(g.rec_min, g.base_pct_max).slope).round(3).to_dict())
                set  mice  trials  slope  ci_low  ci_high         p   minutes
0       ZX1 (a) C+D    16    1010 0.1312  0.1072   0.1553 2.054e-25  0 to 165
1         ZX1 (b) C    10     614  0.141  0.1107   0.1712 7.743e-19  0 to 165
2     ZX1 (c) B+C+D    22    1559 0.1648  0.1449   0.1848 8.175e-55  0 to 178
3  ZX1 (d) labelled    11     924 0.2294  0.2034   0.2553 1.663e-58  0 to 178
4            ACSF F     4     225 0.3509  0.3043   0.3975 4.265e-35  0 to 143
ZX1 (a) C+D: slope > 0 and p < 0.05: True; CI overlaps ACSF CI: False
ZX1 (b) C: slope > 0 and p < 0.05: True; CI overlaps ACSF CI: False
ZX1 (c) B+C+D: slope > 0 and p < 0.05: True; CI overlaps ACSF CI: False
ZX1 (d) labelled: slope > 0 and p < 0.05: True; CI overlaps ACSF CI: False
ACSF: slope > 0 and p < 0.05: True
paper: ZX1 CI (0.0798, 0.183), p = 1.26e-6; ACSF CI (0.0159, 0.279), p = 0.0282
per-mouse slopes (% per min): {'AA0304': 0.316, 'AA0308': 0.277, 'AA0310': 0.319, 'AA0312': 0.098, 'AA0314': 0.097, 'AA0315': 0.088, 'AA0317': 0.354, 'AA0318': 0.133, 'AA0319': 0.088, 'AA0320': 0.109, 'AA0322': 0.424, 'AA0323': 0.592, 'AA0325': 0.241, 'AA0326': 0.311, 'AA0327': -0.024, 'AA0328': 0.152, 'AA0330': 0.047, 'AA0331': 0.284, 'AA0332': 0.776, 'AA0333': -0.349, 'AA0334': 0.051, 'AA0335': 0.32, 'AA0336': 0.341, 'AA0337': 0.277, 'AA0339': 0.061, 'AA0340': 0.131, 'AA0341': 0.11, 'AA0350': 0.514, 'AA0351': 0.373, 'AA0353': 0.432}

Result: partially reproduced. Baseline PD rises with recording time in both experiments: under the four ZX1 readings, slopes of 0.131 to 0.229% of max per minute (95% CIs within 0.107 to 0.255, p <= 7.7e-19), and in the ACSF mice 0.351 (CI 0.304 to 0.398, p = 4.3e-35). But the ACSF interval does not overlap any ZX1 interval, which the criterion requires; the paper's ACSF interval (0.0159 to 0.279) is wider and lower, while the intervals of ZX1 readings (a) and (b) (0.107 to 0.155 and 0.111 to 0.171) lie inside the paper's ZX1 interval (0.0798 to 0.183). The drift is present in both, as the paper reports, and the claim that the two are alike does not hold. Per-mouse slopes range from -0.349 to 0.776. No cleaning variant gives an overlap under readings (a) to (c), which the criterion lists; with the round-1 cleaning without AA0319 and AA0334 the added reading (d) overlaps (0.231 to 0.285 against ACSF 0.281 to 0.371; variants at the end).

Contrast effect after ACSF (Fig. 6b)¶

Group F, DRC trials, baseline PD < 50%. Readings: (a) ACSF trials only, pupil ~ (tPoly1 + tPoly2) x contrast + (1 | subject); (b) trials before and after ACSF, the models of Fig. 4 with ACSF as treatment, and the contrast effect within ACSF from the cell means.

In [27]:
F_ = GROUPS["F"]
ac = drc[drc.subject.isin(F_) & (drc.base_pct_max < 50)]
print("group F DRC trials with a usable pupil:", int(drc.subject.isin(F_).sum()), "; below 50%:", len(ac))
print(pd.crosstab([ac.subject], [ac.treat, ac.contrast]).to_string())
ra, _, long_a = gca(ac[ac.treat == "ACSF"], forms={"post only": "pupil ~ (tPoly1 + tPoly2) * c"})
print("(a) ACSF trials only")
print(ra[["model", "coding", "rows", "trials", "mice", "contrast_int_b", "contrast_int_p", "contrast_slope_b", "contrast_slope_p", "converged", "group_var"]].to_string())
rb, fits_b, long_b = gca(ac[ac.treat.isin(["CTRL", "ACSF"])], factor="treat", level="ACSF")
print("(b) before and after ACSF")
print(rb.to_string())
phb = posthoc_summary(fits_b)
print(phb[["model", "coding", "HIGH-LOW CTRL", "p", "HIGH-LOW X", "p "]].rename(columns={"HIGH-LOW X": "HIGH-LOW ACSF", "p ": "p ACSF"}).to_string())
print("paper: contrast intercept F(1,2558.3) = 46.22 p = 1.31e-11; slope F(1,2558) = 15.076 p = 1.10e-4")
mt = long_b.groupby(["treat", "contrast", "time"]).pupil.mean().unstack(["treat", "contrast"])
print(mt.iloc[::4].round(2).to_string())
group F DRC trials with a usable pupil: 193 ; below 50%: 100
treat    ACSF     CTRL    
contrast HIGH LOW HIGH LOW
subject                   
AA0320      4   8    5  10
AA0322      2   5   12  13
AA0350      5   5   10  13
AA0351      2   2    2   2
(a) ACSF trials only
       model     coding  rows  trials  mice  contrast_int_b  contrast_int_p  contrast_slope_b  contrast_slope_p  converged  group_var
0  post only  reference   693      33     4           4.404       1.512e-05             7.372            0.1074       True      20.99
1  post only        sum   693      33     4           2.202       1.512e-05             3.686            0.1074       True      20.99
(b) before and after ACSF
            model     coding  rows  trials  mice optimizer  converged  group_var  boundary  warnings  intercept  contrast_int_b  contrast_int_z  contrast_int_p  contrast_slope_b  contrast_slope_z  contrast_slope_p  x_int_b  x_int_z  x_int_p  x_slope_b  x_slope_z  x_slope_p  c_x_b  c_x_z  c_x_p
0     written+cxt  reference  2100     100     4    powell       True      11.75     False         0      105.8           2.579           4.125       3.709e-05             3.645             1.554            0.1202   0.7592    1.078   0.2812     -0.101   -0.04103     0.9673  1.589  1.446 0.1482
1  full factorial  reference  2100     100     4        nm       True      11.75     False         0      105.8           2.579           4.125       3.714e-05              1.86            0.6521            0.5143   0.7592    1.078   0.2812     -2.342    -0.7325     0.4638  1.589  1.446 0.1483
2     written+cxt        sum  2100     100     4    powell       True      11.75     False         0      107.9           1.686           6.127       8.977e-10             1.823             1.554            0.1202   0.7767    2.772 0.005563   -0.05051   -0.04103     0.9673 0.3971  1.446 0.1482
3  full factorial        sum  2100     100     4        nm       True      11.75     False         0      107.9           1.686           6.126       9.006e-10             2.308             1.842           0.06554   0.7767    2.772 0.005567      0.207     0.1652     0.8688 0.3971  1.446 0.1483
            model     coding  HIGH-LOW CTRL         p  HIGH-LOW ACSF    p ACSF
0     written+cxt  reference          2.579 0.0002253          4.167 2.595e-05
1  full factorial  reference          2.579 0.0002257          4.167   2.6e-05
2     written+cxt        sum          2.579 0.0002253          4.167 2.595e-05
3  full factorial        sum          2.579 0.0002257          4.167   2.6e-05
paper: contrast intercept F(1,2558.3) = 46.22 p = 1.31e-11; slope F(1,2558) = 15.076 p = 1.10e-4
treat     ACSF        CTRL      
contrast  HIGH   LOW  HIGH   LOW
time                            
0        101.1 100.7 102.6 100.1
0.4      104.5 102.9 104.4 101.6
0.8      110.9 107.8 108.8 106.8
1.2      113.6 109.5 111.5 108.9
1.6      114.6 109.7 112.8   110
2        114.7 109.6 114.2 109.9

Result: partially reproduced. The contrast intercept effect holds after ACSF under every reading (ACSF trials only, b = 4.40% with HIGH above LOW, p = 1.5e-05; trials before and after, contrast term p = 3.7e-05 with reference and 9.0e-10 with sum coding, and HIGH minus LOW within ACSF 4.17 at the cell means, Tukey p = 2.6e-05). The contrast slope effect does not hold under any reading (p = 0.11 with ACSF trials only, 0.066 to 0.51 with both). Only 33 ACSF trials (693 rows) and 100 trials before and after (2100 rows, against about 2560 in the paper) are below 50%.

Baseline PD against evoked PD (Fig. 6c, and the correlation in the Methods)¶

Per trial, baseline PD (% animal max) against the mean evoked PD over 1 to 2 s (% baseline), both contrasts. The readings the claims file lists: groups A, B before ZX1 (CGC-assay trials), C, D, F (DRC trials), CTRL or all trials (in_claims_file). Two kinds of reading are added here and marked: group B with its trials after ZX1, and the mice the files label pupilBaseline_vs_evoked (DRC, CGC-assay or both kinds of trial). They are shown, but the outcome is decided on the listed readings, as the criterion says.

In [28]:
rows = []
kinds = {"A": ["pt"], "B": ["pt"], "C": ["drc"], "D": ["drc"], "F": ["drc"], "base_vs_evoked": ["drc", "pt"]}
for g, ks in kinds.items():
    for kind in ([ks] if len(ks) == 1 else [["drc"], ["pt"], ["drc", "pt"]]):
        for trt in ("CTRL", "all"):
            d = snd_tr[snd_tr.subject.isin(GROUPS[g]) & snd_tr.kind.isin(kind)]
            if trt == "CTRL":
                d = d[d.treat == "CTRL"]
            r_all = stats.pearsonr(d.base_pct_max, d.ev_1_2)
            d50 = d[d.base_pct_max < 50]
            r50 = stats.pearsonr(d50.base_pct_max, d50.ev_1_2)
            # the claims file lists A, B before ZX1, C, D and F, CTRL or all trials; B with its trials
            # after ZX1 and the files' pupilBaseline_vs_evoked mice are readings added here
            listed = g in ("A", "C", "D", "F") or (g == "B" and trt == "CTRL")
            rows.append({"group": g, "kind": "+".join(kind), "trials": trt, "in_claims_file": listed, "n_all": len(d), "r_all": r_all.statistic,
                         "p_all": r_all.pvalue, "n_below50": len(d50), "r_below50": r50.statistic, "p_below50": r50.pvalue})
F6C = pd.DataFrame(rows)
F6C["n50_matches_240"] = (F6C.n_below50 - 240).abs() <= 24
print(F6C.to_string())
listed = F6C[F6C.in_claims_file]
print("claims-file readings within 240 ± 24:", listed[listed.n50_matches_240][["group", "trials", "n_below50", "r_below50", "p_below50"]].to_dict("records"))
print("added readings within 240 ± 24:", F6C[~F6C.in_claims_file & F6C.n50_matches_240][["group", "kind", "trials", "n_below50", "r_below50", "p_below50"]].to_dict("records"))
print("paper (Fig. 6c): r(238) = -0.0928, p = 0.1537, 240 responses")
             group    kind trials  in_claims_file  n_all   r_all     p_all  n_below50  r_below50  p_below50  n50_matches_240
0                A      pt   CTRL            True    209 -0.3913 4.656e-09         82   -0.05668      0.613            False
1                A      pt    all            True    345 -0.3833 1.607e-13         99    -0.1087      0.284            False
2                B      pt   CTRL            True    235 -0.2668 3.431e-05        140    0.03266     0.7017            False
3                B      pt    all           False    474 -0.2815 4.394e-10        230   0.009611     0.8847             True
4                C     drc   CTRL            True    252 -0.2645 2.095e-05        192   -0.08695     0.2304            False
5                C     drc    all            True    473 -0.2789 6.689e-10        328   -0.07076     0.2012            False
6                D     drc   CTRL            True    142 -0.4219 1.704e-07         96    -0.1818    0.07625            False
7                D     drc    all            True    315 -0.4213 5.511e-15        176    -0.2728  0.0002497            False
8                F     drc   CTRL            True     76  -0.265   0.02069         67    -0.1142     0.3575            False
9                F     drc    all            True    193  -0.328 3.206e-06        100     -0.135     0.1806            False
10  base_vs_evoked     drc   CTRL           False    262 -0.2126  0.000531        196    0.07402     0.3025            False
11  base_vs_evoked     drc    all           False    563 -0.2768 2.329e-11        330    0.04459     0.4195            False
12  base_vs_evoked      pt   CTRL           False    175 -0.2755 0.0002247        106    0.01042     0.9156            False
13  base_vs_evoked      pt    all           False    361 -0.2765 9.288e-08        171   -0.01646     0.8308            False
14  base_vs_evoked  drc+pt   CTRL           False    437 -0.2502  1.16e-07        302    0.05266     0.3618            False
15  base_vs_evoked  drc+pt    all           False    924 -0.2815 2.696e-18        501    0.02131     0.6341            False
claims-file readings within 240 ± 24: []
added readings within 240 ± 24: [{'group': 'B', 'kind': 'pt', 'trials': 'all', 'n_below50': 230, 'r_below50': 0.009610613818702688, 'p_below50': 0.884741345760481}]
paper (Fig. 6c): r(238) = -0.0928, p = 0.1537, 240 responses

Result: blocked (methods_underspecified). No reading that the claims file lists (groups A, B before ZX1, C, D, F; CTRL or all trials) has a count of responses below 50% within 216 to 264 (they range from 67 to 328), so the criterion shows every result and blocks the claim unless all agree. They do not: group D, all trials, gives a significant correlation (r = -0.273, p = 0.00025), and the other eight do not (p = 0.076 to 0.70). One reading added here, all CGC-assay trials of group B, before and after ZX1, matches the count (230 responses) and gives r = 0.0096, p = 0.88, not significant, as the paper reports (r = -0.0928, p = 0.1537); the claims file lists group B before ZX1 only. The count, and so which reading is selected, depends on the cleaning: with the round-1 cleaning group B, all trials, has 262 responses (p = 0.072), and with the single pass group C, CTRL (250, p = 0.032) and group D, all trials (233, p = 0.00095) match, which would give not reproduced; with the narrower step rule no listed reading matches and one of nine is significant, as with the main cleaning (variants at the end). The outcome rests on the cleaning.

In [29]:
F6C["n_matches_626"] = (F6C.n_all - 626).abs() <= 62.6
F6C["n50_matches_384"] = (F6C.n_below50 - 384).abs() <= 38.4
print(F6C[["group", "kind", "trials", "in_claims_file", "n_all", "r_all", "p_all", "n_below50", "r_below50", "p_below50", "n_matches_626", "n50_matches_384"]].to_string())
print("paper (Methods): r(624) = -0.35, p = 1.20e-19 over 626 responses; r(382) = -0.055, p = 0.285 below 50%")
# Variants: evoked PD over 0-2 s and 0-8 s, for the readings whose counts match
for _, r in F6C[F6C.n_matches_626 & F6C.n50_matches_384].iterrows():
    d = snd_tr[snd_tr.subject.isin(GROUPS[r.group]) & snd_tr.kind.isin(r.kind.split("+"))]
    if r.trials == "CTRL":
        d = d[d.treat == "CTRL"]
    for col in ("ev_0_2", "ev_0_8"):
        a = stats.pearsonr(d.base_pct_max, d[col]); b = stats.pearsonr(d[d.base_pct_max < 50].base_pct_max, d[d.base_pct_max < 50][col])
        print(f"variant {r.group} {r.kind} {r.trials} {col}: all r = {a.statistic:.3f} p = {a.pvalue:.3g}; below 50% r = {b.statistic:.3f} p = {b.pvalue:.3g}")
             group    kind trials  in_claims_file  n_all   r_all     p_all  n_below50  r_below50  p_below50  n_matches_626  n50_matches_384
0                A      pt   CTRL            True    209 -0.3913 4.656e-09         82   -0.05668      0.613          False            False
1                A      pt    all            True    345 -0.3833 1.607e-13         99    -0.1087      0.284          False            False
2                B      pt   CTRL            True    235 -0.2668 3.431e-05        140    0.03266     0.7017          False            False
3                B      pt    all           False    474 -0.2815 4.394e-10        230   0.009611     0.8847          False            False
4                C     drc   CTRL            True    252 -0.2645 2.095e-05        192   -0.08695     0.2304          False            False
5                C     drc    all            True    473 -0.2789 6.689e-10        328   -0.07076     0.2012          False            False
6                D     drc   CTRL            True    142 -0.4219 1.704e-07         96    -0.1818    0.07625          False            False
7                D     drc    all            True    315 -0.4213 5.511e-15        176    -0.2728  0.0002497          False            False
8                F     drc   CTRL            True     76  -0.265   0.02069         67    -0.1142     0.3575          False            False
9                F     drc    all            True    193  -0.328 3.206e-06        100     -0.135     0.1806          False            False
10  base_vs_evoked     drc   CTRL           False    262 -0.2126  0.000531        196    0.07402     0.3025          False            False
11  base_vs_evoked     drc    all           False    563 -0.2768 2.329e-11        330    0.04459     0.4195          False            False
12  base_vs_evoked      pt   CTRL           False    175 -0.2755 0.0002247        106    0.01042     0.9156          False            False
13  base_vs_evoked      pt    all           False    361 -0.2765 9.288e-08        171   -0.01646     0.8308          False            False
14  base_vs_evoked  drc+pt   CTRL           False    437 -0.2502  1.16e-07        302    0.05266     0.3618          False            False
15  base_vs_evoked  drc+pt    all           False    924 -0.2815 2.696e-18        501    0.02131     0.6341          False            False
paper (Methods): r(624) = -0.35, p = 1.20e-19 over 626 responses; r(382) = -0.055, p = 0.285 below 50%

Result: blocked (methods_underspecified). No reading matches both counts (626 ± 62.6 and 384 ± 38.4), whether the claims file lists it or not; the closest, the files' pupilBaseline_vs_evoked mice with DRC trials before and after ZX1, has 563 responses (just under 563.4) and 330 below 50%. The readings do not agree. Over all responses r ranges from -0.213 to -0.422, inside the tolerance (-0.315 to -0.385) for groups A and F (all trials) only, and below 50% group D (all trials) is significant (p = 0.00025) while the others are not. Under no cleaning variant does a reading match both counts (variants at the end).

Genotype effect on high-contrast responses before ZX1 (Fig. 6d)¶

In [30]:
gd = drc[drc.subject.isin(GC + GD) & (drc.treat == "CTRL") & (drc.contrast == "HIGH") & (drc.base_pct_max < 50)].copy()
gd["genotype"] = gd.subject.map(summary.genotype)
r6d, fits6d, long6d = gca(gd, factor="genotype", level="ZnT3KO", forms={"genotype": "pupil ~ (tPoly1 + tPoly2) * x"})
print(r6d[["model", "coding", "rows", "trials", "mice", "x_int_b", "x_int_p", "x_slope_b", "x_slope_z", "x_slope_p", "optimizer", "converged", "group_var", "boundary"]].to_string())
print("paper: genotype on slope F(1,3869) = 22.37, p = 2.33e-6 (about 3870 rows)")
mt = long6d.groupby(["genotype", "time"]).pupil.mean().unstack("genotype")
print(mt.iloc[::4].round(2).to_string())
      model     coding  rows  trials  mice  x_int_b  x_int_p  x_slope_b  x_slope_z  x_slope_p optimizer  converged  group_var  boundary
0  genotype  reference  2814     134    16   -3.033   0.3913     -7.507     -3.469  0.0005225    powell       True      45.38     False
1  genotype        sum  2814     134    16   -1.516   0.3913     -3.753     -3.469  0.0005225    powell       True      45.38     False
paper: genotype on slope F(1,3869) = 22.37, p = 2.33e-6 (about 3870 rows)
genotype  ZnT3KO  ZnT3WT
time                    
0          100.5   100.5
0.4        106.7   104.8
0.8        110.8   110.5
1.2          111   112.5
1.6        110.3   113.1
2          109.8   113.2

Result: reproduced. 134 CTRL high-contrast trials of 16 ZnT3-WT and ZnT3-KO mice (2814 rows, against about 3870). The genotype by tPoly1 term is negative, so the KO slope is below the WT slope (b = -7.51 with reference coding, z = -3.47, p = 0.00052; the same test under sum coding). The genotype intercept term is not significant (p = 0.39). The mean KO trace rises faster at first and is below WT from 1.2 s (111.0 against 112.5 at 1.2 s, 109.8 against 113.2 at 2 s). Both fits converged with a subject variance of 45.4, away from 0. With the single cleaning pass the term is not significant (b = -3.24, p = 0.20; variants at the end).

Peak of high-contrast responses (Discussion; Fig. 4c, d)¶

In [31]:
def peak_rise(trs):
    long = zp.gca_long(trs)
    m = long.groupby("time").pupil.mean()
    return m.max() - 100, m.idxmax(), long.trial.nunique()
rows = []
for name, d in (("WT after ZX1, HIGH", wt[(wt.treat == "ZX1") & (wt.contrast == "HIGH")]),
                ("WT CTRL, HIGH", wt[(wt.treat == "CTRL") & (wt.contrast == "HIGH")]),
                ("KO CTRL, HIGH (a)", ko[(ko.treat == "CTRL") & (ko.contrast == "HIGH")]),
                ("KO CTRL+ZX1, HIGH (b)", ko[ko.contrast == "HIGH"]),
                ("WT after ZX1, LOW", wt[(wt.treat == "ZX1") & (wt.contrast == "LOW")]),
                ("WT CTRL, LOW", wt[(wt.treat == "CTRL") & (wt.contrast == "LOW")])):
    pk, tpk, n = peak_rise(d)
    rows.append({"set": name, "trials": n, "peak_rise_%": round(pk, 2), "at_s": tpk, "within_10±2.5": abs(pk - 10) <= 2.5})
print(pd.DataFrame(rows).to_string())
                     set  trials  peak_rise_%  at_s  within_10±2.5
0     WT after ZX1, HIGH      67        10.49   0.9           True
1          WT CTRL, HIGH      87        13.23     2          False
2      KO CTRL, HIGH (a)      47        11.17     1           True
3  KO CTRL+ZX1, HIGH (b)      88        10.93   1.1           True
4      WT after ZX1, LOW      69         9.76   1.3           True
5           WT CTRL, LOW     105        10.01   1.3           True

Result: reproduced. The mean high-contrast trace of ZnT3-WT mice after ZX1 peaks 10.49% above baseline (67 trials), and that of ZnT3-KO mice 11.17% in CTRL (47 trials) and 10.93% with CTRL and ZX1 pooled, all within 10 ± 2.5. The WT CTRL high-contrast peak (13.23%) is outside the interval, but the WT low-contrast peaks (9.76 and 10.01%) are inside it, so the measure separates high from low contrast only in part. The second part of the statement, that both contrasts resemble low-contrast responses, is not tested by the criterion; fig4-wt-posthoc covers it for WT and was not reproduced.

Variants: pupil cleaning and group A¶

The pupil claims rest on the cleaning assumption (Data check). Here the number each pupil claim's outcome rests on is recomputed under each cleaning: the main cleaning (trials with a step by more than a factor 2 between tracked frames dropped), the round-1 cleaning (no trial dropped for steps, so the tracking-failure runs of AA0319 and AA0334 set their maxima), the round-1 cleaning without those two mice, and the Methods' single pass (no spike filter, no trial dropped; several animals' "maximum" PD is a tracking failure). The last column keeps the main cleaning and leaves the ZnT3-WT mouse AA0335 out of group A, so that group A holds only C57BL6/J mice (nine, against the paper's eight). The last variant narrows the step rule: steps are counted on the trace after the spike filter, so trials whose only fault is a spike the filter removes are kept. Model readings: Figure 3, cells responsive in both contrasts (SD over time), 2-2.8 s; Figure 4 post hoc, written model with reference coding; Figure 6b, reading (a); Figure 6d, reference coding.

In [32]:
def key_results(trx, A_mice=None):
    """The number each pupil claim's outcome rests on, recomputed from a table of cleaned trials."""
    A_mice = GROUPS["A"] if A_mice is None else A_mice
    out = {}
    # Figure 1: main reading (SD over time, both contrasts, 2-2.8 s, maximum of the averaged trace)
    c1 = ct[ct.subject.isin(A_mice)].copy()
    c1["base"] = c1.trial.map(trx.set_index("trial_id").base_pct_max)
    c1 = c1[c1.base.notna() & c1.cell.isin(INCL[("time", "both")])]
    v = bin_values(c1, "peak_2.0_2.8", (2.0, 2.8), "avgmax", "open")
    H, p, top, _ = kw(v)
    out["fig1f KW p; top bin; cells"] = f"{p:.2g}; {zp.BIN_LABELS[top]}; {v.cell.nunique()}"
    v = reliability(c1, "pearson")
    H, p, top, _ = kw(v)
    out["fig1g KW p; top bin"] = f"{p:.2g}; {zp.BIN_LABELS[top]}"
    v = scaling(c1, (2.0, 2.8), "avgmax")
    H, p, top, _ = kw(v)
    nsig = sum((g.value.mean() > 1) and stats.wilcoxon(g.value - 1).pvalue < 0.05 for _, g in v.groupby("bin"))
    out["fig1h KW p; top bin (mean); bins above 1 (Wilcoxon)"] = f"{p:.2g}; {zp.BIN_LABELS[top]}; {nsig} of 7"
    vals, m, a = anova_1i(c1, (2.0, 2.8), "avgmax", "both")
    ph = posthoc(vals, m)
    out["fig1i values; p_bin; p_int"] = f"{len(vals)}; {a.loc['C(bin)', 'PR(>F)']:.2g}; {a.loc['C(bin):C(contrast)', 'PR(>F)']:.2g}"
    out["fig1i bins significant (Bonferroni 7; 91)"] = f"{ph.loc[ph.p_bonf7 < 0.05, 'bin'].tolist()}; {ph.loc[ph.p_bonf91 < 0.05, 'bin'].tolist()}"
    # Figure 2: Wilcoxon rank sum, trials as units
    p2 = trx[(trx.kind == "pt") & (trx.treat == "CTRL") & (trx.base_pct_max < 50)]
    for col, name in (("ev_0_8", "fig2b"), ("ev_1_2", "fig2c")):
        ps = []
        for mn, mice in (("A", A_mice), ("B", GROUPS["B"]), ("A+B", sorted(set(A_mice) | set(GROUPS["B"])))):
            d = p2[p2.subject.isin(mice)]
            ps.append(f"{mn} {stats.ranksums(d[d.contrast == 'HIGH'][col], d[d.contrast == 'LOW'][col]).pvalue:.2g}")
        out[f"{name} p, trials"] = "; ".join(ps)
    # Figure 3: cells responsive in both contrasts (SD over time), 2-2.8 s
    for trials_name in ("all", "<50%"):
        d = c1.copy()
        d["pupil12"] = d.trial.map(trx.set_index("trial_id").ev_1_2) - 100
        d["base"] = d["base"] - 50
        d["HIGH"] = (d.contrast == "HIGH").astype(float)
        if trials_name == "<50%":
            d = d[d.base < 0]
        d = d.rename(columns={"peak_2.0_2.8": "peak"})[["peak", "base", "HIGH", "pupil12", "subject", "trial"]].dropna()
        full = fit_fig3(d, "peak ~ base + HIGH * pupil12"); null = fit_fig3(d, "peak ~ base")
        out[f"fig3 {trials_name} trials, p base; evoked; interaction; LRT"] = (
            f"{full.pvalues['base']:.2g}; {full.pvalues['pupil12']:.2g}; {full.pvalues['HIGH:pupil12']:.2g}; "
            f"{stats.chi2.sf(2 * (full.llf - null.llf), 3):.2g}")
    # Figure 4
    dr = trx[trx.kind == "drc"]
    w4 = dr[dr.subject.isin(GC) & dr.treat.isin(["CTRL", "ZX1"]) & (dr.base_pct_max < 50)]
    r, fits, _ = gca(w4)
    out["fig4c terms p < 0.05 (written ref, factorial ref, written sum, factorial sum); c x ZX1 p"] = (
        f"{(r[terms] < 0.05).sum(1).tolist()}; {r.c_x_p.max():.2g}")
    main_terms = ["contrast_int_p", "contrast_slope_p", "x_int_p", "x_slope_p"]
    full_ = (r[terms] < 0.05).all(1)
    part_ = (r.c_x_p < 0.05) & ((r[main_terms] < 0.05).sum(1) >= 2)
    out["fig4c readings meeting the full criterion; the partial one (or the full)"] = (
        f"{int(full_.sum())} of 4; {int((part_ | full_).sum())} of 4")
    ph = posthoc_summary({k: fits[k] for k in [("written+cxt", "reference")]}).iloc[0]
    out["fig4 post hoc p: HIGH-LOW CTRL; HIGH-LOW ZX1; ZX1 on HIGH; ZX1 on LOW"] = (
        f"{ph['p']:.2g}; {ph['p ']:.2g}; {ph['p  ']:.2g}; {ph['p   ']:.2g}")
    k4 = dr[dr.subject.isin(GD) & dr.treat.isin(["CTRL", "ZX1"]) & (dr.base_pct_max < 50)]
    rk, _, _ = gca(k4)
    out["fig4f readings with all four absence terms p >= 0.05"] = f"{int((rk[absent] >= 0.05).all(1).sum())} of 4"
    out["fig4f KO ZX1 slope p (range); readings meeting the criterion"] = (
        f"{rk.x_slope_p.min():.2g} to {rk.x_slope_p.max():.2g}; "
        f"{int(((rk.x_slope_b < 0) & (rk.x_slope_p < 0.05) & (rk.x_slope_b.abs() < 0.5 * r.x_slope_b.abs())).sum())} of 4")
    # Figure 6
    st = trx[trx.kind.isin(["pt", "drc"])]
    def ci(mice):
        d = st[st.subject.isin(mice)]
        q = stats.linregress(d.rec_min, d.base_pct_max)
        tc = stats.t.ppf(0.975, len(d) - 2)
        return q.slope - tc * q.stderr, q.slope + tc * q.stderr, q.pvalue
    ac_ = ci(GROUPS["F"])
    zxs = {"a": ci(GC + GD), "b": ci(GC), "c": ci(sorted(set(GROUPS["B"]) | set(GC) | set(GD))),
           "d": ci(GROUPS["ZX1_drift"])}
    out["fig6a ACSF CI; ZX1 readings (a)-(d) CI, overlap with ACSF"] = f"({ac_[0]:.3f}, {ac_[1]:.3f}); " + "; ".join(
        f"({k}) ({z[0]:.3f}, {z[1]:.3f}) {max(z[0], ac_[0]) <= min(z[1], ac_[1])}" for k, z in zxs.items())
    a6 = dr[dr.subject.isin(GROUPS["F"]) & (dr.treat == "ACSF") & (dr.base_pct_max < 50)]
    ra_, _, _ = gca(a6, forms={"post only": "pupil ~ (tPoly1 + tPoly2) * c"}, codings=("reference",))
    out["fig6b (a) contrast intercept p; slope p"] = f"{ra_.contrast_int_p[0]:.2g}; {ra_.contrast_slope_p[0]:.2g}"
    rows_ = []
    for g, kinds_ in (("A", ["pt"]), ("B", ["pt"]), ("C", ["drc"]), ("D", ["drc"]), ("F", ["drc"])):
        for trt in ("CTRL", "all"):
            d = st[st.subject.isin(GROUPS[g]) & st.kind.isin(kinds_)]
            d = d[d.treat == "CTRL"] if trt == "CTRL" else d
            d50 = d[d.base_pct_max < 50]
            rows_.append({"r": f"{g} {trt}", "listed": g != "B" or trt == "CTRL", "n": len(d), "n50": len(d50),
                          "r_all": stats.pearsonr(d.base_pct_max, d.ev_1_2).statistic,
                          "p50": stats.pearsonr(d50.base_pct_max, d50.ev_1_2).pvalue})
    rr = pd.DataFrame(rows_)
    m6c = rr[(rr.n50 - 240).abs() <= 24]
    out["fig6c readings within 240 (n, p below 50%); listed readings significant"] = (
        "; ".join(f"{x.r}{'' if x.listed else ' (added)'} ({x.n50}, {x.p50:.2g})" for x in m6c.itertuples()) or "none") + (
        f"; {int((rr[rr.listed].p50 < 0.05).sum())} of {int(rr.listed.sum())}")
    mm = rr[((rr.n - 626).abs() <= 62.6) & ((rr.n50 - 384).abs() <= 38.4)]
    out["methods corr readings matching both counts (r all, p below 50%)"] = (
        "; ".join(f"{x.r} ({x.r_all:.3f}, {x.p50:.2g})" for x in mm.itertuples()) or "none")
    g6 = dr[dr.subject.isin(GC + GD) & (dr.treat == "CTRL") & (dr.contrast == "HIGH") & (dr.base_pct_max < 50)].copy()
    r6, _, _ = gca(g6, factor="genotype", level="ZnT3KO", forms={"genotype": "pupil ~ (tPoly1 + tPoly2) * x"}, codings=("reference",))
    out["fig6d genotype x tPoly1 b; p"] = f"{r6.x_slope_b[0]:.2f}; {r6.x_slope_p[0]:.2g}"
    pw = peak_rise(w4[(w4.treat == "ZX1") & (w4.contrast == "HIGH")])[0]
    pk = peak_rise(k4[(k4.treat == "CTRL") & (k4.contrast == "HIGH")])[0]
    pwc = peak_rise(w4[(w4.treat == "CTRL") & (w4.contrast == "HIGH")])[0]
    out["discussion peak rise WT ZX1 HIGH; KO CTRL HIGH; WT CTRL HIGH"] = f"{pw:.2f}; {pk:.2f}; {pwc:.2f}"
    return out

no_art = ["AA0319", "AA0334"]
VARIANTS = {
    "main": (tr, None),
    "round-1 cleaning": (prev, None),
    "single pass": (single, None),
    "round-1, without AA0319 and AA0334": (prev[~prev.subject.isin(no_art)], None),
    "main, group A without AA0335": (tr, [m for m in GROUPS["A"] if m != "AA0335"]),
    "steps counted after the spike filter": (narrow, None),
}
KEY = pd.DataFrame({name: key_results(trx, am) for name, (trx, am) in VARIANTS.items()})
with pd.option_context("display.max_colwidth", 200, "display.width", 400):
    for name in KEY.columns:
        print(f"== {name} ==")
        print(KEY[name].to_string())
        print()
print("trials below 50% of animal max: main", int((tr.base_pct_max < 50).sum()), "of", len(tr), "; round-1",
      int((prev.base_pct_max < 50).sum()), "of", len(prev), "; single pass", int((single.base_pct_max < 50).sum()), "of", len(single))
== main ==
fig1f KW p; top bin; cells                                                                                                                                                                       2e-09; 21-32; 318
fig1g KW p; top bin                                                                                                                                                                                 1.1e-09; 21-32
fig1h KW p; top bin (mean); bins above 1 (Wilcoxon)                                                                                                                                         5.5e-12; 54-65; 5 of 7
fig1i values; p_bin; p_int                                                                                                                                                                   1830; 2.7e-46; 0.0084
fig1i bins significant (Bonferroni 7; 91)                                                                                                                                                     ['54-65']; ['54-65']
fig2b p, trials                                                                                                                                                                           A 0.18; B 0.4; A+B 0.054
fig2c p, trials                                                                                                                                                                         A 0.099; B 0.16; A+B 0.011
fig3 all trials, p base; evoked; interaction; LRT                                                                                                                                      0.00017; 0.92; 0.29; 0.0024
fig3 <50% trials, p base; evoked; interaction; LRT                                                                                                                                          0.01; 0.43; 0.7; 0.053
fig4c terms p < 0.05 (written ref, factorial ref, written sum, factorial sum); c x ZX1 p                                                                                                       [5, 5, 4, 3]; 3e-05
fig4c readings meeting the full criterion; the partial one (or the full)                                                                                                                            2 of 4; 4 of 4
fig4 post hoc p: HIGH-LOW CTRL; HIGH-LOW ZX1; ZX1 on HIGH; ZX1 on LOW                                                                                                                   3.9e-08; 0.95; 0.015; 0.05
fig4f readings with all four absence terms p >= 0.05                                                                                                                                                        1 of 4
fig4f KO ZX1 slope p (range); readings meeting the criterion                                                                                                                                   0.2 to 0.33; 0 of 4
fig6a ACSF CI; ZX1 readings (a)-(d) CI, overlap with ACSF                                   (0.304, 0.398); (a) (0.107, 0.155) False; (b) (0.111, 0.171) False; (c) (0.145, 0.185) False; (d) (0.203, 0.255) False
fig6b (a) contrast intercept p; slope p                                                                                                                                                              1.5e-05; 0.11
fig6c readings within 240 (n, p below 50%); listed readings significant                                                                                                          B all (added) (230, 0.88); 1 of 9
methods corr readings matching both counts (r all, p below 50%)                                                                                                                                               none
fig6d genotype x tPoly1 b; p                                                                                                                                                                        -7.51; 0.00052
discussion peak rise WT ZX1 HIGH; KO CTRL HIGH; WT CTRL HIGH                                                                                                                                   10.49; 11.17; 13.23

== round-1 cleaning ==
fig1f KW p; top bin; cells                                                                                                                                                                     3.2e-06; 32-43; 318
fig1g KW p; top bin                                                                                                                                                                                 3.2e-08; 21-32
fig1h KW p; top bin (mean); bins above 1 (Wilcoxon)                                                                                                                                         5.5e-12; 54-65; 5 of 7
fig1i values; p_bin; p_int                                                                                                                                                                   1830; 2.7e-46; 0.0084
fig1i bins significant (Bonferroni 7; 91)                                                                                                                                                     ['54-65']; ['54-65']
fig2b p, trials                                                                                                                                                                          A 0.27; B 0.55; A+B 0.096
fig2c p, trials                                                                                                                                                                         A 0.12; B 0.16; A+B 0.0098
fig3 all trials, p base; evoked; interaction; LRT                                                                                                                                      0.00013; 0.29; 0.64; 0.0027
fig3 <50% trials, p base; evoked; interaction; LRT                                                                                                                                       0.0072; 0.15; 0.98; 0.048
fig4c terms p < 0.05 (written ref, factorial ref, written sum, factorial sum); c x ZX1 p                                                                                                        [2, 3, 1, 1]; 0.25
fig4c readings meeting the full criterion; the partial one (or the full)                                                                                                                            0 of 4; 0 of 4
fig4 post hoc p: HIGH-LOW CTRL; HIGH-LOW ZX1; ZX1 on HIGH; ZX1 on LOW                                                                                                                      0.078; 0.96; 0.83; 0.89
fig4f readings with all four absence terms p >= 0.05                                                                                                                                                        1 of 4
fig4f KO ZX1 slope p (range); readings meeting the criterion                                                                                                                                   0.2 to 0.52; 0 of 4
fig6a ACSF CI; ZX1 readings (a)-(d) CI, overlap with ACSF                                   (0.281, 0.371); (a) (0.098, 0.148) False; (b) (0.098, 0.161) False; (c) (0.113, 0.159) False; (d) (0.162, 0.225) False
fig6b (a) contrast intercept p; slope p                                                                                                                                                             3.5e-05; 0.071
fig6c readings within 240 (n, p below 50%); listed readings significant                                                                                                         B all (added) (262, 0.072); 3 of 9
methods corr readings matching both counts (r all, p below 50%)                                                                                                                                               none
fig6d genotype x tPoly1 b; p                                                                                                                                                                         -6.50; 0.0063
discussion peak rise WT ZX1 HIGH; KO CTRL HIGH; WT CTRL HIGH                                                                                                                                   10.42; 10.84; 11.94

== single pass ==
fig1f KW p; top bin; cells                                                                                                                                                                      1.4e-06; 21-32; 318
fig1g KW p; top bin                                                                                                                                                                                  9.4e-14; 21-32
fig1h KW p; top bin (mean); bins above 1 (Wilcoxon)                                                                                                                                          2.7e-06; 32-43; 6 of 7
fig1i values; p_bin; p_int                                                                                                                                                                        1786; 6e-43; 0.17
fig1i bins significant (Bonferroni 7; 91)                                                                                                                                                      ['54-65']; ['54-65']
fig2b p, trials                                                                                                                                                                           A 0.43; B 0.35; A+B 0.078
fig2c p, trials                                                                                                                                                                           A 0.16; B 0.31; A+B 0.037
fig3 all trials, p base; evoked; interaction; LRT                                                                                                                                       8.7e-05; 0.15; 0.56; 0.0019
fig3 <50% trials, p base; evoked; interaction; LRT                                                                                                                                        0.0067; 0.093; 0.69; 0.04
fig4c terms p < 0.05 (written ref, factorial ref, written sum, factorial sum); c x ZX1 p                                                                                                         [2, 2, 2, 2]; 0.56
fig4c readings meeting the full criterion; the partial one (or the full)                                                                                                                             0 of 4; 0 of 4
fig4 post hoc p: HIGH-LOW CTRL; HIGH-LOW ZX1; ZX1 on HIGH; ZX1 on LOW                                                                                                                        0.015; 0.0045; 1; 0.93
fig4f readings with all four absence terms p >= 0.05                                                                                                                                                         0 of 4
fig4f KO ZX1 slope p (range); readings meeting the criterion                                                                                                                                   0.24 to 0.57; 0 of 4
fig6a ACSF CI; ZX1 readings (a)-(d) CI, overlap with ACSF                                   (0.266, 0.406); (a) (0.027, 0.081) False; (b) (-0.017, 0.052) False; (c) (0.076, 0.126) False; (d) (0.142, 0.211) False
fig6b (a) contrast intercept p; slope p                                                                                                                                                               6.6e-10; 0.28
fig6c readings within 240 (n, p below 50%); listed readings significant                                                                                           C CTRL (250, 0.032); D all (233, 0.00095); 4 of 9
methods corr readings matching both counts (r all, p below 50%)                                                                                                                                                none
fig6d genotype x tPoly1 b; p                                                                                                                                                                             -3.24; 0.2
discussion peak rise WT ZX1 HIGH; KO CTRL HIGH; WT CTRL HIGH                                                                                                                                      9.34; 9.58; 11.10

== round-1, without AA0319 and AA0334 ==
fig1f KW p; top bin; cells                                                                                                                                                                    3.2e-06; 32-43; 318
fig1g KW p; top bin                                                                                                                                                                                3.2e-08; 21-32
fig1h KW p; top bin (mean); bins above 1 (Wilcoxon)                                                                                                                                        5.5e-12; 54-65; 5 of 7
fig1i values; p_bin; p_int                                                                                                                                                                  1830; 2.7e-46; 0.0084
fig1i bins significant (Bonferroni 7; 91)                                                                                                                                                    ['54-65']; ['54-65']
fig2b p, trials                                                                                                                                                                          A 0.27; B 0.88; A+B 0.15
fig2c p, trials                                                                                                                                                                         A 0.12; B 0.22; A+B 0.011
fig3 all trials, p base; evoked; interaction; LRT                                                                                                                                     0.00013; 0.29; 0.64; 0.0027
fig3 <50% trials, p base; evoked; interaction; LRT                                                                                                                                      0.0072; 0.15; 0.98; 0.048
fig4c terms p < 0.05 (written ref, factorial ref, written sum, factorial sum); c x ZX1 p                                                                                                    [4, 5, 3, 3]; 1.1e-05
fig4c readings meeting the full criterion; the partial one (or the full)                                                                                                                           1 of 4; 4 of 4
fig4 post hoc p: HIGH-LOW CTRL; HIGH-LOW ZX1; ZX1 on HIGH; ZX1 on LOW                                                                                                                1.6e-06; 0.44; 0.31; 0.00011
fig4f readings with all four absence terms p >= 0.05                                                                                                                                                       1 of 4
fig4f KO ZX1 slope p (range); readings meeting the criterion                                                                                                                                  0.2 to 0.52; 0 of 4
fig6a ACSF CI; ZX1 readings (a)-(d) CI, overlap with ACSF                                   (0.281, 0.371); (a) (0.116, 0.164) False; (b) (0.126, 0.188) False; (c) (0.160, 0.201) False; (d) (0.231, 0.285) True
fig6b (a) contrast intercept p; slope p                                                                                                                                                            3.5e-05; 0.071
fig6c readings within 240 (n, p below 50%); listed readings significant                                                                                                                              none; 1 of 9
methods corr readings matching both counts (r all, p below 50%)                                                                                                                                              none
fig6d genotype x tPoly1 b; p                                                                                                                                                                        -6.11; 0.0034
discussion peak rise WT ZX1 HIGH; KO CTRL HIGH; WT CTRL HIGH                                                                                                                                  10.26; 10.84; 12.11

== main, group A without AA0335 ==
fig1f KW p; top bin; cells                                                                                                                                                                     2.8e-10; 21-32; 308
fig1g KW p; top bin                                                                                                                                                                                 1.1e-11; 32-43
fig1h KW p; top bin (mean); bins above 1 (Wilcoxon)                                                                                                                                         2.7e-15; 43-54; 5 of 7
fig1i values; p_bin; p_int                                                                                                                                                                   1750; 4.2e-52; 0.0046
fig1i bins significant (Bonferroni 7; 91)                                                                                                                                                     ['54-65']; ['54-65']
fig2b p, trials                                                                                                                                                                          A 0.028; B 0.4; A+B 0.054
fig2c p, trials                                                                                                                                                                         A 0.008; B 0.16; A+B 0.011
fig3 all trials, p base; evoked; interaction; LRT                                                                                                                                          0.00077; 1; 0.34; 0.024
fig3 <50% trials, p base; evoked; interaction; LRT                                                                                                                                         0.087; 0.65; 0.59; 0.32
fig4c terms p < 0.05 (written ref, factorial ref, written sum, factorial sum); c x ZX1 p                                                                                                       [5, 5, 4, 3]; 3e-05
fig4c readings meeting the full criterion; the partial one (or the full)                                                                                                                            2 of 4; 4 of 4
fig4 post hoc p: HIGH-LOW CTRL; HIGH-LOW ZX1; ZX1 on HIGH; ZX1 on LOW                                                                                                                   3.9e-08; 0.95; 0.015; 0.05
fig4f readings with all four absence terms p >= 0.05                                                                                                                                                        1 of 4
fig4f KO ZX1 slope p (range); readings meeting the criterion                                                                                                                                   0.2 to 0.33; 0 of 4
fig6a ACSF CI; ZX1 readings (a)-(d) CI, overlap with ACSF                                   (0.304, 0.398); (a) (0.107, 0.155) False; (b) (0.111, 0.171) False; (c) (0.145, 0.185) False; (d) (0.203, 0.255) False
fig6b (a) contrast intercept p; slope p                                                                                                                                                              1.5e-05; 0.11
fig6c readings within 240 (n, p below 50%); listed readings significant                                                                                                          B all (added) (230, 0.88); 1 of 9
methods corr readings matching both counts (r all, p below 50%)                                                                                                                                               none
fig6d genotype x tPoly1 b; p                                                                                                                                                                        -7.51; 0.00052
discussion peak rise WT ZX1 HIGH; KO CTRL HIGH; WT CTRL HIGH                                                                                                                                   10.49; 11.17; 13.23

== steps counted after the spike filter ==
fig1f KW p; top bin; cells                                                                                                                                                                     3.2e-06; 32-43; 318
fig1g KW p; top bin                                                                                                                                                                                 3.2e-08; 21-32
fig1h KW p; top bin (mean); bins above 1 (Wilcoxon)                                                                                                                                         5.5e-12; 54-65; 5 of 7
fig1i values; p_bin; p_int                                                                                                                                                                   1830; 2.7e-46; 0.0084
fig1i bins significant (Bonferroni 7; 91)                                                                                                                                                     ['54-65']; ['54-65']
fig2b p, trials                                                                                                                                                                          A 0.27; B 0.54; A+B 0.088
fig2c p, trials                                                                                                                                                                           A 0.12; B 0.18; A+B 0.01
fig3 all trials, p base; evoked; interaction; LRT                                                                                                                                      0.00013; 0.29; 0.64; 0.0027
fig3 <50% trials, p base; evoked; interaction; LRT                                                                                                                                       0.0072; 0.15; 0.98; 0.048
fig4c terms p < 0.05 (written ref, factorial ref, written sum, factorial sum); c x ZX1 p                                                                                                     [3, 4, 4, 4]; 0.00093
fig4c readings meeting the full criterion; the partial one (or the full)                                                                                                                            0 of 4; 4 of 4
fig4 post hoc p: HIGH-LOW CTRL; HIGH-LOW ZX1; ZX1 on HIGH; ZX1 on LOW                                                                                                                 1.7e-05; 0.98; 0.00036; 0.99
fig4f readings with all four absence terms p >= 0.05                                                                                                                                                        1 of 4
fig4f KO ZX1 slope p (range); readings meeting the criterion                                                                                                                                   0.2 to 0.52; 0 of 4
fig6a ACSF CI; ZX1 readings (a)-(d) CI, overlap with ACSF                                   (0.305, 0.393); (a) (0.109, 0.156) False; (b) (0.115, 0.173) False; (c) (0.141, 0.180) False; (d) (0.195, 0.246) False
fig6b (a) contrast intercept p; slope p                                                                                                                                                               0.0002; 0.12
fig6c readings within 240 (n, p below 50%); listed readings significant                                                                                                          B all (added) (239, 0.61); 1 of 9
methods corr readings matching both counts (r all, p below 50%)                                                                                                                                               none
fig6d genotype x tPoly1 b; p                                                                                                                                                                        -7.29; 0.00069
discussion peak rise WT ZX1 HIGH; KO CTRL HIGH; WT CTRL HIGH                                                                                                                                   10.49; 10.84; 13.20

trials below 50% of animal max: main 1055 of 1995 ; round-1 1179 of 2113 ; single pass 1447 of 2180

Summary¶

Claim Outcome
fig1f-tone-response-inverse-u reproduced
fig1g-reliability-intermediate reproduced
fig1h-cgc-largest-intermediate reproduced
fig1h-cgc-evident-all-bins not reproduced
fig1i-baseline-contrast-interaction reproduced
fig1i-contrast-effect-intermediate-only not reproduced
fig2b-evoked-pd-whole-drc not reproduced
fig2c-evoked-pd-1-2s blocked: methods underspecified
fig2e-drc-responses-no-difference not reproduced
fig3b-lme-coefficients reproduced
fig3c-lme-likelihood-ratio not reproduced
fig4c-wt-contrast-zx1-effects partially reproduced
fig4-wt-posthoc not reproduced
fig4f-ko-no-contrast-effect blocked: methods underspecified
fig4f-ko-zx1-slope not reproduced
fig5-contralateral-zx1-increases blocked: data missing
fig5-ipsilateral-zx1-reduces blocked: data missing
fig5c-no-dye-in-other-hemisphere blocked: data missing
fig6a-baseline-pd-drift partially reproduced
fig6b-acsf-contrast-effect partially reproduced
fig6c-no-baseline-evoked-correlation blocked: methods underspecified
methods-baseline-evoked-correlation blocked: methods underspecified
fig6d-ko-reduced-high-contrast reproduced
discussion-zx1-wt-like-ko 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:

  • The files hold the pupil radius per video frame, with dropped frames and tracking failures (up to 1.5e6 pixels), not the DeepLabCut points. The Methods' single derivative pass leaves these failures in, so a spike filter was added, the pass repeated, trials with more than half their frames missing dropped, and trials whose raw trace steps by more than a factor 2 between tracked frames dropped (118 of 2113). This sets each animal's maximum PD, hence the baseline in % of maximum and the 50% selection. The step rule reads the raw trace and so drops trials in 15 mice, not only the two whose failure runs it targets; counted after the spike filter it drops 39 trials in 6 mice and gives the same animal maxima. Several outcomes depend on the cleaning (variants at the end): with the round-1 cleaning, which kept the step trials, fig4c-wt-contrast-zx1-effects would be not reproduced (no interaction); fig4-wt-posthoc fails under every cleaning but the narrower step rule, which meets it; with the single pass, fig6c-no-baseline-evoked-correlation would be not reproduced, fig6d-ko-reduced-high-contrast not reproduced (p = 0.20), and the fig1i interaction not significant (p = 0.17), which would make fig1i-baseline-contrast-interaction partially reproduced.
  • The DRC trials without the tone switch contrast after 10 s (both orders, about equally often); a trial's contrast is that of its first 10 s, which covers the analysed 0 to 2 s. The 32 ZX1 DRC trials of AA0327 start the sound 10 s after the first frame, and the pupil dilates after that onset.
  • Groups are taken from the files' analysis labels; group A holds ten mice (paper eight; one is ZnT3-WT), group B twelve (paper fourteen C57BL6/J; six here are C57BL6/J), and the ZnT3-WT group five F and five M (paper six F and four M). Keeping the ZnT3-WT mouse AA0335 in group A is an assumption the Fig. 2b and Fig. 3b outcomes rest on: without it group A's Fig. 2b trial test becomes significant (p = 0.028), so the readings would disagree, and the Fig. 3 baseline coefficient is not significant in the trials below 50% (p = 0.087), which would make fig3b-lme-coefficients partially reproduced.
  • LME tests are Wald z tests from statsmodels, not Satterthwaite F tests; the Fig. 3 random intercepts for baseline and evoked PD are fitted as one trial intercept.
  • Recording time for Fig. 6a comes from the .tif creation times, since the table's starting times wrap by one day for trials recorded before the reference file.

What was found about the dataset: the files carry labels naming the paper's analyses, a per-trial table of sounds and treatments, ROI fluorescence and pupil radius, enough to test 21 of 24 claims. The widefield experiments of Figure 5 are not in it. Pupil traces hold tracking failures, in two mice as runs at a second level; 25 pupil series have a length that does not match their trial; every pupil series's description names the wrong TwoPhotonSeries; the stimulus table's starting times wrap by 24 h for 84 trials; the contrast-switching DRC stimulus is not described in the paper; and group sizes differ from the paper.

In [33]:
print(f"total run time {(time.time() - T0) / 60:.1f} min")
total run time 3.5 min