Learn R Programming

mechkar (version 1.14.6)

getModelCutoffs: Function for selection of the prediction cutoffs by each quantile of the prediction

Description

This function is intended to calculate the most important statistics that may help in making desicions on the optimal cutoff of the predictions for our needs.

Usage

getModelCutoffs(pred, obs, div=10)

Arguments

pred

a vector containing the predicted values of a model

obs

a vector containing the values of the outcome variable

div

the number of quantiles to calculate. Default=10

Value

This function returns a table containing the following statistics:

  • TP - the number of true negatives

  • FP - the number of false positives

  • FN - the number of false negatives

  • TN - the number of true positives

  • sensitivity

  • specificity

  • PPV - positive predictive value

  • NVP - negative predictive value

  • accuracy

  • error

  • prevalence

  • lift

  • precision (same as PPV)

  • recall (same as sensitivity)

  • F1_score (harmonic mean of precision and recall)

Details

This function return a list containing nine values (see values section). It includes three types of standards: the European (euro), the American (us) and the World Health Organization (who). The confidence interval (CI) is calculated using the binomial probabilities using the binconf function of the Hmisc package. The default is to calculate the 95% CI (using an alpha of 0.05).

Examples

Run this code
# NOT RUN {
mod <- glm(am ~ mpg + cyl + hp + wt, data=mtcars, family="binomial")
pred <- as.numeric(predict(mod, newdata = mtcars, type="response"))
tab2 <- getModelCutoffs(pred,mtcars$am)
# }

Run the code above in your browser using DataLab