get_LOF_by_class.Rd
Calculate lack_of_fit (LOF) for spectroscopic data by class
get_LOF_by_class(obj, by, FUN = median)
- hyperSpec object.
- string with name of factor variable in `obj`.
- 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")
#> Warning: Function 'chk.hy' is deprecated.
#> Use function 'assert_hyperSpec' instead.
str(obj0, max.level = 1)
#> List of 4
#> $ data :Formal class 'hyperSpec' [package "hyperSpec"] with 4 slots
#> $ centers :Formal class 'hyperSpec' [package "hyperSpec"] with 4 slots
#> $ differences:Formal class 'hyperSpec' [package "hyperSpec"] with 4 slots
#> $ LOF : num [1:150] 36.41 12.86 11.41 5.51 19.03 ...
#> - attr(*, "class")= chr [1:2] "LOF_obj" "list"
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 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))
# })
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~