checkPriorAndMisClassCost {folda} | R Documentation |
Check and Normalize Prior Probabilities and Misclassification Costs
Description
This function verifies and normalizes the provided prior probabilities and
misclassification cost matrix for a given response variable. It ensures that
the lengths of the prior and the dimensions of the misclassification cost
matrix match the number of levels in the response variable. If prior
or
misClassCost
are not provided, default values are used: the prior is set to
the observed frequencies of the response, and the misclassification cost
matrix is set to 1 for all misclassifications and 0 for correct
classifications.
Usage
checkPriorAndMisClassCost(prior, misClassCost, response)
Arguments
prior |
A numeric vector representing the prior probabilities for each
class in the response variable. If |
misClassCost |
A square matrix representing the misclassification costs
for each pair of classes in the response variable. If |
response |
A factor representing the response variable with multiple classes. |
Value
A list containing:
prior |
A normalized vector of prior probabilities for each class. |
misClassCost |
A square matrix representing the misclassification costs, with rows and columns labeled by the levels of the response variable. |
Examples
# Example 1: Using default prior and misClassCost
response <- factor(c('A', 'B', 'A', 'B', 'C', 'A'))
checkPriorAndMisClassCost(NULL, NULL, response)
# Example 2: Providing custom prior and misClassCost
prior <- c(A = 1, B = 1, C = 2)
misClassCost <- matrix(c(0, 2, 10,
1, 0, 10,
1, 2, 0), nrow = 3, byrow = TRUE)
checkPriorAndMisClassCost(prior, misClassCost, response)