import { type ContinuousAgreement, type ContinuousAgreementOptions } from './judge-calibration';
import type { JudgeScore } from './types';
/** Identity: dimensions already follow "higher = better" by prompt convention
 *  (inverted dims like hallucination are scored 10 = best at the source). */
export declare const normalizeScores: (scores: JudgeScore[]) => JudgeScore[];
/** Weighted mean — falls back to uniform weights when omitted */
export declare function weightedMean(scores: {
    score: number;
    weight?: number;
}[]): number;
/** Bootstrap confidence interval */
export declare function confidenceInterval(scores: number[], confidence?: number, opts?: {
    seed?: number;
    resamples?: number;
}): {
    mean: number;
    lower: number;
    upper: number;
};
/**
 * Inter-rater reliability — simplified Krippendorff's alpha.
 *
 * Each inner array is one judge's scores for all items.
 * All arrays must have the same length (same items scored).
 */
export declare function interRaterReliability(judgeScores: JudgeScore[][]): number;
/**
 * Mann-Whitney U test for comparing two independent groups.
 * Returns U statistic and approximate p-value (normal approximation).
 */
export declare function mannWhitneyU(a: number[], b: number[]): {
    u: number;
    p: number;
};
/** Partial credit: returns 0-1 ratio of current toward target */
export declare function partialCredit(current: number, target: number): number;
/**
 * Paired t-test — before/after measurements on the SAME items.
 * Pairing removes inter-item variance, giving tighter significance than
 * an unpaired test when comparing prompt v1 vs prompt v2 on identical
 * scenarios.
 */
export declare function pairedTTest(before: number[], after: number[]): {
    t: number;
    df: number;
    p: number;
};
/**
 * Wilcoxon signed-rank test — paired non-parametric alternative.
 * Use when the differences aren't normally distributed.
 */
export declare function wilcoxonSignedRank(before: number[], after: number[]): {
    w: number;
    p: number;
};
/**
 * Cohen's d — standardized effect size for two independent groups.
 * Positive d means group b has higher mean than group a.
 * Rule of thumb: |d| < 0.2 negligible, 0.2–0.5 small, 0.5–0.8 medium, > 0.8 large.
 */
export declare function cohensD(a: number[], b: number[]): number;
export type CliffsMagnitude = 'negligible' | 'small' | 'medium' | 'large';
/**
 * Cliff's delta — a non-parametric effect size for two independent samples.
 * `δ = (#(after > before) − #(after < before)) / (n_before · n_after)`,
 * ranging [-1, 1]. Positive ⇒ `after` tends to exceed `before` (improvement).
 *
 * Distribution-free counterpart to Cohen's d: no normality assumption, robust
 * to the bounded/skewed score distributions judges produce. Pairs with
 * `pairedBootstrap` / `wilcoxonSignedRank` for the non-parametric reporting
 * path. Returns 0 when either sample is empty.
 */
export declare function cliffsDelta(before: number[], after: number[]): number;
/**
 * Map a Cliff's delta to a qualitative magnitude using the standard
 * Romano et al. thresholds (|δ|): <0.147 negligible, <0.33 small,
 * <0.474 medium, else large.
 */
export declare function interpretCliffs(delta: number): CliffsMagnitude;
export interface WeightedCompositeInput {
    /** Per-dimension scores (typically 0..1). */
    dims: Record<string, number>;
    /** Weight per dimension. Every weighted dimension MUST be present in
     *  `dims` — a weight for an absent dimension is a config error and throws,
     *  because silently dropping it would renormalise the composite onto a
     *  different denominator than intended. */
    weights: Record<string, number>;
    /** Optional pass threshold; when set, the result reports `pass`. */
    threshold?: number;
}
export interface WeightedCompositeResult {
    composite: number;
    pass?: boolean;
}
/**
 * Weighted composite over judge dimensions: `Σ(score_d · w_d) / Σ(w_d)` across
 * the weighted dimensions. The canonical replacement for the per-consumer
 * hand-rolled composite math (tax/legal/creative/gtm each ship a copy).
 *
 * Fail-loud: throws if a weighted dimension is missing from `dims`, if any
 * weight is negative, or if the weights sum to 0 — none of which can produce
 * a meaningful composite.
 */
