eempf_residuals_metrics: Calculate residual metrics from a PARAFAC model

eempf_residuals_metricsR Documentation

Calculate residual metrics from a PARAFAC model

Description

The metrics calculated with this function are:

  • RSS: residual sum of squares

  • MAE: mean absolute error

  • SAE: sum of absolute errors

  • RSAE: sum of absolute error in relation to the sum of fluorescence and

  • LEV: the leverage as described in eempf_leverage The example contains a way to plot these numbers.

Usage

eempf_residuals_metrics(residuals, leverage)

Arguments

residuals

data.frame as derived from eempf_residuals

leverage

list of data.frames as derived from eempf_leverage

Value

a list of data.frames containing residuals metrics for each sample, emission and excitation wavelength

Examples


data(eem_list)
data(pf_models)

residuals <- eempf_residuals(pf4[[1]], eem_list, cores = 2)
leverage <- eempf_leverage(pf4[[1]])

metrics <- eempf_residuals_metrics(residuals, leverage)

metrics$sample

## plot different residual metrics
require(dplyr)
require(tidyr)
require(ggplot2)

lapply(names(metrics), function(name){
  metrics[[name]] %>%
  mutate(mode = name, element = !!sym(name))
}) %>%
  bind_rows() %>%
  pivot_longer(cols = RSS:LEV, names_to = "metric", values_to = "value") %>%
  # uncomment the following line to select certain metrics
  # filter(metric %in% c("RSS","LEV")) %>%
  ggplot(aes(x = element, y = value, colour = metric))+
  geom_point()+
  facet_wrap(mode ~ ., ncol = 3, scales = "free")+
  theme(axis.text.x = element_text(angle = 90))+
  scale_y_continuous(trans="log")


staRdom documentation built on July 9, 2023, 5:57 p.m.