Outlier detection with interquartile range (IQR) based distances, defined as: lower limit \(Q1 - k * IQR\) and upper limit \(Q3 + k * IQR\). Here Q1 and Q3 is the first and the third quantile respectively. 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).

IQR_outliers(x, k_out = 3, k_inn = 1.5)

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 3.

k_inn

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

Value

A list with these variables

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

  • 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

Read about boxplots and outliers (Box Plot: Display of Distribution)

Other spHelper utilities: expr2text(), mad_outliers(), rmExpr(), sd_outliers(), subt(), unGroup(), uncall()

Other spHelper functions for spectroscopy and hyperSpec: binning(), file, gapDer(), hy2mat(), hyAdd_Label_wl(), hyAdd_Labels_PAP_PD_2014(), hyAdd_Labels_TD2009(), hyAdd(), hyDrop_NA(), hyGet_palette(), hyRm_palette(), mad_outliers(), mean_Nsd(), median_Nmad(), plot_hyPalette(), prepare_PAP_RK_2014__MATLAB_failui(), read.OOIBase32(), read.OceanView.header(), read.OceanView(), read.sp.csv2(), read3csv2hy(), replace_spc(), sd_outliers(), spStat(), sp_class_perform()

Other outlier detection functions in spHelper: mad_outliers(), sd_outliers()

Author

Vilmantas Gegzna

Examples


outl <- IQR_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("IQR based distances")
#> Error in title("IQR based distances"): plot.new has not been called yet