export declare function weightedComposite(input: WeightedCompositeInput): WeightedCompositeResult;
export interface CorpusScoreRecord {
    /** Stable identifier for the rated item (scenario, span, turn, …). */
    itemId: string;
    /** Identifier for the judge that produced this score. */
    judgeName: string;
    /** Dimension name (matches `JudgeScore.dimension`). */
    dimension: string;
    /** Numeric score; must be finite. */
    score: number;
}
export interface CorpusAgreementPerDimension extends ContinuousAgreement {
    dimension: string;
    /** Item IDs that contributed to this dimension's matrix (every judge scored them). */
    itemIds: string[];
    /** Judge IDs that contributed to this dimension's matrix. */
    judgeIds: string[];
}
export interface CorpusAgreementReport {
    /** Per-dimension ICC(2,1) + κ_w + Pearson + Spearman + bootstrap CIs. */
    perDimension: CorpusAgreementPerDimension[];
    /** Mean ICC across dimensions (NaN if no dimension yielded a finite ICC). */
    overallIcc: number;
    /** Mean weighted κ across dimensions (NaN if none finite). */
    overallWeightedKappa: number;
    /** Dimensions evaluated (sorted). */
    dimensions: string[];
    /** Judges seen across the corpus (sorted). */
    judgeIds: string[];
}
export interface CorpusAgreementOptions extends ContinuousAgreementOptions {
    /**
     * Restrict the audit to these dimensions. Default = every dimension
     * that appears in the input. A dimension named here but absent from
     * the input throws — silent omission would corrupt the overall metric.
     */
    dimensions?: string[];
    /**
     * Restrict the audit to these judges. Default = every judge that
     * appears in the input. A judge named here but absent from a
     * dimension throws (see "fail loud" below).
     */
    judges?: string[];
}
/**
 * Corpus-wide inter-rater agreement across N items × M judges × D dimensions.
 *
 * For each dimension, builds the [n_items][n_judges] matrix of scores
 * (keeping only items every judge rated on that dimension), then runs
 * `continuousAgreement` to get ICC(2,1), κ_w, Pearson, Spearman, and
 * bootstrap CIs. Reports a pooled mean across dimensions as a single
 * "is this judge panel reliable on this corpus?" number.
 *
 * Fail-loud contract:
 *   - Empty input throws.
 *   - Fewer than 2 judges or fewer than 2 items per dimension throws.
 *   - A judge present in some dimensions but with zero scored items on
 *     another dimension throws (would silently shrink the matrix).
 *   - Duplicate (itemId, judgeName, dimension) records throw.
 */
export declare function corpusInterRaterAgreement(records: CorpusScoreRecord[], opts?: CorpusAgreementOptions): CorpusAgreementReport;
/**
 * Convenience adapter for `JudgeScore[]` data keyed externally by item.
 *
 * Use when you have per-item arrays of `JudgeScore[]` (e.g. one
 * `ScenarioResult.judgeScores` per scenario) and want corpus-wide
 * agreement without manually flattening. `itemId` must be unique per
 * row of `itemsScores`.
 */
export declare function corpusInterRaterAgreementFromJudgeScores(itemsScores: Array<{
    itemId: string;
    scores: JudgeScore[];
}>, opts?: CorpusAgreementOptions): CorpusAgreementReport;
/**
 * Required N per arm for a two-sample comparison at target effect size,
 * alpha, and power. Normal-approximation formula:
 *   n = 2 * ( (z_{1-α/2} + z_{1-β}) / d )^2
 * where d is Cohen's d. Returns Infinity for effect ≤ 0.
 */
