Matthews Correlation Coefficient in R

Matthews Correlation Coefficient in R, We can evaluate a classification model’s effectiveness using a metric called the Matthews correlation coefficient (MCC).

How to perform Rolling Correlation in R »

It is determined by:

MCC = (TP*TN – FP*FN) /√(TP+FP)(TP+FN)(TN+FP)(TN+FN)

where:

  • TP: Number of true positives
  • TN: Number of true negatives
  • FP: Number of false positives
  • FN: Number of false negatives

This statistic is especially helpful when there is an imbalance between the two classes, meaning that one class appears substantially more frequently than the other.

MCC’s value ranges from -1 to 1, depending on:

A score of -1 denotes a complete discrepancy between expected and actual classes.

0 is equivalent to making an entirely arbitrary guess.

Total agreement between expected and actual classes is indicated by a score of 1.

The following example uses R’s mcc() function from the mltools package to demonstrate how to calculate MCC for this specific circumstance.

Calculate Polychoric Correlation in R »

Matthews Correlation Coefficient in R

An illustration is computing the Matthews correlation coefficient in R.

The mcc() function from the mltools package is used to calculate the Matthews correlation coefficient after defining a vector of predicted classes and a vector of actual classes:

library(mltools)
actual <- rep(c(1, 0), times=c(20, 380))
preds <- rep(c(1, 1, 0, 0), times=c(15, 5, 5, 75))
mcc(preds, actual)
0.4588315

The correlation coefficient for Matthews is 0.45.

Group wise Correlation in R »

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

1 × three =