Diagnostic tests as residual analysis