# NOT RUN {
# Simulate data set with binary outcome
dfBinary <- quickSim(type="binary")
# Logistic regression, used as algorithm to predict the response variable
# (response = estimated probability of outcome being present).
glmRes <- glm(y~x1+x2,data=dfBinary,family="binomial")
# Extract measured outcome and the predicted probability (fitted values)
# from the logistic regression output, put both in a data.frame.
glmDf <- data.frame(measOutcome=dfBinary$y,
fitted=glmRes$fitted.values)
# binary outcome, based on the default probability threshold of 0.5.
get2by2Df <- data.frame(
measuredOutcome=glmDf$measOutcome,
predictedOutcome=ifelse(glmDf$fitted<.5, 0, 1))
# Demand 2x2 matrix to be part of the resulting list.
my2x2 <- get2by2(xr=get2by2Df, measColumn=1, print2by2 = TRUE)
# Display both 2x2 matrices
# tbl1: Theoretical perspective, with specificity in top left cell,
# sensitivity in bottom right cell.
my2x2$tbl1
# tbl2: Practical perspective, with negative predictive value (npv)
# in top left cell, positive predictive value (ppv) in bottom right
# cell.
my2x2$tbl2
# }
Run the code above in your browser using DataLab