/** * Standard normal CDF Φ(z) using Abramowitz & Stegun 7.1.26 (max error 1.5e-7). * Symmetric: `normalCdf(-z) === 1 - normalCdf(z)`. */ declare function normalCdf(z: number): number; /** * Inverse standard normal CDF (quantile). Beasley-Springer-Moro algorithm. * Accurate to ~1e-9 over the full open interval. */ declare function normalInv(p: number): number; /** * Student's t-distribution CDF. Two-tailed via symmetry. * Uses the regularized incomplete beta function for arbitrary df > 0. * * P(T ≤ t) = 1 - 0.5 * I_x(df/2, 1/2) where x = df / (df + t²) for t ≥ 0 * P(T ≤ t) = 0.5 * I_x(df/2, 1/2) where x = df / (df + t²) for t < 0 */ declare function studentTCdf(t: number, df: number): number; /** * Inverse Student's t (quantile). Bisection on `studentTCdf` — adequate for * SDK use; not the fastest possible. */ declare function studentTInv(p: number, df: number): number; interface ProportionTestInput { controlConversions: number; controlTotal: number; treatmentConversions: number; treatmentTotal: number; /** Significance level (default 0.05). */ alpha?: number; /** Alternative hypothesis (default "two-sided"). */ alternative?: "two-sided" | "greater" | "less"; } interface ProportionTestResult { controlRate: number; treatmentRate: number; /** Absolute lift = treatmentRate - controlRate. */ lift: number; /** Relative lift = (treatment - control) / control. NaN when control is 0. */ liftRelative: number; zStatistic: number; pValue: number; /** Two-sided CI for the absolute lift at level 1-α. */ confidenceInterval: { lower: number; upper: number; }; significant: boolean; /** Post-hoc power: P(reject H0 | observed effect is true). */ power: number; } /** * Two-proportion z-test for the difference between conversion rates. Uses the * pooled-variance estimator for the test statistic and unpooled variance for * the confidence interval (Newcombe 1998 recommends this combination). */ declare function twoProportionTest(input: ProportionTestInput): ProportionTestResult; interface WelchTTestInput { control: { mean: number; variance: number; n: number; }; treatment: { mean: number; variance: number; n: number; }; alpha?: number; alternative?: "two-sided" | "greater" | "less"; } interface WelchTTestResult { meanDiff: number; tStatistic: number; degreesOfFreedom: number; pValue: number; confidenceInterval: { lower: number; upper: number; }; significant: boolean; } /** * Welch's two-sample t-test — does NOT assume equal variances. Use for * comparing means of any continuous metric (revenue, latency, time-on-page). * * Variance must be the *sample* variance (Σ(x - x̄)² / (n - 1)). */ declare function welchTTest(input: WelchTTestInput): WelchTTestResult; /** * Wilson score interval for a binomial proportion. More accurate than the * Wald interval, especially for small n or extreme p̂. Always within [0, 1]. */ declare function wilsonInterval(successes: number, total: number, alpha?: number): { lower: number; upper: number; midpoint: number; }; /** Normal-approximation CI for a quantity with known SE. */ declare function normalInterval(estimate: number, stdError: number, alpha?: number): { lower: number; upper: number; }; interface ProportionSampleSizeInput { baselineRate: number; /** Minimum effect we want to detect. */ minimumDetectableEffect: number; /** Whether MDE is absolute (e.g. 0.02) or relative to baseline (e.g. 0.05). */ effectType?: "absolute" | "relative"; alpha?: number; power?: number; alternative?: "two-sided" | "one-sided"; } /** * Required sample size per group for a two-proportion test at the given * power and significance level. * * n_per_group = (z_{α/2} + z_β)² * (p_C(1-p_C) + p_T(1-p_T)) / (p_T - p_C)² */ declare function sampleSizeForProportion(input: ProportionSampleSizeInput): { perGroup: number; total: number; }; interface MeanSampleSizeInput { /** Expected baseline mean (informational, not used in formula). */ baselineMean?: number; /** Population (or pooled) standard deviation. */ stdDev: number; /** Minimum detectable mean difference (treatment - control). */ minimumDetectableEffect: number; alpha?: number; power?: number; alternative?: "two-sided" | "one-sided"; } /** * Required sample size per group for a two-sample t-test on continuous means. * * n_per_group = 2 * σ² * (z_{α/2} + z_β)² / δ² * * Uses the normal approximation for the critical value — refine with the t * inverse for very small samples if you need stricter calibration. */ declare function sampleSizeForMean(input: MeanSampleSizeInput): { perGroup: number; total: number; }; interface CUPEDObservation { /** Pre-experiment covariate (e.g. user's metric value during pre-period). */ x: number; /** Experiment metric value. */ y: number; } interface CUPEDResult { /** Optimal coefficient: Cov(X, Y) / Var(X). */ theta: number; /** Adjusted Y values: Y - θ * (X - mean(X)). */ adjustedValues: number[]; /** Variance reduction proportion: 1 - Var(Y_adj) / Var(Y). */ varianceReduction: number; adjustedMean: number; adjustedVariance: number; originalMean: number; originalVariance: number; } /** * Apply CUPED variance reduction. Returns adjusted metric values whose mean * estimates the same population mean as Y but with reduced variance — * shrinking required sample size proportionally. * * The covariate X must be measured BEFORE the experiment (so it can't be * affected by treatment assignment). */ declare function applyCUPED(observations: CUPEDObservation[]): CUPEDResult; interface MSPRTState { /** Cumulative log-likelihood ratio under H1 vs H0. */ cumLogLR: number; /** Observations accumulated. */ n: number; /** Mixing variance τ² of the prior on the effect size. */ tau2: number; /** Assumed noise variance per observation (σ² in the formulae). */ sigma2: number; /** Running sum of (treatment - control) per observation. */ sumDiff: number; } interface MSPRTUpdateInput { /** Per-observation difference (treatment_i - control_i). */ diff: number; } /** * Create an initial mSPRT state. Pick `tau2` to encode the *expected* scale * of the true effect (e.g. tau = MDE / 3 puts ~99% mass within ±MDE). Pick * `sigma2` from your population's per-observation variance. */ declare function createMSPRTState(opts: { tau2: number; sigma2: number; }): MSPRTState; /** * Add one observation to the mSPRT state. The `diff` is treatment_i - * control_i for paired data, or x_i - μ_0 for one-sample tests. * * Recomputes the cumulative log-LR using the mixture-Gaussian prior. */ declare function updateMSPRT(state: MSPRTState, input: MSPRTUpdateInput): MSPRTState; /** * Always-valid p-value derived from the mSPRT log-LR. Bounded by 1. * Reject H0 (no effect) when this drops below α — and unlike a fixed-horizon * z-test, this controls Type I error under arbitrary stopping rules. */ declare function mSPRTPValue(state: MSPRTState): number; interface BanditArmStats { arm: string; successes: number; failures: number; } interface BanditScoredArm { arm: string; score: number; } /** * Thompson sampling for a Beta-Bernoulli bandit. Returns one posterior sample * per arm — the highest score is the recommended action. With default * Beta(1, 1) priors the first pull is uniform random. */ declare function thompsonSample(arms: BanditArmStats[], opts?: { prior?: { alpha: number; beta: number; }; rng?: () => number; }): BanditScoredArm[]; /** * Pick the highest-scoring arm. Convenience wrapper around `thompsonSample`. */ declare function pickArmThompson(arms: BanditArmStats[], opts?: { prior?: { alpha: number; beta: number; }; rng?: () => number; }): string; interface UCBArmStats { arm: string; mean: number; pulls: number; } /** * UCB1 (Auer 2002). Returns a score per arm; pick the highest. * score_i = μ̂_i + √(2 * ln(N) / n_i) * * Unpulled arms (n_i = 0) receive +Infinity so they're always tried first. */ declare function ucb1(arms: UCBArmStats[], totalPulls?: number): BanditScoredArm[]; /** * ε-greedy: with probability ε pull a uniformly random arm; otherwise pull * the empirical leader. Simple, surprisingly effective. */ declare function epsilonGreedy(arms: Array<{ arm: string; mean: number; }>, epsilon: number, rng?: () => number): string; export { type BanditArmStats, type BanditScoredArm, type CUPEDObservation, type CUPEDResult, type MSPRTState, type MSPRTUpdateInput, type MeanSampleSizeInput, type ProportionSampleSizeInput, type ProportionTestInput, type ProportionTestResult, type UCBArmStats, type WelchTTestInput, type WelchTTestResult, applyCUPED, createMSPRTState, epsilonGreedy, mSPRTPValue, normalCdf, normalInterval, normalInv, pickArmThompson, sampleSizeForMean, sampleSizeForProportion, studentTCdf, studentTInv, thompsonSample, twoProportionTest, ucb1, updateMSPRT, welchTTest, wilsonInterval };