/** * Statistical primitives for v0.5 LLM-judge harness — paired-t CI * computation + 4-level aggregation pipeline per ADR-19 §4. * * Per ADR-19 §4 (descriptive CI only; paired-t for difference-of-means * per 2026-05-03 amendment commit `05c9fc7`) + Step 1.4 statistical * methodology lock + STEP-PLAN-V0.5 Step 5. Roll-our-own t-distribution * lookup honors CLAUDE.md "Dependencies: Minimize" principle (~30 LOC * lookup table; no simple-statistics or scipy dependency). * * Variance / standardDeviation use SAMPLE standard deviation * (Bessel's correction; n-1 denominator) per textbook convention. * Matches scipy.stats.tstd default. Required for t-distribution * assumptions to hold; also matches reference values used in test * substrate. * * Difference-of-means CI uses paired-t per ADR-19 §4 amendment: * df = n − 1 * mean_diff = mean(differences) where differences[i] = groupA[i] − groupB[i] * SE_diff = sd(differences) / sqrt(n) * CI_diff = mean_diff ± t_critical(df, α/2) × SE_diff * * Cross-cell rollup applies the same paired-t primitive at the * concatenated-differences scale (Option B-2 lock per Step 5 design): * concat all per-cell raw differences across cells; apply paired-t at * N=25 base substrate; df=24. Single primitive at two scales keeps * the formula uniform. * * t-table provenance: scipy.stats.t.ppf(1 - α/2, df) for df=1..30 + ∞, * α ∈ {0.025, 0.05}. Generated against scipy v1.x; values frozen as * TypeScript object literal at 6-decimal precision. To regenerate * (e.g., precision sweep or coverage extension): scipy.stats.t.ppf in * a Python repl with the same df/α inputs; values are stable to * machine precision; 6-decimal rounding has no impact on CI bounds at * v0.5 substrate scale. * * See: * - docs/adr/ADR-19-llm-judge-methodology.md §4 (paired-t amendment; * CI computation paragraph; 4-level aggregation table) + §Revision * history (2026-05-03 amendment entry) * - docs/adr/ADR-02-extraction-sole-api-caller.md (amended 2026-04-30; * src/grading/ permitted module; this file does not call API) * - STEP-PLAN-V0.5.md Step 5 (statistical tooling implementation) */ /** * Two-sided CI levels supported. 0.95 → α/2 = 0.025; 0.90 → α/2 = 0.05. */ export type CILevel = 0.95 | 0.9; /** * Look up t_critical for given (df, ciLevel). df > 30 falls back to the * z-distribution asymptote (1.959964 for 95% CI; 1.644854 for 90% CI) * with implicit narrow-CI bias of <2% per textbook convention. df < 1 * throws (no CI computable). */ export declare function tCritical(df: number, ciLevel: CILevel): number; /** * Sample variance: sum((x_i − mean)^2) / (n − 1). Bessel's correction * applied. Matches scipy.stats.tstd default (and t-distribution * theoretical assumption). Throws if n < 2 (no variance computable). */ export declare function variance(values: readonly number[]): number; /** sqrt(variance). Same n>=2 requirement. */ export declare function standardDeviation(values: readonly number[]): number; /** Arithmetic mean. Throws if empty. */ export declare function mean(values: readonly number[]): number; /** * (max − min) / mean. ADR-19 §5 variance trigger metric for low-N * cells where range/mean is preferred over CV for cross-cycle * comparability with Phase 8 §8 framing. Throws on empty or * mean=0 (division by zero would yield Inf/NaN; loud-fail). */ export declare function rangeOverMean(values: readonly number[]): number; export interface MeanCI { mean: number; ciLower: number; ciUpper: number; n: number; df: number; tCritical: number; ciLevel: CILevel; /** sd / sqrt(n); useful for downstream pooled-SE checks. */ standardError: number; } /** * 95% (or 90%) CI on a single sample via single-sample t formula. * df = n − 1; SE = sample-sd / sqrt(n). Throws if n < 2 (variance * not computable; per-axis rubric scores at n=1 cannot bound a CI). */ export declare function meanWithCI(values: readonly number[], ciLevel?: CILevel): MeanCI; export interface DifferenceCI { meanA: number; meanB: number; meanDifference: number; ciLowerDifference: number; ciUpperDifference: number; /** True iff difference CI excludes zero per ADR-19 §4. */ distinguishable: boolean; n: number; df: number; tCritical: number; ciLevel: CILevel; standardErrorDifference: number; /** * Raw paired differences (groupA[i] − groupB[i]). Carried through the * pipeline so cross-cell rollup can concat across cells per Option * B-2 lock without forcing the caller to thread raw values * separately. */ rawDifferences: number[]; } /** * Paired-t difference-of-means CI per ADR-19 §4 amendment. Computes * differences[i] = groupA[i] − groupB[i] then a single-sample CI on * the differences (df = n − 1; SE = sd(differences) / sqrt(n)). * * Throws if groupA.length !== groupB.length (paired-t requires * one-to-one correspondence) or if either is empty/n<2. */ export declare function differenceOfMeansCI(groupA: readonly number[], groupB: readonly number[], ciLevel?: CILevel): DifferenceCI; export type Condition = "ca" | "beta-ca"; export interface PerCellInput { cellId: string; condition: Condition; metric: string; values: number[]; } export interface PerCellAggregate extends MeanCI { cellId: string; condition: Condition; metric: string; } export interface PerCellDifference extends DifferenceCI { cellId: string; metric: string; } export interface CrossCellRollup extends DifferenceCI { metric: string; /** Cells that contributed to the concatenated paired-t. */ cellIds: string[]; } /** * Per-cell aggregate per (cell, condition, metric). Slim summary view * over MeanCI; raw values are NOT carried forward (PerCellAggregate is * a derived view per Step 5 design Q5 lock). Caller threads raw values * separately to aggregatePerCellDifference for paired-t computation. */ export declare function aggregatePerCell(input: PerCellInput, ciLevel?: CILevel): PerCellAggregate; /** * Per-cell paired-t difference CI per ADR-19 §4 amendment. Takes raw * caValues + betaCaValues arrays (paired by trial-index); computes * paired-t difference internally. PerCellDifference carries * rawDifferences for downstream cross-cell rollup per Option B-2 lock. */ export declare function aggregatePerCellDifference(cellId: string, metric: string, caValues: readonly number[], betaCaValues: readonly number[], ciLevel?: CILevel): PerCellDifference; /** * Cross-cell rollup per ADR-19 §4 Option B-2 lock: concat all paired * differences across cells; apply paired-t at the concatenated scale * (e.g., 5 cells × n=5 → N=25 paired obs; df=24). All input cells * must agree on metric (caller's responsibility — function asserts). */ export declare function aggregateCrossCellRollup(perCellDifferences: readonly PerCellDifference[], ciLevel?: CILevel): CrossCellRollup; //# sourceMappingURL=stats.d.ts.map