export declare function requiredSampleSize(opts: {
    effect: number;
    alpha?: number;
    power?: number;
    twoSided?: boolean;
}): number;
/**
 * Minimum detectable paired effect (standardised units) for a target paired
 * sample size: d_min = (z_{1-α/2} + z_β) / sqrt(n_paired). Multiply by
 * sd(deltas) for score units; treat as a lower bound — Wilcoxon and bootstrap
 * have asymptotic relative efficiency below 1 vs the t-test on heavy tails.
 */
export declare function pairedMde(opts: {
    nPaired: number;
    alpha?: number;
    power?: number;
    twoSided?: boolean;
}): number;
/**
 * Number of paired observations needed for a McNemar test to reach a target
 * power — the pre-registration companion to {@link mcnemar}. Parametrised by the
 * expected discordant-cell probabilities `p10` (P[treatment wins on a pair]) and
 * `p01` (P[control wins]); concordant pairs carry no information, so the count
 * is driven entirely by the discordant rate. Lachin's (1992) asymptotic normal
 * approximation: with discordant rate `pDisc = p10 + p01` and marginal effect
 * `δ = p10 − p01`,
 *   n = ( z_{1-α/2}·√pDisc + z_{1-β}·√(pDisc − δ²) )² / δ².
 * Returns Infinity when there is no effect (p10 === p01). Asymptotic — at the
 * tiny discordant counts where the exact {@link mcnemar} differs from the normal
 * approximation, treat the result as a lower bound and prefer the discordant-pair
 * floor.
 */
export declare function mcnemarRequiredN(opts: {
    p10: number;
    p01: number;
    alpha?: number;
    power?: number;
    twoSided?: boolean;
}): number;
/**
 * Power of a McNemar test at a given number of paired observations, the inverse
 * of {@link mcnemarRequiredN} (same Lachin asymptotic model, same parameters).
 * Returns a value in [0, 1]; equals `alpha` when there is no effect.
 */
export declare function mcnemarPower(opts: {
    p10: number;
    p01: number;
    nPairs: number;
    alpha?: number;
    twoSided?: boolean;
}): number;
/** Bonferroni adjustment: multiply every p-value by the test count, clamp at 1. */
export declare function bonferroni(pValues: number[], alpha?: number): {
    adjusted: number[];
    significant: boolean[];
};
/**
 * Benjamini–Hochberg false discovery rate. Returns adjusted q-values and
 * significance at the target FDR; handles ties and preserves q monotonicity.
 */
export declare function benjaminiHochberg(pValues: number[], fdr?: number): {
    qValues: number[];
    significant: boolean[];
};
export interface PairedBootstrapResult {
    /** Number of paired observations. */
    n: number;
    /** Median of paired deltas (after − before). */
    median: number;
    /** Mean of paired deltas. */
    mean: number;
    /** Lower bound of the bootstrap CI on the chosen statistic. */
    low: number;
    /** Upper bound of the bootstrap CI on the chosen statistic. */
    high: number;
    /** Confidence level used (e.g. 0.95). */
    confidence: number;
    /** Number of bootstrap resamples used. */
    resamples: number;
}
export interface PairedBootstrapOptions {
    /** Confidence level. Default 0.95. */
    confidence?: number;
    /** Bootstrap resample count. Default 2000. */
    resamples?: number;
    /** Statistic to bootstrap. Default 'median'. */
    statistic?: 'median' | 'mean';
    /** Deterministic seed. If omitted, uses Math.random(). */
    seed?: number;
}
/**
 * Paired bootstrap on (after − before) deltas. Returns a CI on the chosen
 * statistic (median by default); pairs are resampled with replacement. The
 * lower bound is what the promotion gate checks — `low > threshold` means the
 * gain is real at the confidence level. Throws on unequal sample sizes.
 */
