smooth.AutoADAM.outlierdummy

AutoADAM.outlierdummy(level=0.999, type='rstandard')

Detect outliers and return a matrix of indicator dummy variables.

Computes standardised residuals (via rstandard() or rstudent()), then derives two-sided quantile bounds [q_lo, q_hi] for the fitted distribution at the given confidence level. Observations whose standardised residual falls outside these bounds are labelled outliers.

The quantile bounds are distribution-specific:

  • dnorm / dlnorm (log-space): scipy.stats.norm.ppf

  • dlaplace: scipy.stats.laplace.ppf

  • ds: scipy.stats.gennorm.ppf(..., beta=0.5)

  • dgnorm: scipy.stats.gennorm.ppf(..., beta=shape)

  • dgamma: scipy.stats.gamma.ppf(..., a=1/σ, scale=σ)

  • dinvgauss: scipy.stats.invgauss.ppf with df-corrected dispersion

Mirrors R’s outlierdummy.adam() from the greybox package.

Parameters:
  • level (float, default 0.999) – Two-sided confidence level for outlier detection. 0.99 flags observations in the outer 1 % of the distribution.

  • type ({"rstandard", "rstudent"}, default "rstandard") – Which standardised residuals to use. "rstudent" is more sensitive to individual outliers in small samples.

Returns:

Dataclass with fields:

outliersndarray of shape (n, m) or None

Binary dummy matrix, one column per detected outlier. None when no outliers are found.

idndarray of int

0-based indices of outlier observations.

statisticndarray of shape (2,)

[lower, upper] quantile bounds used for detection.

levelfloat

The confidence level used.

typestr

The residual type used ("rstandard" or "rstudent").

Return type:

OutlierDummy

Raises:
  • ValueError – If type is not "rstandard" or "rstudent".

  • ValueError – If the model has not been fitted yet.

See also

rstandard

Standardised residuals.

rstudent

Studentised residuals.

Examples

>>> model = ADAM(model="AAN")
>>> model.fit(y)
>>> od = model.outlierdummy(level=0.99)
>>> od.id          # 0-based indices of detected outliers
>>> od.statistic   # [lower, upper] bounds, e.g. [-2.576, 2.576]
>>> if od.outliers is not None:
...     # Refit with outlier dummies as exogenous regressors
...     model2 = ADAM(model="AAN")
...     model2.fit(y, X=od.outliers)

Parent Class: AutoADAM