Under-querying vs out of data: the answer depends on the unit
The platoon test's n=452 described how much of the JOIN survived, not how much data exists. There are 1,266 clean settled hits rows and zero quarantined ones. platoon_splits had been ingested from tonight's lineups only (315 players), so any hitter who settled a prop without appearing in an ingest-day lineup was silently absent from every test. Backfilled all 380 hitters (81 fetched, 0 unresolved). Re-ran on 1,059 rows, up from 452. THE DEMOTION IS THE HEADLINE. pitcher_contact_profile, the strongest proven factor in the programme (-0.0064, CI [-0.0113,-0.0014]), roughly halved to -0.0034 on more than double the sample and its corrected interval now spans zero. The Bonferroni denominator also rose to 55, which widens every interval -- but a denominator cannot move a point estimate, and that halved on its own. platoon and platoon_severity now clear the bar and are NOT promoted. Upper bound -0.0001, on season-to-date splits that contain the games they predict: measured contamination is 4.5% median, 12.4% at p90, 137% worst. I had assumed ~1%. They stay CANDIDATE pending point-in-time splits. GAME-LEVEL IS A DIFFERENT PROBLEM. game_context held zero weather rows ever -- not because the fetcher was wrong (it correctly targets Open-Meteo's archive) but because ledger_entries keys a game as mlb:2026-08-03:Away@Home and game_context keys it as mlb:823437. Every lookup missed and NULL columns read as honest absence. Third occurrence of that class. Fixed the join: 96/101 settled games now carry actual archived weather, park dimensions backfilled 15 -> 30 venues. But 928 total_bases rows sit on 47 games at 17.6 rows per game. Park and weather assign one value per game, so resampling rows would have manufactured a pass. factorGate now resamples clusters when rows carry one and judges sample against effective_n; unclustered rows keep the original path byte-for-byte. Verdict: 47 clusters < 500, and the point estimate is +0.0011 -- worse, not merely unproven. Weather needs ~57 more days. Park dimensions need never: there are 30 ballparks in MLB, so a venue-constant factor can never reach 500 independent units. That bar was built for player-level factors and does not transfer. Wind is refused. We have speed and bearing for all 96 games; we lack park orientation, and 220 degrees is blowing out at one park and in at another. Using speed alone would assert an effect while discarding the sign that decides what it is. Counter and frozen clusters untouched. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W1sivYNqY2TS5ftykmHBU9
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* prove-park-weather — DOES PARK GEOMETRY AND AIR READ TOTAL BASES?
|
||||
*
|
||||
* Run through the two-part gate like every other factor, with one addition that
|
||||
* changes the answer: the rows are CLUSTERED BY GAME. Park and weather assign a
|
||||
* single value to every hitter in a ballpark on a night, so eighteen prop rows
|
||||
* from one game are one reading of that game's conditions. Resampling rows would
|
||||
* treat them as eighteen and hand back an interval far tighter than the evidence
|
||||
* supports — which is how a gate passes a factor on sample it never had.
|
||||
*
|
||||
* SUPABASE_URL=... node scripts/prove-park-weather.js
|
||||
*/
|
||||
|
||||
require('dotenv').config();
|
||||
const { createClient } = require('@supabase/supabase-js');
|
||||
const pw = require('../src/services/model/parkWeather');
|
||||
const fg = require('../src/services/model/factorGate');
|
||||
const tl = require('../src/services/model/testLedger');
|
||||
const { knownNumber } = require('../src/utils/known');
|
||||
|
||||
const SB_URL = process.env.SUPABASE_URL;
|
||||
const SB_KEY = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_SERVICE_KEY;
|
||||
const PAGE = 1000;
|
||||
|
||||
async function page(sb, table, select, apply) {
|
||||
const out = [];
|
||||
for (let from = 0; ; from += PAGE) {
|
||||
const { data, error } = await apply(sb.from(table).select(select)).range(from, from + PAGE - 1);
|
||||
if (error) throw error;
|
||||
if (!data || data.length === 0) break;
|
||||
out.push(...data);
|
||||
if (data.length < PAGE) break;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Hit-type shares → expected total bases, so a reshape has a consequence. */
|
||||
const tbFromShares = (s) => s.single + 2 * s.double + 3 * s.triple + 4 * s.home_run;
|
||||
|
||||
async function main() {
|
||||
const sb = createClient(SB_URL, SB_KEY, { auth: { persistSession: false } });
|
||||
|
||||
const parks = await page(sb, 'park_dimensions', '*', (q) => q.eq('sport', 'mlb'));
|
||||
const byVenue = new Map();
|
||||
for (const p of parks) if (!byVenue.has(p.venue_id)) byVenue.set(p.venue_id, p);
|
||||
const league = pw.leagueGeometry([...byVenue.values()]);
|
||||
|
||||
const ctx = await page(sb, 'game_context', 'game_id, venue_id, wx_temp_f, wx_wind_speed_mph, wx_wind_direction_deg', (q) => q);
|
||||
const ctxBy = new Map(ctx.map((c) => [c.game_id, c]));
|
||||
|
||||
const led = await page(sb, 'ledger_entries',
|
||||
'game_id, game_date, player_key, stat, line, side, outcome, quarantine_reason, p_win, proj_hits_p_over',
|
||||
(q) => q.eq('sport', 'mlb').is('user_id', null).eq('stat', 'total_bases').in('outcome', ['hit', 'miss']));
|
||||
const clean = led.filter((r) => !(r.quarantine_reason || '').startsWith('nontakeable_book'));
|
||||
|
||||
// League-typical hit-type shares — the shape the atom reshapes.
|
||||
const BASE_SHARES = { single: 0.655, double: 0.195, triple: 0.017, home_run: 0.133 };
|
||||
const baseTb = tbFromShares(BASE_SHARES);
|
||||
|
||||
const loss = { no_context: 0, no_venue: 0, no_park: 0, no_baseline: 0, kept: 0 };
|
||||
const rows = [];
|
||||
for (const r of clean) {
|
||||
const c = ctxBy.get(r.game_id);
|
||||
if (!c) { loss.no_context += 1; continue; }
|
||||
if (c.venue_id == null) { loss.no_venue += 1; continue; }
|
||||
const dims = byVenue.get(c.venue_id);
|
||||
if (!dims) { loss.no_park += 1; continue; }
|
||||
|
||||
const baseline = knownNumber(r.p_win);
|
||||
if (baseline === null) { loss.no_baseline += 1; continue; }
|
||||
|
||||
const read = pw.parkWeatherRead({ dims, wx: c, league });
|
||||
if (!read) { loss.no_park += 1; continue; }
|
||||
|
||||
// The atom reshapes hit type; the consequence for total bases is the ratio
|
||||
// of expected bases per hit under the reshaped shape.
|
||||
const shaped = pw.applyToShares(BASE_SHARES, read);
|
||||
const ratio = tbFromShares(shaped) / baseTb;
|
||||
const conditioned = Math.max(0.01, Math.min(0.99, baseline * ratio));
|
||||
|
||||
rows.push({
|
||||
cluster: r.game_id, // ONE reading per game — the whole point
|
||||
baseline,
|
||||
conditioned,
|
||||
won: r.outcome === 'hit' ? 1 : 0,
|
||||
});
|
||||
loss.kept += 1;
|
||||
}
|
||||
|
||||
// Cumulative Bonferroni across the programme lifetime — this hypothesis is
|
||||
// one more test, and the bar rises for it like every other.
|
||||
const mc = await tl.recordAndCount(tl.supabaseStore(sb), [
|
||||
{ sport: 'mlb', stat: 'total_bases', archetype: null, interaction: 'factor:park_weather_hit_type', target: 'outcome' },
|
||||
]);
|
||||
const verdict = fg.adjudicate(rows, {
|
||||
factor: 'park_weather_hit_type',
|
||||
stat: 'total_bases',
|
||||
cumulativeTests: mc.cumulative_tests,
|
||||
});
|
||||
|
||||
const games = new Set(rows.map((r) => r.cluster)).size;
|
||||
const venues = new Set(clean.map((r) => ctxBy.get(r.game_id)?.venue_id).filter((v) => v != null)).size;
|
||||
|
||||
console.log(JSON.stringify({
|
||||
clean_settled_tb_rows: clean.length,
|
||||
rows_built: rows.length,
|
||||
row_loss: loss,
|
||||
distinct_games: games,
|
||||
distinct_venues: venues,
|
||||
rows_per_game: games ? Math.round((rows.length / games) * 10) / 10 : null,
|
||||
cumulative_tests: mc.cumulative_tests,
|
||||
verdict,
|
||||
honest_note: 'sample judged in GAMES, not prop rows — park and weather vary per game',
|
||||
}, null, 2));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
main().catch((e) => { console.error(e); process.exit(1); });
|
||||
Reference in New Issue
Block a user