Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

DS 303 HoMEWoRK 6

Fall 2022

Problem 1: Wrapping up Multiple Linear Regression

Suppose you are going to teach a friend the fundamentals of multiple linear regression. Summarize the following topics in a way that your friend, who has a minimal statistics/CS background, could understand. Each summary should be no more than 3-5 sentences.

a. What is our goal in training (or tting) a linear model? Does we require any assumptions?

b.  Conceptually,  how do we obtain the regression estimates for  a multiple linear regression model?

c. Are these regression estimates trustworthy? How do we know? Explain any key concepts in plain language.

d. How do we obtain a prediction for Y based on our model? How do we quantify any uncertainty related to our predictions?

e. How can we evaluate how good our model is at prediction?

f. What is statistical inference and why is it useful in the context of linear regression models?

g. What are 3 potential issues that may arise with our multiple linear regression model?  For each of these issues, explain 1.  why the issue can cause problems and 2.  what can be done to resolve the issue.

Problem 2:  Predictions in the presence of multicollinearity

a. Is multicollinearity a problem for making accurate predictions?  If you’re unsure, make an educated guess based on what we have learned in class.

b. Let’s carry out a simulation study to answer this.  We will simulate data with and without multicollinearity. This is our true model:

Yi = 80 + 81Xi1 + 82Xi2 + ∈i

where i = 1. 口 口 口 . 100, ∈ ~ N(A = 0. u2 = 4), 80 = 3, 81 = 2, and 82 = 4.    To generate your predictors with multicollinearity use the following code:

set .seed(42)

x1  =  runif(100)

x2  =  0 .8*x1  +  rnorm(100,0,0 .1)

Using these predictors, generate your Y values in R. Check the correlation between x1 and x2 using the cor() function. Report that value here.

c.  Split your data into a training set and test set. Train your model on the training set. lm(Y  ~  x1+x2,  data  =  train)

Report the test MSE for this model.

d.  Repeat this process 2,500 times (use a for-loop).  This means for each iteration, you’ll need to generate a random set of Y’s, fit a model on your training set, and then obtain the test MSE for that model.  We do not need to generate new predictor values (think about why). Remember to store the test MSE for each iteration and do not set seed. What is the mean test MSE in this setting when the predictors are highly correlated? Plot a histogram of your 2,500 test MSEs and comment on what you see.

e. Now generate predictors without multicollinearity using the following code:

set .seed(24)

x1  =  runif(100)

x2  =  rnorm(100,0,1)

Using these predictors, generate your Y values in R. Check the correlation between x1 and x2. Report that value here.

f. Again run 2,500 simulations to obtain the test MSE of our model when the predictors are not correlated. What is the mean test MSE in this setting when the predictors are not correlated? Plot a histogram of your test MSE and comment on what you see.

g.  Based on our simulation study, is multicollinearity a problem for making accurate predictions? Comment on your ndings.

Problem 3:  Model Diagnostics

We will use the Auto dataset for this problem. It is part of the library ISLR2. We will treat mpg as the response and all other variables except name as the predictors.

a.  Perform a multiple linear regression with mpg as the response and all other variables except name as the predictors. Is there a significant relationship between at least one of the predictors and the response? Justify your answer.

b.  Compute the matrix of correlations between the variables using the function cor(). You will need to exclude the name variable, which is qualitative.

c. Is multicollinearity an issue in our model?  Justify your answer.  Propose and implement a solution.

d.  Check that the constant variance and linearity assumption hold for the model in part(a). Comment on any problems you see.

e.  Propose and implement some transformations on the variables.  This should include fitting some of the non-linear models we’ve covered. Report your nal model. Is this an improvement over the model from part (a)? Justify your answer.

Problem 4:  Polynomial Regression

For this problem, we will use the Boston data set in the ISLR2 R package.  We will treat nox as the response and dis as the predictor.

a. Use the poly() function to t a cubic polynomial regression to predict nox using dis. Report the regression output, and plot the resulting data and tted polynomial model.

b.  Plot the polynomial ts for a range of different polynomial degrees (say, from 1 to 10) and report the associated RSS.

c. Using hypothesis testing, what is the optimal polynomial degree? Report your results.

d.  Perform 5-fold cross-validation to select the optimal degree for the polynomial. Report your training MSE and test MSES. Do your results coincide with part (c)?

Problem 5:  Ridge Regression

For this problem, we will use the College data set in the ISLR2 R package. Our aim is to predict the number of applications (Apps) received using the other variables in the dataset.

a.  Split the data set into a training and a test set. Please set .seed(12) so that we can all have the same results.

b. Fit a least squares linear model (using all predictors) on the training set, and report the test MSE obtained.

c. Fit a ridge regression model (using all predictors) on the training set. The function glmnet, by default, internally scales the predictor variables so that they will have standard deviation

1. Explain why this scaling is necessary when implementing regularized models.

d. Find an optimal  for the ridge regression model on the training set by using 5-fold cross- validation. Report the optimal  here.

e. Using that optimal 入, evaluate your trained ridge regression model on the test set.  Report the test MSE obtained. Is there an improvement over the model from part (b)?

f. Fit a lasso regression model on the training set. Find the optimal lambda using 5-fold cross- validation. Report the optimal  and the test MSE obtained.

g.  Comment on your results. How accurately can we predict the number of college applications received? Is there much difference among the test errors resulting from these 3 approaches?