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

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)
#> Error in switch(class(sp), hyperSpec = sp$spc, matrix = sp, stop("The class of the input must be either \"hyperSpec\" or \"matrix\"")): EXPR must be a length 1 vector

head(evaluation)
#> Error in head(evaluation): object 'evaluation' not found

par(mfrow = c(3,1))
 plot(density(evaluation$RMSE), main = "RMSE", col = 2)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'evaluation' not found
 plot(density(evaluation$LOF), main = "Lack-of-fit")
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'evaluation' not found
 plot(density(evaluation$GOF), main = "Goodness-of-fit")
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'evaluation' not found
par(mfrow = c(1,1))

# Density plot of LOF by group:
DATA <- cbind(obj$.., evaluation)
#> Error in data.frame(..., check.names = FALSE): object 'evaluation' not found
qplot(LOF, data = DATA, fill = gr, color = gr,
 geom = "density", alpha = I(.2))
#> Warning: `qplot()` was deprecated in ggplot2 3.4.0.
#> Error in ggplot(data, mapping, environment = caller_env): object 'DATA' not found