Solved – Calculation of accuracy (and Cohen’s kappa) using sensitivity, specificity, positive and negative predictive values

accuracycohens-kappaconfusion matrixsensitivity-specificity

I read How to calculate specificity from accuracy and sensitivity, but I have two diagnostic performance measures more. Please correct me if I am wrong: if

  • Sensitivity=TP/(TP+FN)
  • Specificity=TN/(TN+FP)
  • Positive predictive value=TP/(TP+FP)
  • Negative predictive value=TN/(TN+FN)
  • Accuracy=(TP+TN)/(TP+TN+FP+FN)
  • Cohen's kappa=1-[(1-Po)/(1-Pe)]

Can I calculate the accuracy if I know the sensitivity, specificity, positive and negative predictive values? Can I calculate the Cohen's kappa too?

Unfortunately, that situation could happen if you read an abstract of a scientific work.

(I use R)

Best Answer

You generally know TP, FN, FP, and TN, so based on this wiki:

Po = (TP + TN) / (TP + TN + FP + FN),

Pe = ((TP + FN) * (TP + FP) + (FP + TN) * (FN + TN)) / (TP + TN + FP + FN)^2

Kappa = (Po - Pe) / (1 - Pe)

Our friend Wolfram can then help to simplify this, leading to:

Kappa = 2 * (TP * TN - FN * FP) / (TP * FN + TP * FP + 2 * TP * TN + FN^2 + FN * TN + FP^2 + FP * TN)

So in R, the function would be:

cohens_kappa <- function(TP, FN, FP, TN) {
  return(2 * (TP * TN - FN * FP) / (TP * FN + TP * FP + 2 * TP * TN + FN^2 + FN * TN + FP^2 + FP * TN))
}
Related Question