mad_outliers: Outlier detection with MAD based distances (limits)

View source: R/mad_outliers.R

mad_outliersR Documentation

Outlier detection with MAD based distances (limits)

Description

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

Usage

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.

Author(s)

Vilmantas Gegzna

See Also

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

Other spHelper functions for spectroscopy and hyperSpec: IQR_outliers(), binning(), file, gapDer(), hy2mat(), hyAdd_Label_wl(), hyAdd_Labels_PAP_PD_2014(), hyAdd_Labels_TD2009(), hyAdd(), hyDrop_NA(), hyGet_palette(), hyRm_palette(), 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: IQR_outliers(), sd_outliers()

Examples


outl <- mad_outliers(Spectra2)

plot(outl$outer, col = NA)
plot(Spectra2, add = TRUE, spc.nmax = nrow(Spectra2))
plot(outl$outer, add = TRUE, col = "red",    lines.args = list(lwd = 3))
plot(outl$inner,  add = TRUE, col = "orange", lines.args = list(lwd = 3))
legend("topright",legend=c("Outer limit", "Inner limit", "Spectra"),
     col = c("red", "orange", "black"), lwd = c(3,3,1), lty = 1)
title("MAD based distances")


GegznaV/spHelper documentation built on April 16, 2023, 1:42 p.m.