# Constructed data: novel object recognition test, 12 wild-type (WT) and 12 knockout (KO) mice.
# True mean DI 0.20 in BOTH groups (no difference). Exclusion rule, set in advance: total exploration < 20 s.
# The seed (3, found by the search below) is the first from 1 upward where the one-sample tests disagree (WT p < 0.05, KO p > 0.05)
# after exclusions, the situation this page is about; the simulation shows how often that happens.
import numpy as np, pandas as pd
from scipy import stats
from model import simulate
for seed in range(1, 1000):
    rng = np.random.default_rng(seed)
    rows = []
    for g in ("WT", "KO"):
        nov, fam = simulate(rng, 12, 0.20)
        rows += [(f"{g}{i+1}", g, n, f) for i, (n, f) in enumerate(zip(nov, fam))]
    d = pd.DataFrame(rows, columns=["mouse", "genotype", "novel_s", "familiar_s"])
    k = d[d.novel_s + d.familiar_s >= 20]; di = (k.novel_s - k.familiar_s) / (k.novel_s + k.familiar_s)
    pw = stats.ttest_1samp(di[k.genotype == "WT"], 0).pvalue; pk = stats.ttest_1samp(di[k.genotype == "KO"], 0).pvalue
    if pw < 0.05 and pk > 0.05 and (d.novel_s + d.familiar_s < 20).sum() >= 1:
        print("seed", seed); d.to_csv("nor.csv", index=False); break
