title: R Confusion Matrix sensitivity and specificity labeling
body: <p>I am using R v3.3.2 and Caret 6.0.71 (i.e. latest versions) to construct a logistic regression classifier. I am using the confusionMatrix function to create stats for judging its performance. </p>
  
  <p>logRegConfMat &lt;- confusionMatrix(logRegPrediction, valData[,"Seen"])</p>
  
  <ul>
  <li>Reference 0, Prediction 0 = 30 </li>
  <li>Reference 1, Prediction 0 = 14</li>
  <li>Reference 0, Prediction 1 = 60</li>
  <li>Reference 1, Prediction 1 = 164</li>
  </ul>
  
  <p>Accuracy : 0.7239<br>
  Sensitivity : 0.3333<br>
  Specificity : 0.9213 </p>
  
  <p>The target value in my data (Seen) uses 1 for true and 0 for false. I assume the Reference (Ground truth) columns and Predication (Classifier) rows in the confusion matrix follow the same convention. Therefore my results show:</p>
  
  <ul>
  <li>True Negatives (TN) 30</li>
  <li>True Positives (TP) 164 </li>
  <li>False Negatives (FN) 14 </li>
  <li>False Positives (FP) 60</li>
  </ul>
  
  <p><strong>Question: Why is sensitivity given as 0.3333 and specificity given as 0.9213? I would have thought it was the other way round - see below.</strong> </p>
  
  <p>I am reluctant to believe that there is bug in the R confusionMatrix function as nothing has been reported and this seems to be a significant error.</p>
  
  <hr>
  
  <p>Most references about calculating specificity and sensitivity define them as follows - i.e. <a href="http://www.medcalc.org/calc/diagnostic_test.php" rel="noreferrer">www.medcalc.org/calc/diagnostic_test.php</a> </p>
  
  <ul>
  <li>Sensitivity = TP / (TP+FN) =  164/(164+14) = 0.9213</li>
  <li>Specificity = TN / (FP+TN) =  30/(60+30) = 0.3333</li>
  </ul>