Learn R Programming

foster (version 0.1.1)

accuracy: Calculate accuracy metrics

Description

Calculate coefficient of determination (R2), root-mean square error (RMSE) and bias between predictions and observations of continuous variables.

Usage

accuracy(obs, preds, vars = NULL, folds = NULL)

Arguments

obs

A vector of observed values

preds

A vector of predicted values

vars

Optional vector indicating different variables

folds

Optional vector indicating the folds

Value

Data frame with following columns:

vars

Response variable

R2

R2

RMSE

RMSE

RMSE_rel

Relative RMSE

bias

bias

bias_rel

Relative bias

count

Number of observations

Details

R2 is calculated with the following formula: $$R^{2} = 1 - \frac{\sum (y_{i} - \hat{y}_{i})^{2}}{\sum (y_{i} - \bar{y}_{i})^{2}}$$

RMSE is calculated with the following formula: $$RMSE = \sqrt{\frac{1}{n} \sum (\hat{y}_{i} - y_{i})^{2}}$$

Bias is calculated with the following formula: $$Bias = \frac{\sum (\hat{y}_{i} - y_{i})}{n}$$

Relative RMSE and bias are also calculated by dividing their value by the mean of observations.

If accuracy assessment was performed using k-fold cross-validation the accuracy metrics are calculated for each fold separately. The mean value of the accuracy metrics across all folds is also returned.

Examples

Run this code
# NOT RUN {
# kNN_preds is a data frame obtained from foster::trainNN
# It contains predictions and observations of the trained kNN model
load(system.file("extdata/examples/kNN_preds.RData",package="foster"))

accuracy(obs = kNN_preds$obs,
         preds = kNN_preds$preds,
         vars = kNN_preds$variable,
         folds = kNN_preds$Fold)
# }

Run the code above in your browser using DataLab