Treat unsure and blank answers as missing information, not choices
- engine.js / analyze.py: one MISSING set ("Unknown", "Unsure",
"Unsure/unknown", "Multiple", "(not recorded)", "(not asked)", ...).
Factor tables compare only runs that answered each question and report how
many were left out; models are complete-case for every choice variable;
route rankings group only fully known routes; the route flow skips
missing steps.
- "I've lost count" now counts as a later attempt.
- The chase goal keeps its "not asked" stratum as an adjustment only; it is
no longer displayed as a finding.
- Page: no unknown levels in charts, tables or filters; factor explorer notes
how many runs were left out; Methods explains the rule.
JS/Python parity still exact.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
de80e99c74
commit
1b0ef9a2c1
+28
-16
@@ -22,6 +22,13 @@
|
||||
|
||||
const COLORS = ["Red", "Green", "Orange", "Brown", "Blue", "Black"];
|
||||
|
||||
// Answers that carry no information about the choice ("Unsure", blank, a question the form did not ask yet,
|
||||
// conflicting answers). They are kept in the coded data for transparency, but every analysis treats them as
|
||||
// missing: they are never shown or compared as if they were a choice.
|
||||
const MISSING = new Set(["Unknown", "Unsure", "Unsure/unknown", "Multiple", "(not recorded)", "(not asked)",
|
||||
"(not asked/blank)", "Unknown/lost count", "Blank/not asked"]);
|
||||
const isMissing = (v) => v === null || v === undefined || v === "" || MISSING.has(v);
|
||||
|
||||
// ---------------------------------------------------------------- column detection
|
||||
const COLUMN_KEYS = {
|
||||
timestamp: ["timestamp"],
|
||||
@@ -312,7 +319,8 @@
|
||||
|
||||
return {
|
||||
source, date, wing, section, squad: g("squad") || "Unknown", attempt,
|
||||
attempt_group: attempt === 1 ? "First attempt" : attempt > 1 ? "Later attempt" : "Unknown/lost count",
|
||||
// "I've lost count" means many attempts, so it is a later attempt, not missing
|
||||
attempt_group: attempt === 1 ? "First attempt" : attempt > 1 || /lost count/i.test(g("attempt") || "") ? "Later attempt" : "Unknown",
|
||||
goal, company, left_squadmates: leftSquad, direction, first_sighting: first || "Unknown",
|
||||
sighting_action: "sighting_action" in C ? SIGHTING_ACTION[g("sighting_action")] || g("sighting_action") || "Unknown" : "(not asked)",
|
||||
scream, resolution, combat_first: combat || "(not recorded)", combat_second: combat2 || "(not recorded)",
|
||||
@@ -555,9 +563,10 @@
|
||||
const O = OUTCOMES[outKey];
|
||||
const D = runs.filter(O.denom);
|
||||
const total = D.length, events = D.filter(O.event).length;
|
||||
const rows = [];
|
||||
const rows = [], missing = {};
|
||||
for (const f of FACTORS) {
|
||||
const groups = groupBy(D.filter((r) => r[f] !== null && r[f] !== undefined), f);
|
||||
const groups = groupBy(D.filter((r) => !isMissing(r[f])), f);
|
||||
missing[f] = D.filter((r) => isMissing(r[f])).length;
|
||||
const nf = Object.values(groups).reduce((s, g) => s + g.length, 0);
|
||||
const ef = Object.values(groups).reduce((s, g) => s + g.filter(O.event).length, 0);
|
||||
for (const lv of sortedKeys(groups)) {
|
||||
@@ -570,7 +579,7 @@
|
||||
}
|
||||
const tested = rows.filter((r) => r.fisher_p !== undefined);
|
||||
bh(tested.map((r) => r.fisher_p)).forEach((q, i) => (tested[i].q = q));
|
||||
return { outcome: outKey, label: O.label, overall: wilson(events, total), rows };
|
||||
return { outcome: outKey, label: O.label, overall: wilson(events, total), rows, missing };
|
||||
}
|
||||
|
||||
// Multivariable model: one row per run in the outcome's denominator; categorical factors dummy-coded
|
||||
@@ -664,18 +673,19 @@
|
||||
for (const key of Object.keys(OUTCOMES)) res.factors[key] = factorTable(runs, key);
|
||||
|
||||
// adjusted models
|
||||
const first2 = (r) => ["Red", "Brown", "Orange", "Green"].includes(r.first_sighting) ? r.first_sighting : "Unsure/unknown";
|
||||
const first2 = (r) => (["Red", "Brown", "Orange", "Green"].includes(r.first_sighting) ? r.first_sighting : null);
|
||||
const known = (f) => (r) => (isMissing(r[f]) ? null : r[f]);
|
||||
const src2 = (r) => (r.source === "Form" ? "Form submission" : "Bulk log (import)");
|
||||
res.models = {
|
||||
blue_meadow: model(runs, "blue_meadow", {
|
||||
source: src2, goal: goal2, direction: (r) => r.direction, first_sighting: first2,
|
||||
resolution: (r) => r.resolution, company: (r) => (r.company === "Unknown" ? null : r.company),
|
||||
source: src2, goal: goal2, direction: known("direction"), first_sighting: first2,
|
||||
resolution: known("resolution"), company: known("company"),
|
||||
}),
|
||||
shadow: model(runs, "shadow", {
|
||||
source: src2, goal: goal2, attempt: (r) => r.attempt_group, direction: (r) => r.direction,
|
||||
source: src2, goal: goal2, attempt: known("attempt_group"), direction: known("direction"),
|
||||
}),
|
||||
bond_blue_meadow: model(runs, "bond_blue_meadow", {
|
||||
source: src2, goal: goal2, direction: (r) => r.direction, resolution: (r) => r.resolution,
|
||||
source: src2, goal: goal2, direction: known("direction"), resolution: known("resolution"),
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -714,13 +724,13 @@
|
||||
|
||||
function stageValue(r, key) {
|
||||
switch (key) {
|
||||
case "company": return r.company;
|
||||
case "direction": return r.direction;
|
||||
case "first_sighting": return r.scream === "DIED at first sighting" ? null : r.first_sighting;
|
||||
case "company": return isMissing(r.company) ? null : r.company;
|
||||
case "direction": return isMissing(r.direction) ? null : r.direction;
|
||||
case "first_sighting": return r.scream === "DIED at first sighting" || isMissing(r.first_sighting) ? null : r.first_sighting;
|
||||
case "cadet":
|
||||
if (r.scream.startsWith("DIED")) return null;
|
||||
if (r.scream.startsWith("DIED") || isMissing(r.scream) || isMissing(r.resolution)) return null;
|
||||
return r.scream === "Investigate & help" ? "Help → " + r.resolution : r.scream + " → " + r.resolution;
|
||||
case "post_path": return r.post_path;
|
||||
case "post_path": return isMissing(r.post_path) ? null : r.post_path;
|
||||
case "hour": return r.hour === "Tree" ? "Climb the tree" : r.hour === "Valley" ? "Valley centre" : null;
|
||||
case "encounter": {
|
||||
if (!r.branch) return null;
|
||||
@@ -803,7 +813,9 @@
|
||||
const keyStages = STAGES.slice(0, 6).map((s) => s.key);
|
||||
const pool = runs.filter(TARGETS[targetKey].pool);
|
||||
const totK = pool.filter(T).length, totN = pool.length;
|
||||
const groups = groupBy(pool, (r) => keyStages.map((k) => stageValue(r, k) || "—").join(" › "));
|
||||
// a route is only ranked from runs whose every step is known; runs with a gap still count in the comparison group
|
||||
const groups = groupBy(pool.filter((r) => keyStages.every((k) => stageValue(r, k) || (k === "post_path" && r.post_path === null))),
|
||||
(r) => keyStages.map((k) => stageValue(r, k) || "—").join(" › "));
|
||||
const rows = Object.entries(groups).filter(([, g]) => g.length >= minN).map(([key, g]) => {
|
||||
const k = g.filter(T).length, n = g.length;
|
||||
const o = Object.assign({ route: key, values: keyStages.map((s) => stageValue(g[0], s)) }, wilson(k, n));
|
||||
@@ -826,7 +838,7 @@
|
||||
}
|
||||
|
||||
return {
|
||||
COLORS, COLUMN_KEYS, STAGES, TARGETS, OUTCOMES, FACTORS, ROUTE_FIELDS, rankRoutes,
|
||||
COLORS, MISSING, isMissing, COLUMN_KEYS, STAGES, TARGETS, OUTCOMES, FACTORS, ROUTE_FIELDS, rankRoutes,
|
||||
findColumns, codeRow, codeRows, parseTimestamp,
|
||||
wilson, fisher, oddsRatio, bh, logisticRidge, mantelHaenszel,
|
||||
applyFilters, analyse, factorTable, model, buildGraph, stageValue, stratum,
|
||||
|
||||
@@ -133,7 +133,8 @@
|
||||
/* ---------- Decision-variable graph (all sources) ---------- */
|
||||
|
||||
const VAR_STAGES = ["company", "direction", "first_sighting", "scream", "resolution", "post_path", "hour", "branch"];
|
||||
const MISSING = new Set([null, undefined, "", "Unknown", "Unsure", "Multiple", "(no fork)", "(not recorded)"]);
|
||||
// "(no fork)" is a real state (that path has no fork), but it is not a choice node, so it is skipped too
|
||||
const MISSING = new Set([null, undefined, "", "Unknown", "Unsure", "Unsure/unknown", "Multiple", "(no fork)", "(not recorded)", "(not asked)", "(not asked/blank)", "Unknown/lost count"]);
|
||||
|
||||
function endLabel(v) {
|
||||
if (v.outcome === "Bonded") return v.outcome_color ? `Bonded ${v.outcome_color}` : "Bonded (colour unknown)";
|
||||
|
||||
Reference in New Issue
Block a user