# Novel object recognition: discrimination index against chance and between groups. R 4.3.3, base R.
d <- read.csv("nor.csv"); d$total <- d$novel_s + d$familiar_s
cat(sprintf("Excluded (total exploration < 20 s, rule set in advance): %s\n", paste(d$mouse[d$total < 20], collapse = ", ")))
cat(sprintf("Mean total exploration, all mice before exclusion: WT %.1f s; KO %.1f s\n", mean(d$total[d$genotype == "WT"]), mean(d$total[d$genotype == "KO"])))
k <- d[d$total >= 20, ]; k$di <- (k$novel_s - k$familiar_s) / k$total
for (g in c("WT", "KO")) { x <- k$di[k$genotype == g]; t <- t.test(x, mu = 0)
  cat(sprintf("%s: n = %d, mean DI %.3f (95%% CI %.3f to %.3f); one-sample t-test vs 0: t = %.2f, p = %.4f; mean total exploration %.1f s\n",
              g, length(x), mean(x), t$conf.int[1], t$conf.int[2], t$statistic, t$p.value, mean(k$total[k$genotype == g]))) }
w <- k$di[k$genotype == "WT"]; ko <- k$di[k$genotype == "KO"]; t <- t.test(ko, w)
cat(sprintf("KO - WT difference in DI: %.3f (95%% CI %.3f to %.3f), Welch's t-test p = %.4f\n", mean(ko) - mean(w), t$conf.int[1], t$conf.int[2], t$p.value))
