
Validate predictions of class 'spectral_prediction'
Source: R/validate_prediction.R
validate_prediction.RdCalculate several prediction validation statistics for a prediction of class
'spectral_prediction'.
Arguments
- prediction
an object of class
'spectral_prediction', as returned by thepredictfunction.- 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 theprediction. Seepredictfor more details.validation: A list with the validation statistics. For each prediction contained inprediction(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_resultscontains the predicted values and the corresponding errors in a matrix, whileval_statsis a vector consisting of the coefficient of determination (\(R^2\)), root mean squared error (RMSE) and the largest residual obtained. These statistics are computed based on thepredictionandreference, while ignoring anyNA's.control_limits: A list carried over from thepredictionwith the per-component control limits used by the leverage-vs-Q plot:q(spectral residual Q limits),leverage(leverage limits) andconf(their confidence level).
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])
#> Validating response: CBDA
#> Number of validated predictions: 3
#> Number of validations: 1
#> Number of components (nc): 5
#> ________________________________________________________________________________
#>
#> y | nc_5 y_hat error mahalanobis q_residual
#> 10 7.59 | 9.457 -1.867 0.583 0.000
#> 25 0.03 | -0.851 0.881 2.216 0.000
#> 37 9.77 | 14.070 -4.302 1.300 0.000
#> ________________________________________________________________________________
#> Comparison of model and validation statistics:
#>
#> | nc_5 val model
#> R^2 | 0.992 0.486
#> RMSE | 3.374 4.379
#> max_error | -4.302 19.590
#> ________________________________________________________________________________