Diagnostic Functions

January 29, 2026 · View on GitHub

Model diagnostics and evaluation functions for regression analysis.

Variance Inflation Factor (VIF)

vif / anofox_stats_vif

Compute Variance Inflation Factor for multicollinearity detection.

Signature:

vif(x LIST(LIST(DOUBLE))) -> LIST(DOUBLE)

Interpretation:

VIFInterpretation
VIF = 1No correlation
VIF 1-5Moderate correlation
VIF > 5High correlation (warning)
VIF > 10Very high correlation (problematic)

Example:

SELECT vif([[x1_vals], [x2_vals], [x3_vals]]) as vif_values;

vif_agg / anofox_stats_vif_agg

Streaming VIF aggregate function.

SELECT vif_agg([x1, x2, x3]) FROM data;

Model Selection Criteria

aic / anofox_stats_aic

Compute Akaike Information Criterion. Lower is better.

Signature:

aic(rss DOUBLE, n BIGINT, k BIGINT) -> DOUBLE

Parameters:

ParameterTypeDescription
rssDOUBLEResidual Sum of Squares
nBIGINTNumber of observations
kBIGINTNumber of parameters (including intercept)

Example:

SELECT aic(100.0, 50, 3) as aic_value;

Formula: AIC = n × ln(RSS/n) + 2k

bic / anofox_stats_bic

Compute Bayesian Information Criterion. Lower is better. Penalizes complexity more than AIC.

Signature:

bic(rss DOUBLE, n BIGINT, k BIGINT) -> DOUBLE

Example:

SELECT bic(100.0, 50, 3) as bic_value;

Formula: BIC = n × ln(RSS/n) + k × ln(n)

Choosing Between AIC and BIC

CriterionBest for
AICPrediction, when true model may not be in candidate set
BICModel identification, converges to true model as n→∞

Normality Tests

jarque_bera / anofox_stats_jarque_bera

Jarque-Bera test for normality of residuals.

Signature:

jarque_bera(data LIST(DOUBLE)) -> STRUCT

Returns:

STRUCT(
    statistic DOUBLE,
    p_value DOUBLE,
    skewness DOUBLE,
    kurtosis DOUBLE,
    n BIGINT
)

Example:

SELECT jarque_bera(residuals).p_value as normality_pvalue;

jarque_bera_agg / anofox_stats_jarque_bera_agg

Streaming Jarque-Bera aggregate function.

SELECT jarque_bera_agg(residual) FROM fitted_data;

Residual Analysis

residuals_diagnostics / anofox_stats_residuals_diagnostics

Compute comprehensive residual diagnostics.

Signature:

residuals_diagnostics(
    y LIST(DOUBLE),
    y_hat LIST(DOUBLE),
    [x LIST(LIST(DOUBLE))],
    [residual_std_error DOUBLE],
    [include_studentized BOOLEAN]
) -> STRUCT

Returns:

STRUCT(
    raw LIST(DOUBLE),           -- Raw residuals (y - ŷ)
    standardized LIST(DOUBLE),  -- Standardized residuals
    studentized LIST(DOUBLE),   -- Studentized residuals
    leverage LIST(DOUBLE)       -- Leverage values (hat matrix diagonal)
)

Example:

SELECT residuals_diagnostics(
    actual_values,
    predicted_values
) as diagnostics;

residuals_diagnostics_agg / anofox_stats_residuals_diagnostics_agg

Streaming residuals diagnostics aggregate function.

SELECT residuals_diagnostics_agg(y, y_hat, [x]) FROM data;

Residual Types

TypeFormulaUse
Rawe = y - ŷBasic residuals
Standardizede / σScale-free comparison
Studentizede / (σ × √(1-h))Account for leverage

Detecting Problems

High Leverage Points

  • Leverage > 2(k+1)/n suggests influential point
  • Check studentized residuals for these points

Outliers

  • |Studentized residual| > 3 suggests outlier
  • Use Jarque-Bera to test overall normality

Multicollinearity

  • VIF > 5 indicates moderate collinearity
  • VIF > 10 indicates severe collinearity
  • Consider Ridge regression or variable selection

See Also