## S3 method for class 'factor'
plr(actual, predicted, ...)
## S3 method for class 'factor'
weighted.plr(actual, predicted, w, ...)
## S3 method for class 'cmatrix'
plr(x, ...)
## Generic S3 method
plr(...)
## Generic S3 method
weighted.plr(
...,
w )
Positive Likelihood Ratio
plr.factor | R Documentation |
Description
A generic function for the positive likelihood ratio in classification tasks. Use weighted.plr()
weighted positive likelihood ratio.
Usage
Arguments
actual
|
A vector of |
predicted
|
A vector of |
…
|
micro = NULL, na.rm = TRUE Arguments passed into other methods |
w
|
A |
x
|
A confusion matrix created |
Value
If micro
is NULL (the default), a named <numeric>
-vector of length k
If micro
is TRUE or FALSE, a <numeric>
-vector of length 1
Definition
Let \(\hat{\alpha} \in [0, \infty]\) be the likelihood of a positive outcome. The positive likelihood ratio of the classifier is calculated as,
\[ \hat{\alpha} = \frac{\frac{\#TP}{\#TP + \#FN}}{1 - \frac{\#TN}{\#TN + \#FP}} \]
Where:
-
\(\frac{\#TP}{\#TP + \#FN}\) is the sensitivity, or true positive rate
-
\(\frac{\#TN}{\#TN + \#FP}\) is the specificity, or true negative rate
Examples
# 1) recode Iris
# to binary classification
# problem
$species_num <- as.numeric(
iris$Species == "virginica"
iris
)
# 2) fit the logistic
# regression
<- glm(
model formula = species_num ~ Sepal.Length + Sepal.Width,
data = iris,
family = binomial(
link = "logit"
)
)
# 3) generate predicted
# classes
<- factor(
predicted as.numeric(
predict(model, type = "response") > 0.5
),levels = c(1,0),
labels = c("Virginica", "Others")
)
# 3.1) generate actual
# classes
<- factor(
actual x = iris$species_num,
levels = c(1,0),
labels = c("Virginica", "Others")
)
# 4) evaluate model performance
# with class-wise positive likelihood ratios
cat("Positive Likelihood Ratio", sep = "\n")
plr(
actual = actual,
predicted = predicted
)
cat("Positive Likelihood Ratio (weighted)", sep = "\n")
weighted.plr(
actual = actual,
predicted = predicted,
w = iris$Petal.Length/mean(iris$Petal.Length)
)