preval estimates the prevalence of positive cases for a nominal/categorical predicted-observed dataset.

preval_t estimates the prevalence threshold for a binary predicted-observed dataset.

## Usage

preval(
data = NULL,
obs,
pred,
atom = FALSE,
pos_level = 2,
tidy = FALSE,
na.rm = TRUE
)

preval_t(
data = NULL,
obs,
pred,
atom = FALSE,
pos_level = 2,
tidy = FALSE,
na.rm = TRUE
)

## Arguments

data

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

obs

Vector with observed values (character | factor).

pred

Vector with predicted values (character | factor).

atom

Logical operator (TRUE/FALSE) to decide if the estimate is made for each class (atom = TRUE) or at a global level (atom = FALSE); Default : FALSE.

pos_level

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.

tidy

Logical operator (TRUE/FALSE) to decide the type of return. TRUE returns a data.frame, FALSE returns a list; Default : FALSE.

na.rm

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

## Value

an object of class numeric within a list (if tidy = FALSE) or within a data frame (if tidy = TRUE).

## Details

The prevalence measures the overall proportion of actual positives with respect to the total number of observations. Currently, it is defined for binary cases only.

The general formula is:

$$preval = \frac{positive}{positive + negative}$$

The prevalence threshold represents an point on the ROC curve (function of sensitivity (recall) and specificity) below which the precision (or PPV) dramatically drops.

$$preval_t = \frac{\sqrt{TPR * FPR} - FPR}{TPR - FPR}$$

It is bounded between 0 and 1. The closer to 1 the better. Values towards zero indicate low performance. For the formula and more details, see online-documentation

Freeman, E.A., Moisen, G.G. (2008). A comparison of the performance of threshold criteria for binary classification in terms of predicted prevalence and kappa. . Ecol. Modell. 217(1-2): 45-58. doi:10.1016/j.ecolmodel.2008.05.015

Balayla, J. (2020). Prevalence threshold and the geometry of screening curves. _Plos one, 15(10):e0240215, _ doi:10.1371/journal.pone.0240215