get_LOF_by_class: Calculate lack_of_fit (LOF) for spectroscopic data by class

View source: R/get_LOF_by_class.R

get_LOF_by_classR Documentation

Calculate lack_of_fit (LOF) for spectroscopic data by class

Description

Calculate lack_of_fit (LOF) for spectroscopic data by class

Usage

get_LOF_by_class(obj, by, FUN = median)

Arguments

obj

- hyperSpec object.

by

- string with name of factor variable in 'obj'.

FUN

- function used to calculate expected values.

Value

Function returns a list of 4 objects:
data - object 'obj';
centers - hyperSpec object in which variable $spc is matrix with expected values (means, medians, etc. indicated by 'FUN') for every row;
difference - hyperSpec object in which variable $spc is matrix with differences between observed and expected values;
LOF - vector of lack-of-fit values for every row.

See Also

Other LOF_obj: plot_LOF_MDS(), plot_LOF_hist(), plot_LOF_sp(), plot_stacked()

Examples

library(spHelper)
obj0 <- get_LOF_by_class(obj = Spectra2, by = "gr")
str(obj0, max.level = 1)

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Unit tests:
#
#  require(testthat)
# test_that("classes and their centers are sorted correctly",{
# require(hyperSpec)
# set.seed(1)
# obj <- hyperSpec::sample(Spectra2, 150)
#
# LOF_obj <- get_LOF_by_class(obj, "gr")
# N_unique <- (!duplicated(
#     LOF_obj$centers[,c("gr","spc")]  %>%
#    as.wide.df)) %>%  sum
# expect_equal(N_unique, nlevels(obj$gr))
#  })
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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