accuracy: Calculate accuracy metrics

Description Usage Arguments Details Value Examples

View source: R/accuracy.R

Description

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

Usage

1
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

Details

R2 is calculated with the following formula:

R^{2} = 1 - \frac{∑ (y_{i} - \hat{y}_{i})^{2}}{∑ (y_{i} - \bar{y}_{i})^{2}}

RMSE is calculated with the following formula:

RMSE = √{\frac{1}{n} ∑ (\hat{y}_{i} - y_{i})^{2}}

Bias is calculated with the following formula:

Bias = \frac{∑ (\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.

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

Examples

1
2
3
4
5
6
7
8
# 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)

mqueinnec/foster documentation built on March 28, 2021, 4:27 p.m.