#### Commands for a logistic regression. uva.nomiss <- na.omit(uva) ### Remove missing values. dim(uva.nomiss) ### check dimensions. in.sample <- sample(19022,9500) ### Choose the in-sample rows. out.sample <- c(1:19022)[-in.sample] attach(uva.nomiss) ### make the data set available. ### The logistic regression command. glm(Newbie ~ Age, family="binomial",subset = in.sample,data=uva.nomiss) ### Saving the model output to a variable. glm.out <- glm(Newbie ~ Age, family="binomial",subset = in.sample,data=uva.nomiss) ### predicting new values. predict.glm(glm.out,uva.nomiss,type=c("response")) ### saving the predicted values my.preds <- predict.glm(glm.out,uva.nomiss,type=c("response")) ### Recoding them as categories. my.classes <- as.factor(ifelse(my.preds > .333, 1, 0)) ### Calling the original newbie variable a factor Newbie <- as.factor(Newbie) ### Cross classify: (in sample) table (Newbie[in.sample],my.classes[in.sample]) ### Cross classify: (out of sample) table (Newbie[out.sample],my.classes[out.sample])