## S3 method for class 'factor'
specificity(actual, predicted, micro = NULL, na.rm = TRUE, ...)
## S3 method for class 'factor'
weighted.specificity(actual, predicted, w, micro = NULL, na.rm = TRUE, ...)
## S3 method for class 'cmatrix'
specificity(x, micro = NULL, na.rm = TRUE, ...)
## S3 method for class 'factor'
tnr(actual, predicted, micro = NULL, na.rm = TRUE, ...)
## S3 method for class 'factor'
weighted.tnr(actual, predicted, w, micro = NULL, na.rm = TRUE, ...)
## S3 method for class 'cmatrix'
tnr(x, micro = NULL, na.rm = TRUE, ...)
## S3 method for class 'factor'
selectivity(actual, predicted, micro = NULL, na.rm = TRUE, ...)
## S3 method for class 'factor'
weighted.selectivity(actual, predicted, w, micro = NULL, na.rm = TRUE, ...)
## S3 method for class 'cmatrix'
selectivity(x, micro = NULL, na.rm = TRUE, ...)
specificity(...)
tnr(...)
selectivity(...)
weighted.specificity(...)
weighted.tnr(...)
weighted.selectivity(...)
specificity
specificity.factor | R Documentation |
Description
The specificity()
-function computes the specificity, also known as the True Negative Rate (TNR) or selectivity, between two vectors of predicted and observed factor()
values. The weighted.specificity()
function computes the weighted specificity.
Usage
Arguments
actual
|
A vector of |
predicted
|
A vector of |
micro
|
A |
na.rm
|
A |
…
|
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
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
actual <- factor(
x = iris$species_num,
levels = c(1,0),
labels = c("Virginica", "Others")
)
# 4) evaluate class-wise performance
# using Specificity
# 4.1) unweighted Specificity
specificity(
actual = actual,
predicted = predicted
)
# 4.2) weighted Specificity
weighted.specificity(
actual = actual,
predicted = predicted,
w = iris$Petal.Length/mean(iris$Petal.Length)
)
# 5) evaluate overall performance
# using micro-averaged Specificity
cat(
"Micro-averaged Specificity", specificity(
actual = actual,
predicted = predicted,
micro = TRUE
),
"Micro-averaged Specificity (weighted)", weighted.specificity(
actual = actual,
predicted = predicted,
w = iris$Petal.Length/mean(iris$Petal.Length),
micro = TRUE
),
sep = "\n"
)