Last active
December 14, 2015 18:49
-
-
Save nborwankar/5131870 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# compute error measures for predictive model for activity (act) as dependent variable | |
# note this is computed for all 6 activities and a total computed which is an aggregate value | |
errormeasures <- function(orig, pred, act) { | |
N <- length(orig) | |
origtrue <-as.vector(NULL) | |
origfalse <-as.vector(NULL) | |
predtrue <-as.vector(NULL) | |
predfalse <-as.vector(NULL) | |
for (i in 1:N) { | |
if(orig[i] == act){ | |
origtrue <- append(origtrue, i) | |
} else { | |
origfalse <- append(origfalse, i) | |
} | |
if(pred[i] == act){ | |
predtrue <- append(predtrue, i) | |
} else { | |
predfalse <- append(predfalse, i) | |
} | |
} | |
# compute the members of the quadrant | |
truepos <- length(intersect(origtrue, predtrue)) | |
trueneg <- length(intersect(origfalse, predfalse)) | |
falsepos <- length(intersect(origfalse, predtrue)) | |
falseneg <- length(intersect(origtrue, predfalse)) | |
# compute the 4 measures as defined in class | |
# | |
# PosPred: Positive Predictive Value | |
# NegPred: Negative Predictive Value | |
# Sens: Sensitivity | |
# Spec: Specificity | |
pospred <- truepos/(truepos + falsepos) | |
negpred <- trueneg/(trueneg + falseneg) | |
sens <- truepos/(truepos + falseneg) | |
spec <- trueneg/(trueneg + falsepos) | |
c(truepos,trueneg,falsepos,falseneg,pospred,negpred,sens,spec) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment