In this lab, you will begin to get oriented with R and work with some data.
Attempt each exercise in order.
In each code chunk, if you see “# INSERT CODE HERE”, then you are expected to add some code to create the intended output (Make sure to erase “# INSERT CODE HERE” and place your code in its place).
If my instructions say to “Run the code below…” then you do not need to add any code to the chunk.
Many exercises may require you to type some text below the code chunk, interpreting the output and answering the questions.
Please follow the Davidson Honor Code and rules from the course syllabus regarding seeking help with this assignment.
When you are finished, click the “Knit” button at the top of this panel. If there are no errors, an word file should pop up after a few seconds.
Take a look at the resulting word file that pops up. Make sure everything looks correct, your name is listed at the top, and that there is no ‘junk’ code or output.
Save the word file (to your local computer, and/or to a cloud location) as: Lab 6 “Insert Your Name”.
Use this link to upload your word file to my Google Drive folder. Do not upload the original .Rmd version.
This assignment is due Thursday, July 21, 2022, no later than 9:30 am Eastern. Points will be deducted for late submissions.
TIP: Start early so that you can troubleshoot any issues with knitting to word.
There are 6 possible points on this assignment.
Baseline (C level work)
Average (B level work)
Advanced (A level work)
In this exercise, you will further analyze the Wage
data
set.
Perform polynomial regression to predict wage using age. Use cross-validation to select the optimal degree d for the polynomial. What degree was chosen, and how does this compare to the results of hypothesis testing using ANOVA? Make a plot of the resulting polynomial fit to the data.
Fit a step function to predict wage
using
age
, and perform cross-validation to choose the optimal
number of cuts. Make a plot of the fit obtained.
#insert code here
ANSWER:
This question relates to the College
data set.
Split the data into a training set and a test set. Using
out-of-state tuition
as the response and the other
variables as the predictors, perform forward stepwise selection on the
training set in order to identify a satisfactory model that uses just a
subset of the predictors.
Fit a GAM on the training data, using
out-of-state tuition
as the response and the features
selected in the previous step as the predictors. Plot the results, and
explain your findings.
Evaluate the model obtained on the test set, and explain the results obtained.
For which variables, if any, is there evidence of a non-linear relationship with the response?
#insert code here
ANSWER: