####### Computing and plotting confidence bands for ####### logistic regression ####### (Unfortunately need a custom function at this point, ####### since it is not handled by mosaic yet) library("mosaic") library("Stat2Data") data("MedGPA") ### Fit the model medschool.model <- glm(Acceptance ~ MCAT, data = MedGPA, family = "binomial") summary(medschool.model) ### Get the custom function source("http://colindawson.net/stat215/code/logistic_interval_function.R") ### The usage pattern of the function # plot.logistic.bands( # model, # the logistic model object # xname, # name of the predictor # xlim, # range of x values to plot # xlab, # label to use on X axis # ylab # label to use on Y axis # level # confidence level (0 to 1 scale) # ) plot.logistic.bands( model = medschool.model, xname = "MCAT", xlim = range(~MCAT, data = MedGPA), xlab = "MCAT Score", ylab = "P(Acceptance)", level = 0.95 ) points(Acceptance ~ MCAT, data = MedGPA) ### Fit a model with multiple predictors and get a confidence ### interval for a prediction at specific x values model2 <- glm(Acceptance ~ MCAT + GPA, data = MedGPA) get.logistic.CI(model2, level = 0.95, MCAT = 34, GPA = 3.5)