quality_of_fit: [!] Calculate quality of fit parameters (for spectroscopic...

View source: R/quality_of_fit.R

quality_of_fitR Documentation

[!] Calculate quality of fit parameters (for spectroscopic data)

Description

Calculate LOF (lack-of-fit), GOF (goodness-of-fit) and RMSE (root of mean squared error) for original and reconstructed spectra.

Usage

quality_of_fit(obj = NULL, fit)

spFitEval(obj, fit)

Arguments

obj

The first set of (original) spectra. Either a matrix or a hyperSpec object.

fit

The second set of usually processed or reconstructed spectra, that will be compared to the first set. Either a matrix or a hyperSpec object.

Value

A dataframe with following parameters for each row in obj and fit:

  • $LOF - Lack of fit in percent (%):

    \frac{\sum{(obj - fit)^2}}{\sum{obj^2}} \cdot 100\%

  • $GOF - Goodness of fit in percent (%):

    100\% - LOF

  • $RMSE - Root of mean squared error:

    \sqrt{(obj - fit)^2}

Examples

obj <- Spectra2
fit <- reconstructSp(Loadings2, Scores2)

evaluation <- quality_of_fit(obj, fit)

head(evaluation)

par(mfrow = c(3,1))
 plot(density(evaluation$RMSE), main = "RMSE", col = 2)
 plot(density(evaluation$LOF), main = "Lack-of-fit")
 plot(density(evaluation$GOF), main = "Goodness-of-fit")
par(mfrow = c(1,1))

# Density plot of LOF by group:
DATA <- cbind(obj$.., evaluation)
qplot(LOF, data = DATA, fill = gr, color = gr,
 geom = "density", alpha = I(.2))

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