# ROC Curve

A ROC curve is a graphical representation of the performance of a binary classification model for all classification thresholds. Here, ROC stands for Receiver Operating Characteristic.

## Example of a ROC curve

We would like to classify based on a screening, whether a person has cancer or not.

This classification is done with the help of a certain blood value, where high values indicate cancer. The question now is which value we choose as the classification threshold. So from which value do we predict a disease?

For this, we obtain data from 10 people about how high the blood value is and whether or not a disease is present.

We could now choose a classification threshold of 45, for example. In this case, of the 5 people with disease, we would correctly classify 4 as "diseased" and 1 incorrectly as "healthy." Thus, we correctly classified 4 out of 5 as "sick."

This value is called True Positive Rate (TPR) and is equal to the sensitivity.

On the other hand, out of the 5 healthy individuals, we have 2 misclassified as " diseased" and 3 correctly classified as "healthy". So, we misclassified 2 out of 5 as " diseased". This value is called False Positive Rate (FPR) and is 1 - specificity.

So for a threshold of 45 we get a True Positive Rate of 4/5 i.e. 0.8 and a False Positive Rate of 3/5 i.e. 0.6.

## True Positve Rate and False Positve Rate

The True Positve Rate (TPR) is calculated with this equation:

The True Positve Rate is equal to the true positives divided by the true positvs plus the false negatives. The true positives are those correctly classified as ill and the false negatives are those incorrectly classified as healthy.

The False Positve Rate (FPR) is obtained using this equation:

The false positive rate is equal to is equal to the false positives divided by the false positives plus the true negatives. The false positives are the healthy individuals misclassified as diseased and the true negatives are the individuals correctly classified as healthy.

## Plot the ROC Curve

We can now calculate for each threshold what the True Positive Rate and the False Positive Rate are. And these two values are then plotted on the ROC curve. The True Positive Rate is plotted on the y-axis and the False Positive Rate on the x-axis.

Now let's plot the complete ROC curve for our example!

If we choose the threshold value to be very small, i.e. pushed all the way to the left, we correctly classify all 5 diseased individuals. Our True Positive Rate is thus 5 out of 5 i.e. 1.

In the same way, however, we also misclassify all 5 healthy persons as " diseased". Our False Positive Rate is therefore 5 out of 5, i.e. 1.

This gives us the first point:

Now we can push the threshold further. Here we still classify all 5 diseased correctly as diseased. So we still have a True Positive Rate 5 / 5. However, of the 5 healthy individuals, we now only misclassify 4 out of 5 as " diseased". So we have 4 out of 5 or 0.8.

At the next threshold, we still have a True Positive Rate of 1. All 5 diseased are correctly classified and a False Positive Rate of 3/5, so 0.6.

At the next threshold, for the first time, a diseased person is misclassified as "healthy". We therefore obtain a True Positive Rate of 4/5, i.e. 0.8, and a False Positive Rate of 3/5, i.e. 0.6.

We can now do this for all other thresholds.So we now have our finished ROC curve At this point, for example, 80% of the diseased people were correctly classified as "diseased" and 20% of the healthy people were incorrectly classified as "diseased".

## AUC value

Using the ROC curve, we can now also compare different classification methods. A classification model is better the higher the curve is. Therefore, the larger the area under the curve, the better the classifier. And exactly this area is reflected by the AUC value, the Area under the Curve.

The AUC value varies between 0 and 1. The larger the value, the better the classifier.

## ROC curve and logistic regression

But what about the ROC curve and the logistic regression? We could, for example, create a new classifier using logistic regression. Here we could use, in addition to the blood value, the age and gender of the person.

In a logistic regression, the estimated value is then how likely it is that a particular person has the disease.

Very often, 50% is then simply taken as the threshold to classify whether a person is diseased or not. But of course this does not have to be the case! Any threshold can be used.

Therefore, we can also create a ROC curve for the different threshold values in the logistic regression.

## Create ROC curve with DATAtab

Of course, we can easily output an ROC curve online with DATAtab. To do this, we simply copy our data into this table and click on ROC Calculator. Alternatively, you can also create an ROC curve in the Regression Calculator in Logistic Regression.

Now we simply select the two variables Diseased and Blood Value and specify what we consider a positive event, in our case the answer yes. Now we get the ROC curve. In the table below the ROC curve we find the respective threshold value for each point of the ROC curve.

### Statistics made easy

- Many illustrative examples
- Ideal for exams and theses
- Statistics made easy on 251 pages
**Only 6.99 €**

*"Super simple written"*

*"It could not be simpler"*

*"So many helpful examples"*