bc = {
const r = rng(101 + bc_seed);
const ctrlPre = rnorm(r, bc_n, 10, 2);
const ctrlPost = ctrlPre.map((v) => v + bc_drift + rnorm(r, 1, 0, 2)[0]);
const trtPre = rnorm(r, bc_n, 10, 2);
const trtPost = trtPre.map((v) => v + bc_drift + bc_eff + rnorm(r, 1, 0, 2)[0]);
const groups = [[ctrlPre, 1, "control"], [ctrlPost, 2, "control"], [trtPre, 4, "impact"], [trtPost, 5, "impact"]];
const pts = groups.flatMap(([g, x, s]) => g.map((v) => ({x: x + (r() - 0.5) * 0.3, y: v})));
const ms = groups.map(([g, x, s]) => {
const m = mean(g), h = qt975(g.length - 1) * sd(g) / Math.sqrt(g.length);
return {x, m, lo: m - h, hi: m + h, site: s};
});
const apparent = ms[3].m - ms[2].m, control = ms[1].m - ms[0].m;
return {pts, ms, apparent, control, real: apparent - control};
}
html`<div>${Plot.plot({
width: 560, height: 320, marginLeft: 45,
x: {domain: [0.4, 5.6], ticks: [1, 2, 4, 5], tickFormat: (d) => ({1: "Control before", 2: "Control after", 4: "Impact before", 5: "Impact after"})[d], label: null},
y: {label: "Cat activity (detections)", grid: true},
color: {domain: ["control", "impact"], range: [grey, red]},
marks: [
Plot.dot(bc.pts, {x: "x", y: "y", fill: "#d6d6d6", r: 2.5}),
Plot.line(bc.ms, {x: "x", y: "m", z: "site", stroke: "site", strokeWidth: 2}),
Plot.ruleX(bc.ms, {x: "x", y1: "lo", y2: "hi", stroke: "site", strokeWidth: 3}),
Plot.dot(bc.ms, {x: "x", y: "m", fill: "site", r: 6})
]
})}
<div class="app-verdict">At the mine site alone, cat activity increased by <b>${fmt(bc.apparent)}</b>. But the control site changed by <b>${fmt(bc.control)}</b> without any mining.
The estimated effect of mining is the difference: <b>${fmt(bc.real)}</b>. Without a control site, the whole increase would have been blamed on mining.</div></div>`