This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
#In Chapter 4, we used logistic regression to predict the probability of default using income and balance on the default data set. We will now estimate the test error of this logistic regression model using the validation set approach. Do not forget to set a random seed before beginning your analysis.
#a. Fit a logistic regression model that uses income and balance to predict default.
#b. Using the validation set approach, estimate the test error of this model. In order to do this, you must perform the following steps:
#1) Split the sample set into a training set and a validation set.
#2) Fit a multiple logistic regression model using only the training observations.
#3) Obtain a prediction of default status for each individual in the validation set by computing the posterior probability of default for that individual, and classifying the individual to the default category if the posterior probability is greater than 0.5.
#4) Compute the validation set error, which is the fraction of the observations in the validation set that are misclassified.
#c. Repeat the process in (b) three times, using three different splits of the observations into a training set and a validation set. Comment on the results obtained.
#d. Now consider a logistic regression model that predicts the probability of default using income, balance, and a dummy variable for student. Estimate the test error for this model using the validation set approach. Comment on whether or not including a dummy variable for student leads to a reduction in the test error rate.
# Set random seed
# Load the dataset
# Split the dataset into features (X) and target variable (y)
# Split the data into training set and validation set
# Fit a logistic regression model using only the training observations
# Obtain predictions for the validation set
# Compute the validation set error
# Repeat the process three times
# Split the data into new training set and validation set
# Fit a new logistic regression model
# Obtain predictions for the new validation set
# Compute the new validation set error
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.