validate_prediction: Validate predictions of class "spectral_prediction"

View source: R/validate_prediction.R

validate_predictionR Documentation

Validate predictions of class 'spectral_prediction'

Description

\loadmathjax

Calculate several prediction validation statistics for a prediction of class 'spectral_prediction'.

Usage

validate_prediction(prediction, reference)

Arguments

prediction

an object of class 'spectral_prediction', as returned by the predict function.

reference

a vector or a matrix with one column, containing the response variable.

Value

An object of class "spectral_validation", which is a list containing the following validation statistics of the prediction:

  • model_information: A list containing information of the model on which the predictions are based. Mirrors the very same list contained in the prediction. See predict for more details.

  • validation: A list with the validation statistics. For each prediction contained in prediction (which are based on the number of components), one entry in the list is added. Each of these elements exactly one matrix and one vector: val_results contains the predicted values and the corresponding errors in a matrix, while val_stats is a vector consisting of the coefficient of determination (\mjeqnR^2R^2), root mean squared error (RMSE) and the largest residual obtained. These statistics are computed based on the prediction and reference, while ignoring any NA's.

  • control_limits: A list carried over from the prediction with the per-component control limits used by the leverage-vs-Q plot: q (spectral residual Q limits), leverage (leverage limits) and conf (their confidence level).

Author(s)

Claudio Orellano

Examples

data("proximateCannabis")
skips <- c(10, 25, 37)
simple_model <- calibrate(CBDA ~ spc,
  data = proximateCannabis, preprocess = preprocess_recipe(),
  method = fit_plsr(5), control = calibration_control("kfold"),
  skips = skips, verbose = FALSE
)

# Predict the skipped indices
pred <- predict(simple_model,
  newdata = proximateCannabis[skips, ],
  ncomp = simple_model$final_ncomp,
  verbose = FALSE
)

# Validate skipped indices
validate_prediction(pred, proximateCannabis$CBDA[skips])

proximetricsR documentation built on Sept. 4, 2026, 5:08 p.m.