View source: R/get_LOF_by_class.R
get_LOF_by_class | R Documentation |
Calculate lack_of_fit (LOF) for spectroscopic data by class
get_LOF_by_class(obj, by, FUN = median)
obj |
- hyperSpec object. |
by |
- string with name of factor variable in 'obj'. |
FUN |
- function used to calculate expected values. |
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.
Other LOF_obj:
plot_LOF_MDS()
,
plot_LOF_hist()
,
plot_LOF_sp()
,
plot_stacked()
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))
# })
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.