median_Nmad: [!] Find spectra that represent median +/- n median absolute...

View source: R/median_Nmad.R

median_NmadR Documentation

[!] Find spectra that represent median +/- n median absolute deviations (MAD)

Description

Function finds spectra that represent mean +/- n MADs and adds column .name.

Usage

median_Nmad(
  sp,
  n = 2,
  plus.minus = TRUE,
  var_fun = mad,
  center_fun = median,
  center_name = as.character(match.call()$center_fun),
  var_name = as.character(match.call()$var_fun)
)

Arguments

sp

hyperSpec object.

n

Number of MADs.

plus.minus

Logical. If TRUE, two spectra representing \u00B1 n are calculated. Otherwise only one spectrum representing n is calculated.

var_fun

Function that calculates variability measure. Default is var_fun = mad.

center_fun

Function that calculates center tendency. Default is center_fun = median.

center_name

A string with the name for measure of center tendency (will be used to create a row name in .name).

var_name

A string with the name for measure of variability (will be used to create a row name in .name).

Value

A hyperSpec object with spectra at median(sp) \u00B1 n*MAD(sp).

Author(s)

Vilmantas Gegzna

See Also

scale, outside_mean_pm_Nsd, mean_sd

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(), mad_outliers(), mean_Nsd(), 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()

Examples


data(Spectra2)
Margins  <- median_Nmad(Spectra2)
Margins3 <- median_Nmad(Spectra2, n = 3)

plotspc(Margins)


# Plot data and margins =======================================

Marg2 <- as.long.df(Margins,  rownames = TRUE, na.rm = FALSE)
Marg3 <- as.long.df(Margins3, rownames = TRUE, na.rm = FALSE)

Spectra2$.name <- factor("Spectra")

qplotspc(Spectra2, spc.nmax = nrow(Spectra2),
         mapping = aes(x = .wavelength, y = spc, group = .rownames, color = .name),
         alpha = .25) + theme_light() +
    geom_line(data = Marg2, aes(color = .name), lwd = 1) +
    geom_line(data = Marg3, aes(color = .name), lwd = 1) +
    scale_color_manual(" ", values = c("darkgreen","blue", "red")) +
    scale_alpha_manual(" ", values = ".2", guide = FALSE)


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