/** * Statistical analysis utilities. * Pure functions with zero dependencies - can be used standalone for any data analysis. * * @module */ /** * Calculate the mean (average) of an array of numbers. */ export declare const stats_mean: (values: Array) => number; /** * Calculate the median of an array of numbers. * NaN values are filtered out before computing. */ export declare const stats_median: (values: Array) => number; /** * Calculate the standard deviation of an array of numbers. * Uses population standard deviation (divides by n, not n-1). * For benchmarks with many samples, this is typically appropriate. */ export declare const stats_std_dev: (values: Array, mean?: number) => number; /** * Calculate the variance of an array of numbers. */ export declare const stats_variance: (values: Array, mean?: number) => number; /** * Calculate a percentile of an array of numbers using linear interpolation. * Uses the "R-7" method (default in R, NumPy, Excel) which interpolates between * data points for more accurate percentile estimates, especially with smaller samples. * @param p - percentile (0-1, e.g., 0.95 for 95th percentile) */ export declare const stats_percentile: (values: Array, p: number) => number; /** * Calculate the coefficient of variation (CV). * CV = standard deviation / mean, expressed as a ratio. * Useful for comparing relative variability between datasets. */ export declare const stats_cv: (mean: number, std_dev: number) => number; /** * Calculate min and max values. * NaN values are ignored. */ export declare const stats_min_max: (values: Array) => { min: number; max: number; }; /** * Result from outlier detection. */ export interface StatsOutlierResult { /** Values after removing outliers */ cleaned: Array; /** Detected outlier values */ outliers: Array; } /** * Configuration options for IQR outlier detection. */ export interface StatsOutliersIqrOptions { /** Multiplier for IQR bounds (default: 1.5) */ iqr_multiplier?: number; /** Minimum sample size to perform outlier detection (default: 3) */ min_sample_size?: number; } /** * Detect outliers using the IQR (Interquartile Range) method. * Values outside [Q1 - multiplier*IQR, Q3 + multiplier*IQR] are considered outliers. */ export declare const stats_outliers_iqr: (values: Array, options?: StatsOutliersIqrOptions) => StatsOutlierResult; /** * Configuration options for MAD outlier detection. */ export interface StatsOutliersMadOptions { /** Modified Z-score threshold for outlier detection (default: 3.5) */ z_score_threshold?: number; /** Extreme Z-score threshold when too many outliers detected (default: 5.0) */ z_score_extreme?: number; /** MAD constant for normal distribution (default: 0.6745) */ mad_constant?: number; /** Ratio threshold to switch to extreme mode (default: 0.3) */ outlier_ratio_high?: number; /** Ratio threshold to switch to keep-closest mode (default: 0.4) */ outlier_ratio_extreme?: number; /** Ratio of values to keep in keep-closest mode (default: 0.8) */ outlier_keep_ratio?: number; /** Minimum sample size to perform outlier detection (default: 3) */ min_sample_size?: number; /** Options to pass to IQR fallback when MAD is zero */ iqr_options?: StatsOutliersIqrOptions; } /** * Detect outliers using the MAD (Median Absolute Deviation) method. * More robust than IQR for skewed distributions. * Uses modified Z-score: |0.6745 * (x - median) / MAD| * Values with modified Z-score > threshold are considered outliers. */ export declare const stats_outliers_mad: (values: Array, options?: StatsOutliersMadOptions) => StatsOutlierResult; /** * Common z-scores for confidence intervals. */ export declare const STATS_CONFIDENCE_Z_SCORES: Record; /** * Convert a confidence level (0-1) to a z-score. * Uses a lookup table for common values, approximates others. * * @throws Error if `level` is not in the open interval (0, 1) * * @example * ```ts * stats_confidence_level_to_z_score(0.95); // 1.96 * stats_confidence_level_to_z_score(0.99); // 2.576 * ``` */ export declare const stats_confidence_level_to_z_score: (level: number) => number; /** * Configuration options for confidence interval calculation. */ export interface StatsConfidenceIntervalOptions { /** Z-score for confidence level (default: 1.96 for 95% CI) */ z_score?: number; /** Confidence level (0-1), alternative to z_score. If both provided, z_score takes precedence. */ confidence_level?: number; } /** * Calculate confidence interval for the mean. * @returns `[lower_bound, upper_bound]` */ export declare const stats_confidence_interval: (values: Array, options?: StatsConfidenceIntervalOptions) => [number, number]; /** * Calculate confidence interval from summary statistics (mean, std_dev, sample_size). * Useful when raw data is not available. * @returns `[lower_bound, upper_bound]` */ export declare const stats_confidence_interval_from_summary: (mean: number, std_dev: number, sample_size: number, options?: StatsConfidenceIntervalOptions) => [number, number]; /** * Result from Welch's t-test calculation. */ export interface StatsWelchTTestResult { /** The t-statistic */ t_statistic: number; /** Welch-Satterthwaite degrees of freedom */ degrees_of_freedom: number; } /** * Calculate Welch's t-test statistic and degrees of freedom. * Welch's t-test is more robust than Student's t-test when variances are unequal. * * Params suffixed `1` describe the first sample, `2` the second. */ export declare const stats_welch_t_test: (mean1: number, std1: number, n1: number, mean2: number, std2: number, n2: number) => StatsWelchTTestResult; /** * Standard normal CDF approximation (Abramowitz and Stegun formula 7.1.26). */ export declare const stats_normal_cdf: (x: number) => number; /** * Log gamma function approximation (Lanczos approximation). */ export declare const stats_ln_gamma: (z: number) => number; /** * Approximate regularized incomplete beta function for p-value calculation. * Uses continued fraction expansion for reasonable accuracy. */ export declare const stats_incomplete_beta: (x: number, a: number, b: number) => number; /** * Approximate two-tailed p-value from t-distribution. * For large df (>100), uses normal approximation. * For smaller df, uses incomplete beta function. * * @param t - absolute value of t-statistic * @param df - degrees of freedom * @returns two-tailed p-value */ export declare const stats_t_distribution_p_value: (t: number, df: number) => number; //# sourceMappingURL=stats.d.ts.map