export declare function pairedBootstrap(before: number[], after: number[], opts?: PairedBootstrapOptions): PairedBootstrapResult;
/** A binomial proportion estimate with a confidence interval. */
export interface ProportionInterval {
    /** Point estimate successes / n (0 when n = 0). */
    estimate: number;
    /** Lower bound, clamped to [0, 1]. */
    lower: number;
    /** Upper bound, clamped to [0, 1]. */
    upper: number;
}
/**
 * Wilson score interval for a binomial proportion. Correct at small n and near
 * 0/1, where the normal (Wald) approximation produces bounds outside [0, 1] and
 * understates coverage. Use this for any pass-rate / hit-rate / realness-rate
 * CI — the continuous `confidenceInterval` assumes the wrong distribution for a
 * proportion. `n = 0 ⇒ {0, 0, 0}`.
 */
export declare function wilson(successes: number, n: number, confidence?: number): ProportionInterval;
/** Result of a McNemar paired-binary significance test. */
export interface McNemarResult {
    /** Total paired observations. */
    n: number;
    /** Discordant pairs (b + c) — the only ones that carry signal. */
    nDiscordant: number;
    /** Pairs where treatment succeeded and control failed ("newly correct"). */
    b: number;
    /** Pairs where control succeeded and treatment failed ("newly wrong"). */
    c: number;
    /** Continuity-corrected chi-square statistic (reference; exact p drives the call). */
    statistic: number;
    /** Two-sided p-value. Exact (binomial sign test on discordant pairs). */
    pValue: number;
}
/**
 * McNemar's test for paired binary outcomes — the correct significance test for
 * "does treatment change the success rate vs control on the SAME items". Only
 * discordant pairs (one arm right, the other wrong) carry information; concordant
 * pairs are uninformative, so a paired t-test / two-proportion z-test on the raw
 * rates is wrong here. The p-value is exact: under H0 the b "treatment-wins" are
 * Binomial(b + c, 0.5), so the two-sided p is the doubled binomial tail — correct
 * at the small discordant counts typical of eval runs (no continuity-corrected
 * chi-square approximation needed, though it is returned as `statistic` for
 * reference). Inputs are paired 0/1 (or boolean) arrays, control first to match
 * the module's (before, after) convention. Throws on unequal lengths.
 */
export declare function mcnemar(control: ArrayLike<number | boolean>, treatment: ArrayLike<number | boolean>): McNemarResult;
/** A paired binary effect size (treatment rate − control rate) with a CI. */
export interface RiskDifferenceResult {
    /** Total paired observations. */
    n: number;
    /** Discordant pairs: treatment-win count. */
    b: number;
    /** Discordant pairs: control-win count. */
    c: number;
    /** Paired risk difference p(treatment) − p(control) = (b − c) / n. */
    riskDifference: number;
    /** Lower bound of the CI, clamped to [-1, 1]. */
    lower: number;
    /** Upper bound of the CI, clamped to [-1, 1]. */
    upper: number;
    /** Confidence level used. */
    confidence: number;
}
/**
 * Paired risk difference (the effect-size companion to {@link mcnemar}): the
 * change in success rate p(treatment) − p(control) on matched items, which for
 * paired binary data equals (b − c) / n. The CI uses the paired variance from
 * the discordant counts, not the independent-samples formula (which overstates
 * the interval by ignoring the pairing). Inputs are paired 0/1 (or boolean)
 * arrays, control first. Throws on unequal lengths.
 */
export declare function pairedRiskDifference(control: ArrayLike<number | boolean>, treatment: ArrayLike<number | boolean>, confidence?: number): RiskDifferenceResult;
/**
 * Unbiased pass@k for code generation (Chen et al. 2021, "Evaluating Large
 * Language Models Trained on Code"). Given `n` independent samples for one
 * problem of which `c` pass, the probability that at least one of a random k of
 * them passes is 1 − C(n−c, k) / C(n, k). Estimating pass@k as "did any of the
 * first k pass" is biased high at small n; this is the variance-reduced estimator
 * averaged implicitly over all k-subsets. Average the per-problem values across
 * the suite for the corpus pass@k. Computed in the numerically stable product
 * form. Requires 1 ≤ k ≤ n and 0 ≤ c ≤ n.
 */
