Logistic
Regression

KEY:

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

_____________________________

(1)

XYXY <- glm(DV ~ IV1 + IV2, data=ds, family = binomial)
summary(XYXY)

(2)

XYXYprobabilities <- predict(XYXY, ds, type = "response")

(3)

XYXYprediction <- ifelse(XYXYprobabilities > .5, 1, 0)

(4)

table(XYXYpredition, ds$DV)

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())

_____________________________

library(caret)

confusionMatrix(XYXYprediction, ds$DV)

_____________________________