Outlier detection with median absolute deviation (MAD) based distances, defined as: lower limit \(median - k * MAD\) and upper limit \(median + k * MAD\). Inner lower/upper limit for probable outlier detection has k = k_inn and outer lower/upper limit for (extreme) outlier detection has k = k_out, (k_out > k_inn).

mad_outliers(x, k_out = 4, k_inn = 3)

Arguments

x

Matrix-like data or hyperSpec object.

k_out

Number of IQR distances from Q1 and Q3 for extreme outlier identification. Default value is 4.

k_inn

Number of IQR diustances from Q1 and Q3 for probable outlier idientification. Default value is 3.

Value

A list with these variables

  • outer / inner - matrices with values of outer / inner limits

  • Logical matrices indicating TRUE for points that are:

    • is_out - (extreme) outliers (excluding probable outliers);

    • is_pout - probable outliers (excluding extreme outliers);

    • is_bothOut - either probable or extreme outliers;

  • Logical vectors indicating spectra / rows with at least one:

    • row_out - (extreme) outlier point;

    • row_pout - probable outlier point (excluding extreme outliers);

    • row_bothOut - either probable or extreme outlier point.

If x is a hyperSpec object, then the listed variables are returned as hyperSpec objects.

Note that probable outliers are points between corresponding lower as well as corresponding upper inner and outer limits. Extreme outliers are points outside lower and upper outer limits.

See also

Author

Vilmantas Gegzna

Examples


outl <- mad_outliers(Spectra2)
#> Warning: Function 'chk.hy' is deprecated. 
#> Use function 'assert_hyperSpec' instead.
#> Error in .expand(e1, dim(e2)[c(1, 3)]): Dimension mismatch.

plot(outl$outer, col = NA)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'outl' not found
plot(Spectra2, add = TRUE, spc.nmax = nrow(Spectra2))
#> Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...): plot.new has not been called yet
plot(outl$outer, add = TRUE, col = "red",    lines.args = list(lwd = 3))
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'outl' not found
plot(outl$inner,  add = TRUE, col = "orange", lines.args = list(lwd = 3))
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'outl' not found
legend("topright",legend=c("Outer limit", "Inner limit", "Spectra"),
     col = c("red", "orange", "black"), lwd = c(3,3,1), lty = 1)
#> Error in (function (s, units = "user", cex = NULL, font = NULL, vfont = NULL,     ...) {    if (!is.null(vfont))         vfont <- c(typeface = pmatch(vfont[1L], Hershey$typeface),             fontindex = pmatch(vfont[2L], Hershey$fontindex))    .External.graphics(C_strWidth, as.graphicsAnnot(s), pmatch(units,         c("user", "figure", "inches")), cex, font, vfont, ...)})(dots[[1L]][[1L]], cex = dots[[2L]][[1L]], font = dots[[3L]][[1L]],     units = "user"): plot.new has not been called yet
title("MAD based distances")
#> Error in title("MAD based distances"): plot.new has not been called yet