Skip to contents

It estimates a group of metrics characterizing the prediction performance for a continuous (regression) or categorical (classification) predicted-observed dataset. By default, it calculates all available metrics for either regression or classification.

Usage

metrics_summary(
  data = NULL,
  obs,
  pred,
  type = NULL,
  metrics_list = NULL,
  orientation = "PO",
  pos_level = 2,
  na.rm = TRUE
)

Arguments

data

argument to call an existing data frame containing the data (optional).

obs

vector with observed values (numeric).

pred

vector with predicted values (numeric).

type

argument of class string specifying the type of model. For continuous variables use type = 'regression'. For categorical variables use type = 'classification'.

metrics_list

vector or list of specific selected metrics. Default is = NULL, which will estimate all metrics available for either regression or classification.

orientation

argument of class string specifying the axis orientation to estimate slope(B1) and intercept(B0). It only applies when type = "regression". "PO" is for predicted vs observed, and "OP" for observed vs predicted. Default is orientation = "PO".

pos_level

(for classification only). Integer, for binary cases, indicating the order (1|2) of the level corresponding to the positive. Generally, the positive level is the second (2) since following an alpha-numeric order, the most common pairs are (Negative | Positive), (0 | 1), (FALSE | TRUE). Default : 2.

na.rm

Logic argument to remove rows with missing values (NA). Default is na.rm = TRUE.

Value

an object of class data.frame containing all (or selected) metrics.

Details

The user can choose to calculate a single metric, or to calculate all metrics at once. This function creates a data.frame with all (or selected) metrics in the metrica-package. If looking for specific metrics, the user can pass a list of desired metrics using the argument “metrics_list” (e.g. metrics_list = c("R2","MAE", "RMSE", "RSR", "NSE", "KGE")). For the entire list of available metrics with formula, see online-documentation

Examples

# \donttest{
# Continuous variable (regression)
X <- rnorm(n = 100, mean = 0, sd = 10)
Y <- rnorm(n = 100, mean = 0, sd = 10)
regression_case <- data.frame(obs = X, pred = Y)

# Get a metrics summary for a regression problem
metrics_summary(regression_case, obs = X, pred = Y, type = "regression")
#>    Metric         Score
#> 1      B0  2.261092e+00
#> 2      B1  9.823083e-01
#> 3       r  3.057903e-02
#> 4      R2  9.350771e-04
#> 5      Xa  9.720574e-01
#> 6     CCC  2.972457e-02
#> 7     MAE  1.094530e+01
#> 8    RMAE -1.017724e+01
#> 9    MAPE -2.233993e+01
#> 10  SMAPE  1.497724e+02
#> 11    RAE  1.452330e+00
#> 12    RSE  1.961015e+00
#> 13    MBE -2.280119e+00
#> 14    PBE  2.120118e+02
#> 15    PAB  2.863901e+00
#> 16    PPB  1.596094e-02
#> 17    MSE  1.815336e+02
#> 18   RMSE  1.347344e+01
#> 19  RRMSE -1.252798e+01
#> 20    RSR  1.455467e-01
#> 21 iqRMSE  1.061780e+00
#> 22    MLA  5.227917e+00
#> 23    MLP  1.763057e+02
#> 24   RMLA  5.227917e+00
#> 25   RMLP  1.763057e+02
#> 26     SB  5.198943e+00
#> 27   SDSD  2.897447e-02
#> 28    LCS  1.763057e+02
#> 29    PLA  2.879862e+00
#> 30    PLP  9.712014e+01
#> 31     Ue  9.712014e+01
#> 32     Uc  1.596094e-02
#> 33     Ub  2.863901e+00
#> 34    NSE -9.610150e-01
#> 35     E1 -4.523297e-01
#> 36   Erel  7.188393e-01
#> 37    KGE -1.992940e+00
#> 38      d  4.208294e-01
#> 39     d1  2.782443e-01
#> 40    d1r  2.738352e-01
#> 41    RAC  5.080269e-01
#> 42     AC -8.388534e-01
#> 43 lambda  2.972457e-02
#> 44  dcorr  1.374032e-01
#> 45    MIC  1.911684e-01

# Categorical variable (classification)
binomial_case <- data.frame(labels = sample(c("True","False"), 100, 
replace = TRUE), predictions = sample(c("True","False"), 100, replace = TRUE))

#' # Get a metrics summary for a regression problem
metrics_summary(binomial_case, obs = labels, pred = predictions,
type = "classification")
#>         Metric       Score
#> 1     accuracy  0.48000000
#> 2   error_rate  0.52000000
#> 3    precision  0.45098039
#> 4       recall  0.48936170
#> 5  specificity  0.47169811
#> 6       balacc  0.48052991
#> 7       fscore  0.46938776
#> 8          agf  0.49147938
#> 9        gmean  0.48044874
#> 10        khat -0.03875350
#> 11         mcc -0.03887781
#> 12         fmi  0.46977924
#> 13         bmi -0.03894018
#> 14         csi  0.30263158
#> 15      deltap -0.03881553
#> 16       posLr  0.92629179
#> 17       negLr  1.08255319
#> 18         dor  0.85565476
#> 19         npv  0.51020408
#> 20         FPR  0.52830189
#> 21         FNR  0.51063830
#> 22         FDR  0.54901961
#> 23         FOR  0.48979592
#> 24      preval  0.47000000
#> 25    preval_t  0.49540479
#> 26     AUC_roc  0.47035256
#> 27          p4  0.47956631
# }