ds = dataset you are currently using.
DV = predicted variable
IV = predictor variable
XYXY = dummy name for a variable, matrix, or data frame into which you are moving information.
Logistic regression with two predictors.
(1) run regression (2) generate probabilities (3) generate predictions (4) create table and calculate accuracy
XYXY <- glm(DV ~ IV1 + IV2, data=ds, family = binomial)
XYXYprobabilities <- predict(XYXY, ds, type = "response")
XYXYprediction <- ifelse(XYXYprobabilities > .5, 1, 0)
mean(XYXYprediction == ds$DV)
Alternate to step (4), you can use the caret package to generate a more complete set of descriptives.
NOTE: the command "confusionMatrix" requires both XYXYpredition and ds$DV to be factored (i.e., as.factor())