In my R logistic regression in R, I am trying to create a contingency table comparing fitted to observed values (i.e. 0 or 1 actual vs. 0 or 1 fitted value). However, my data has missing values in various rows of various variables, hence the fitted value vector is of a shorter length than the original data set. Here is an example:
test <- data.frame(male=c(1,0,1,0,0,1,1,0,1,0,0,1),
height=c(58,100,NA,19,20,69,58,24,46,19,97,69))
model <- glm(male~height, family=binomial("logit"),data=test)
check_model <- table(test$male,fitted.values(model)>0.5)
Error in table(test$male, fitted.values(model) > 0.5) : all arguments must have the same length
Does anyone know of a way to feed in the actual values (test$male) only in rows where the model has a fitted.value
that is not NULL
?