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

MATH5806 Applied Regression Analysis

Term 2, 2022

Assignment 2

Exercise 1 [10.5 marks]

In this exercise we are focusing on the breast cancer Wisconsin diagnostic dataset with the aim to classify breast tumors as malign or benign. The dataset is available on the UCI Machine Learning Repository and for conveniency in the dslabs package in R.

1    library ( dslabs )                                                                                                                                                          2    data ( brca )                                                                                                                                                                     

The dataset provides details about 569 biopsies of breasts masses that were computationally ex- tracted from digital images of ne needle aspirate biopsy slides. In addition, to indicating whether a breast mass is malignant or benign, 30 features are provided. These correspond to properties of 10 parameters of cell nuclei, such as size, shape and regularity, and for each of them the mean, standard error, and worst value.

1. The dataset provides of a large number of explanatory variables that can possibly help with the classification problem at hand, and we would like to identify and remove some of the most highly correlated variables.  Rather than simply remove the variables associated with the highest correlations we use the findCorrelation function from the R package caret which for each pair of highly correlated variables, removes the variable with the largest mean absolute correlation.

(a) How many variables are considered as highly correlated when setting the absolute cor-

relation cutoff to be 0.85. Name them.  [0.5 mark]

(b) Use set .seed(2022) and the sample() function to create a training sample of 450

observations. The remaining observations form the test dataset. Provide the observed probabilities of malign and benign breast masses in the full, training and test datasets.

[0.5 mark]

2. We consider the Linear Discriminant Analysis (LDA) as classification tool.

(a) Using the training dataset, fit the LDA model on the diagnosis using the predictors

selected in the previous questions. What are the estimated prior probabilities and how can they be interpreted?  [1 mark]

(b) Using the model t, provide the remaining coordinate of the indifference point when all

the covariates take value zero except for area mean?  [1 mark]

(c) Using the training data, provide the confusion matrix for the 0 .5 threshold and com- ment about the prediction accuracy. Assuming that the interest is to correctly predict malignant tumors, comment about the sensitivity of the model.  [1 mark]

(d) Would a threshold at 0.3 be better? Justify your answer.  [1 mark]

(e) Plot the ROC curve and calculate the area under the curve.  Do they indicate a good

prediction accuracy from the model?  [1 mark]

(f) What is the test error rate at the 0.3 threshold and associated proportion of malign

tumors missed by the LDA? [1 mark]

3. We now consider the logistic regression (LR) as regression tool.

(a) Using the training dataset, fit the LR model on the diagnosis using the predictors se-

lected in question 1.What is the estimated regression equation?  Discuss the adequacy of the model and each estimated coefficient.  [1 mark]

(b) Using the training dataset and, 0.5 and 0.3 thresholds, what is the error rate and the

proportion of malignant tumors that were misclassified by the logistic regression? Com- pare them with those obtained for the LDA model.  [2 marks]

(c) Do your conclusions to the previous question for the 0.3 threshold still hold on the test data?  [0.5 mark]

Exercise 2 [9.5 marks]

This exercise aims at predicting the median value of a home in the City of Boston, the capital and most populous city of Massachusetts in the United States of America. The dataset, simply called Boston, is available in the R package MASS. This dataset contains information collected by the U.S Census Service concerning housing in the area of Boston such as:

● crim - per capita crime rate by town

● zn - proportion of residential land zoned for lots over 25,000 sq.ft.

●  indus - proportion of non-retail business acres per town.

● chas - Charles River dummy variable (1 if tract bounds river; 0 otherwise)

● nox - nitric oxides concentration (parts per 10 million)

● rm - average number of rooms per dwelling

● age - proportion of owner-occupied units built prior to 1940

● dis - weighted distances to ve Boston employment centres

● rad - index of accessibility to radial highways

● tax - full-value property-tax rate per $10,000

● ptratio - pupil-teacher ratio by town

● black - 1000(Bk − 0.63)2  where Bk is the proportion of blacks by town

● lstat - % lower status of the population

● medv - Median value of owner-occupied homes in $1000’s

The data is small in size with only 506 cases. It was originally published by Harrison, D. and Ru- binfeld, D.L. ‘Hedonic prices and the demand for clean air’, J. Environ. Economics & Management, vol.5, 81-102, 1978.

1. Use the regsubsets() function from the R package leaps to perform best subset selection in order to choose the best model.

(a) Plot the Cp  as function of the subset size and then choose the best subset size. Provide

your R code.  [0.5 mark]

(b) Plot the BIC as function of the subset size and then choose the best subset size. Provide

your R code.  [0.5 mark]

(c) Plot the adjusted R2  as function of the subset size and then choose the best subset size. Provide your R code.  [0.5 mark]

(d) What is the estimated regression equation for the best model?  [0.5 mark]

2. Let the indices for the training and test data to be defined by running

1    set . seed (1)                                                                                                                                                        2   train   < -   sample (1: nrow ( Boston ) , nrow ( Boston ) / 2)                                                                     3   test   < -   - train                                                                                                                                                

We now t a lasso model to the training data.  Considering a regular grid of 50 λ values ranging between −6 and 1 on the log scale, perform 8-fold cross-validation to select the op- timal value of the tuning parameter using the R package glmnet and cv .glmnet function.

For  reproducibility  purposes,  please  specify  set .seed(2022)  before  calling  the cv .glmnet function.

(a) What is the optimal value of λ?  Plot the Mean Squared Error as function of log(λ).

Provide your R code.  [1 mark]

(b) Re-fit the model using the selected optimal value of λ .  Which of the predictors are

shrunk to zero? Provide your R code.  [1 mark]

(c) If we were to consider the more conservative choice of λ lambda .1se, how many pa- rameters would be shrunk to zero?  [0.5 mark]

(d) Using the optimal value of the tuning parameter from (a), what is the value of the associated test MSE? [0.5 mark]

3. We now t a ridge model to the training data. Considering the same grid of tuning parame- ters as for the lasso, perform 8-fold cross-validation to select the optimal value of the tuning parameter.

For  reproducibility  purposes,  please  specify  set .seed(2022)  before  calling  the cv .glmnet function.

(a) What is the optimal value of λ?  Plot the Mean Squared Error as function of log(λ).

Provide your R code.  [1 mark]

(b) Re-fit the model using the selected optimal value of λ .  Which of the predictors are

shrunk to zero? Provide your R code.  [1 mark]

(c) If we were to consider the more conservative choice of λ lambda .1se, how many pa- rameters would be shrunk to zero?  [0.5 mark]

(d) Using the optimal value of the tuning parameter from (a), what is the value of the associated test MSE? [0.5 mark]

4.  Compare the Lasso and Ridge using their respective test MSE, and R2 .  [1.5 mark]