compute the Matthews correlation coefficient with actual and predict values.

matthews(predicted, y, positive)

Arguments

predicted

numeric. the predicted value of binary classification

y

factor or character. the actual value of binary classification

positive

level of positive class of binary classification

Value

numeric. The Matthews Correlation Coefficient.

Details

The Matthews Correlation Coefficient has a value between -1 and 1, and the closer to 1, the better the performance of the binary classification.

Examples

# simulate actual data
set.seed(123L)
actual <- sample(c("Y", "N"), size = 100, prob = c(0.3, 0.7), replace = TRUE)
actual
#>   [1] "N" "Y" "N" "Y" "Y" "N" "N" "Y" "N" "N" "Y" "N" "N" "N" "N" "Y" "N" "N"
#>  [19] "N" "Y" "Y" "N" "N" "Y" "N" "Y" "N" "N" "N" "N" "Y" "Y" "N" "Y" "N" "N"
#>  [37] "Y" "N" "N" "N" "N" "N" "N" "N" "N" "N" "N" "N" "N" "Y" "N" "N" "Y" "N"
#>  [55] "N" "N" "N" "Y" "Y" "N" "N" "N" "N" "N" "Y" "N" "Y" "Y" "Y" "N" "Y" "N"
#>  [73] "Y" "N" "N" "N" "N" "N" "N" "N" "N" "N" "N" "Y" "N" "N" "Y" "Y" "Y" "N"
#>  [91] "N" "N" "N" "N" "N" "N" "Y" "N" "N" "N"

# simulate predict data
set.seed(123L)
pred <- sample(c("Y", "N"), size = 100, prob = c(0.2, 0.8), replace = TRUE)
pred
#>   [1] "N" "N" "N" "Y" "Y" "N" "N" "Y" "N" "N" "Y" "N" "N" "N" "N" "Y" "N" "N"
#>  [19] "N" "Y" "Y" "N" "N" "Y" "N" "N" "N" "N" "N" "N" "Y" "Y" "N" "N" "N" "N"
#>  [37] "N" "N" "N" "N" "N" "N" "N" "N" "N" "N" "N" "N" "N" "Y" "N" "N" "N" "N"
#>  [55] "N" "N" "N" "N" "Y" "N" "N" "N" "N" "N" "Y" "N" "Y" "Y" "N" "N" "N" "N"
#>  [73] "N" "N" "N" "N" "N" "N" "N" "N" "N" "N" "N" "N" "N" "N" "Y" "Y" "Y" "N"
#>  [91] "N" "N" "N" "N" "N" "N" "N" "N" "N" "N"

# simulate confusion matrix
table(pred, actual)
#>     actual
#> pred  N  Y
#>    N 71 11
#>    Y  0 18

matthews(pred, actual, "Y")
#> [1] 0.7330937