# mEPSC amplitude, KO vs WT: all events pooled (Kolmogorov-Smirnov test, as in cumulative distribution plots), neurons as n
# (median amplitude per neuron, log scale), and mice as n (mean of each mouse's neuron medians). R 4.3.3, base R.
d <- read.csv("mepsc.csv")                           # one row per event: genotype, mouse, cell, amplitude_pA
f2 <- function(p) formatC(signif(p, 2), format = "g")
ko <- d$genotype == "KO"
ks <- suppressWarnings(ks.test(d$amplitude_pA[ko], d$amplitude_pA[!ko], exact = FALSE))
cat(sprintf("All events pooled (%d vs %d events), Kolmogorov-Smirnov test: D = %.4f, p = %s\n", sum(ko), sum(!ko), ks$statistic, f2(ks$p.value)))
cell <- aggregate(amplitude_pA ~ genotype + mouse + cell, data = d, FUN = median); cell$log_med <- log(cell$amplitude_pA)
kc <- cell$genotype == "KO"; t1 <- t.test(cell$log_med[kc], cell$log_med[!kc])
cat(sprintf("Neurons as n (%d vs %d neurons, median amplitude per neuron): KO / WT %.2f, p = %s\n", sum(kc), sum(!kc), exp(mean(cell$log_med[kc]) - mean(cell$log_med[!kc])), f2(t1$p.value)))
mouse <- aggregate(log_med ~ genotype + mouse, data = cell, FUN = mean); km <- mouse$genotype == "KO"; t2 <- t.test(mouse$log_med[km], mouse$log_med[!km])
cat(sprintf("Mice as n (%d vs %d mice): KO / WT %.2f (95%% CI %.2f to %.2f), p = %s\n", sum(km), sum(!km),
            exp(mean(mouse$log_med[km]) - mean(mouse$log_med[!km])), exp(t2$conf.int[1]), exp(t2$conf.int[2]), f2(t2$p.value)))
cat(sprintf("Median amplitude: WT %.1f pA, KO %.1f pA\n", median(d$amplitude_pA[!ko]), median(d$amplitude_pA[ko])))