export declare function passAtK(n: number, c: number, k: number): number;
export interface EProcessOptions {
    /** Type-I error budget. The process decides when wealth ≥ 1/alpha
     *  (Ville's inequality). Default 0.05. */
    alpha?: number;
    /** Truncation bound on the predictable bet λ ∈ [0, maxBet]. Must satisfy
     *  maxBet < 1/nullMean so every wealth factor stays strictly positive.
     *  Default 0.5. */
    maxBet?: number;
    /** The null boundary m₀ for H0: E[x] ≤ m₀ on x ∈ [0,1]. Default 0.5
     *  (the paired-delta encoding x = (d+1)/2 maps "no effect" to 1/2).
     *  A pre-registered minEffect shifts this — see `sequentialPairedGate`. */
    nullMean?: number;
}
export interface EProcessStep {
    /** Current wealth W_n — the e-value against H0 after n observations. */
    wealth: number;
    /** Observations consumed so far. */
    n: number;
    /** True from the first n where W_n ≥ 1/alpha onward (sticky). */
    decided: boolean;
}
export interface EProcessState extends EProcessStep {
    alpha: number;
    maxBet: number;
    nullMean: number;
    /** The decision boundary 1/alpha. */
    threshold: number;
    /** Observation count at the first threshold crossing; undefined until decided. */
    decidedAtN?: number;
}
export interface EProcess {
    /** Consume one observation x ∈ [0,1]. Throws on non-finite / out-of-range
     *  input — a silent clamp would corrupt the type-I guarantee. */
    update(x: number): EProcessStep;
    state(): EProcessState;
}
/**
 * Betting test-martingale for bounded observations — the e-process core of
 * anytime-valid sequential testing (Waudby-Smith & Ramdas, "Estimating means
 * of bounded random variables by betting", JRSS-B 2024).
 *
 * Observations x_i ∈ [0,1]; H0: E[x] ≤ m₀ (`nullMean`, default 1/2). Wealth
 *
 *   W_t = Π_{i≤t} (1 + λ_i (x_i − m₀)),  W_0 = 1
 *
 * with the truncated GROW-style plug-in bet computed from PRIOR observations:
 *
 *   λ_i = clamp((μ̂_{i−1} − m₀) / (σ̂²_{i−1} + (μ̂_{i−1} − m₀)²), 0, maxBet)
 *
 * where μ̂/σ̂² are the shrunk running estimates μ̂_t = (1/2 + Σx_i)/(t+1),
 * σ̂²_t = (1/4 + Σ(x_i − μ̂_i)²)/(t+1).
 *
 * PREDICTABILITY INVARIANT (load-bearing): λ_i is a function of x_1..x_{i−1}
 * ONLY — it may never see x_i. With λ_i ≥ 0 predictable, each factor has
 * E[1 + λ_i(x_i − m₀) | past] ≤ 1 under H0, so W is a nonnegative
 * supermartingale and Ville's inequality gives P(∃t: W_t ≥ 1/α) ≤ α — the
 * type-I guarantee holds at ANY data-dependent stopping time. λ_1 is always 0
 * (no prior evidence), so the first observation never moves wealth.
 *
 * `decided` latches at the first crossing W_t ≥ 1/α and never un-latches;
 * wealth keeps updating after the crossing (the e-process remains valid), but
 * the decision time is the first crossing.
 */
export declare function eProcess(opts?: EProcessOptions): EProcess;
/** Tiny seedable PRNG (mulberry32) — deterministic resampling/shuffling, not
 *  cryptographic. Exported so e-process shuffles and bootstrap resampling
 *  share ONE PRNG implementation; a seed is REQUIRED (unseeded randomness in
 *  gate verdicts is non-reproducible by construction). */
export declare function mulberry32(seed: number): () => number;
//# sourceMappingURL=statistics.d.ts.map