{"id":556,"date":"2015-08-01T12:52:33","date_gmt":"2015-08-01T11:52:33","guid":{"rendered":"http:\/\/pcool.dyndns.org:8080\/statsbook\/?page_id=556"},"modified":"2025-07-01T18:26:12","modified_gmt":"2025-07-01T17:26:12","slug":"roc-plot","status":"publish","type":"page","link":"https:\/\/pcool.dyndns.org\/index.php\/roc-plot\/","title":{"rendered":"ROC Plot"},"content":{"rendered":"\n<p>Receiver operating characteristics (ROC) plots are used to show the performance of a classifier. For example the Mirels&#8217; score (integer value between 4 and 12) may be used as a classifier for fracture (binary).<\/p>\n\n\n\n<p><strong>Mirels&#8217; score<\/strong><\/p>\n\n\n\n<table id=\"tablepress-9\" class=\"tablepress tablepress-id-9\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">Location<\/th><th class=\"column-2\">Size<\/th><th class=\"column-3\">Appearance<\/th><th class=\"column-4\">Pain<\/th><th class=\"column-5\">Points<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">Upper<\/td><td class=\"column-2\">< 1\/3<\/td><td class=\"column-3\">Blastic<\/td><td class=\"column-4\">Mild<\/td><td class=\"column-5\">1<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">Lower<\/td><td class=\"column-2\">1\/3 &#8211; 2\/3<\/td><td class=\"column-3\">Mixed<\/td><td class=\"column-4\">Moderate<\/td><td class=\"column-5\">2<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">Peritroch.<\/td><td class=\"column-2\">> 2\/3<\/td><td class=\"column-3\">Lytic<\/td><td class=\"column-4\">Severe<\/td><td class=\"column-5\">3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-9 from cache -->\n\n\n<p>Download the <a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/data_files\/plotroc.rda\" target=\"_blank\" rel=\"noreferrer noopener\">plotroc.rda<\/a> dataset for this example. The data frame is called plotroc and has two variables: mirel (the mirels&#8217; score) and fracture (fracture yes \/ no). The package ROCR <sup class='sup-ref-note' id='note-zotero-ref-p556-r1-o1'><a class='sup-ref-note' href='#zotero-ref-p556-r1'>1<\/a><\/sup> should be <a href=\"https:\/\/pcool.dyndns.org\/index.php\/packages\/\" data-type=\"page\" data-id=\"22\">installed<\/a> to create the plot:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>library(ROCR)<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>mirel.pred&lt;-prediction(plotroc$mirel,plotroc$fracture)<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>mirel.perf&lt;-performance(mirel.pred,'tpr','fpr')<\/em><\/span><\/code><\/pre>\n\n\n\n<p>To show the plot with a title:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>plot(mirel.perf,main='ROC curve - Mirels Score')<\/em><\/span><\/code><\/pre>\n\n\n\n<p>This plot shows the performance of the classifier (Mirels&#8217; score) with the false positive rate on the x-axis and the true positive rate on the y-axis. The line of &#8216;chance&#8217; is a diagonal from the origin to (1,1). To add this line:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>abline(0,1)<\/em><\/span><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/rocplot-1024x768.png\" alt=\"\" class=\"wp-image-3605\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/rocplot-1024x768.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/rocplot-300x225.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/rocplot-768x576.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/rocplot.png 1355w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>A classifier should be above this line of chance (a classifier that is below the diagonal line is usually redefined so it becomes &#8216;positive&#8217; rather than &#8216;negative&#8217;). The larger the area under the curve, the better the classifier. To calculate the area under the curve (auc):<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>auc &lt;- performance(mirel.pred,'auc')<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>auc &lt;- unlist(auc@y.values)<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>auc<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&#091;1] 0.95<\/em><\/span><\/code><\/pre>\n\n\n\n<p>An area under the curve of 95% indicates good performance as a classifier<sup class='sup-ref-note' id='note-zotero-ref-p556-r2-o1'><a class='sup-ref-note' href='#zotero-ref-p556-r2'>2<\/a><\/sup>.<\/p>\n\n\n\n<p>The optimum value of the classifier is that value that maximises true positives whilst minimising false positives. Youden&#8217;s index can be helpful in finding the optimum value<sup class='sup-ref-note' id='note-zotero-ref-p556-r3-o1'><a class='sup-ref-note' href='#zotero-ref-p556-r3'>3<\/a><\/sup>. However, the chosen value also depends on the clinical relevance.\u00a0 In the example, all patients with a Mirels&#8217; score of 10 or above had a fracture. Of the 3 patients with a score of 9, 2 had a fracture; whilst 2 out of 4 patients with a score of 8 had a fracture. None of the patients with a score of 7 had a fracture. A score of 8 seems clinically a better classifier as it is important not to miss an impending fracture.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Receiver operating characteristics (ROC) plots are used to show the performance of a classifier. For example the Mirels&#8217; score (integer value between 4 and 12) may be used as a classifier for fracture (binary). Mirels&#8217; score Download the plotroc.rda dataset for this example. The data frame is called plotroc and has two variables: mirel (the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"footnotes":""},"class_list":["post-556","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/556","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/comments?post=556"}],"version-history":[{"count":1,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/556\/revisions"}],"predecessor-version":[{"id":4718,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/556\/revisions\/4718"}],"wp:attachment":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/media?parent=556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}