I want to calculate the prediction ratio
I have predicted a logistic regression, and I also have a dataset of the observation of another variable.
I want to calculate the correctly predicted ratio.
I have recorded the prediction like this
glm9 = glm(v172 ~ age, family=binomial (link="logit"), data=france)
pre10<-predict(glm9, germany, type="terms")
prediction <- ifelse (pre10 >=1, 1, 0)
prediction
0 1
305 5039
The results I have predicted is a value, but the observation value is a variable in a dataframe
I want to have a table that looks like this:
0 1
0 182 63
1 24 32
CodePudding user response:
I think you want something like this. I used mtcars because I didn't have your data.
glm9 <- glm(am ~ cyl, family=binomial (link="logit"), data=mtcars)
prob <- predict(glm9, type = "response")
prediction <- ifelse(prob < 0.5, 0, 1)
with(mtcars, table(am, prediction)
Which gives:
prediction
0 1
0 16 3
1 5 8