Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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
You can’t perform that action at this time.