I have a data set consisting of a dichotomous variable ( Y) and 12 independent variables ( X1to X12) stored in a csv file. Here are the first 5 rows of data:
Y,X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12
0,9,3.86,111,126,14,13,1,7,7,0,M,46-50
1,7074,3.88,232,4654,143,349,2,27,18,6,M,25-30
1,5120,27.45,97,2924,298,324,3,56,21,0,M,31-35
1,18656,79.32,408,1648,303,8730,286,294,62,28,M,25-30
0,3869,21.23,260,2164,550,320,3,42,203,3,F,18-24
I built a logistic regression model from data using the following code:
mydata <- read.csv("data.csv")
mylogit <- glm(Y~X1+X2+X3+X4+X5+X6+X7+X8+X9+X10+X11+X12, data=mydata,
family="binomial")
mysteps <- step(mylogit, Y~X1+X2+X3+X4+X5+X6+X7+X8+X9+X10+X11+X12, data=mydata,
family="binomial")
I can get the predicted probabilities for each of the data using code:
theProbs <- fitted(mysteps)
Now I would like to create a classification table - using the first 20 rows of the data table ( mydata), from which I can determine the percentage of predicted probabilities that actually agree with the data. Note that for the dependent variable ( Y), 0 represents a probability that is less than 0.5, and 1 represents a probability that is greater than 0.5.
, . , - , .