(5/5)

# you will be looking at predicting the fuel efficiency of a car (in kilometers per litre) based on characteristics of the car and its engine.

INSTRUCTIONS TO CANDIDATES

Question 1 (8 marks)

This question will require you to analyse a regression dataset. In particular, you will be looking at predicting the fuel efficiency of a car (in kilometers per litre) based on characteristics of the car and its engine. This is clearly an important and useful problem. The dataset fuel.ass3.2022.csv contains n = 500 observations on p = 9 predictors obtained from actual fuel efficiency tables for car models available for sale during the years 2017 through to 2020. The target is the fuel efficiency of the car measured in kilometers per litre. The higher this score, the better the fuel efficiency of the car. The data dictionary for this dataset is given in Table 1. Provide working/R code/justifications for each of these questions as required.

1. Fit a multiple linear model to the fuel efficiency data using R. Using the results of fitting the linear model, which predictors do you think are possibly associated with fuel efficiency, and why? Which three variables appear to be the strongest predictors of fuel efficiency, and why? [2 marks]

2. How would your assessment of which predictors are associated change if you used the Bonferroni procedure with α = 0.05? [1 marks]

3. Describe what effect engine displacement (Eng.Displacement) appears to have on the mean fuel efficiency of a car. Describe the effect that the Drive.SysF variable has on the mean fuel efficiency of a car. [2 marks]

4. Use the stepwise selection procedure with the BIC penalty (using direction="both") to prune out potentially unimportant variables. Write down the final regression equation obtained after pruning. [1 mark]

5. Imagine that you are looking for a new car to buy to replace your existing car. The characteristics of the new car that you are looking at are given by the thirty-third row of the dataset.

(a) Use your BIC model to predict the mean fuel efficiency for this new car. Provide a 95% confidence interval for this prediction. [1 mark]

(b) The current car that you own has a mean fuel efficiency of 11km/l (measured over the life time of your ownership). Does your model suggest that the new car will have better fuel efficiency than your current car? [1 mark]

Variable name Description Values

Model.Year Year of sale 2017 2020 Eng.Displacement Engine Displacement (litres, l) 0.9 8.4 No.Cylinders Number of Cylinders 3 16

Aspiration Engine Aspiration (Oxygen intake) N: Naturally∗

OT: Other

SC: Supercharged

TC: Turbocharged

TS: Turbo+supercharged

No.Gears Number of Gears 1 10 Lockup.Torque.Converter Lockup torque converter present? N∗ and Y Drive.Sys Drive System 4∗: 4-wheel drive

A:All-wheel F:Front-wheel

P:Part-time 4-wheel

R:Rear-wheel

Max.Ethanol Maximum % of Ethanol allowed 10 85

Fuel.Type Type of Fuel G∗: Regular Unleaded

Comb.FE Fuel Efficiency (km/l) 4.974 − 26.224

Table 1: Fuel efficiency data dictionary. The ∗ denotes the reference category for each categorical variable.

Question 2 (18 marks)

In this question we will analyse the data in heart.train.ass3.2022.csv. In this dataset, each observation represents a patient at a hospital that reported showing signs of possible heart disease. The outcome is presence of heart disease (HD), or not, so this is a classification problem. The predictors are summarised in Table 2. We are interested in learning a model that can predict heart disease from these measurements. To answer this question you must:

When answering this question, you must use the rpart package that we used in Studio 9. The wrapper function for learning a tree using cross-validation that we used in Studio 9 is contained in the file wrappers.R. Don’t forget to source this file to get access to the function.

1. Using the techniques you learned in Studio 9, fit a decision tree to the data using the tree package. Use cross-validation with 10 folds and 5, 000 repetitions to select an appropriate size tree. What variables have been used in the best tree? How many leaves (terminal nodes) does the best tree have? [2 marks]

2. Plot the tree found by CV. Clearly describe in plain English what conditions are required for the tree to predict that someone has heart disease. (hint: use the text(cv\$best.tree,pretty=12) function to add appropriate labels to the tree). [3 marks]

3. For classification problems, the rpart package only labels the leaves with the most likely class. However, if you examine the tree structure in its textural representation on the console, you can determine the probabilities of having heart disease (see Question 2.3 from Studio 9 as a guide) in each leaf (terminal node). Take a screen-capture of the plot of the tree (don’t forget to use the “zoom” button to get a larger image) or save it as an image using the “Export” button in R Studio.

Then, use the information from the textual representation of the tree available at the console and annotate the tree in your favourite image editing software; next to all the leaves in the tree, add text giving the probability of contracting heart disease. Include this annotated image in your report file. [1 mark]

4. According to your tree, which predictor combination results in the lowest probability of having heart-disease? [1 mark]

5. We will also fit a logistic regression model to the data. Use the glm() function to fit a logis- tic regression model to the heart data, and use stepwise selection with the KIC score (using direction="both") to prune the model. What variables does the final model include, and how do they compare with the variables used by the tree estimated by CV? Which predictor is the most important in the logistic regression? [3 marks]

6. Write down the regression equation for the logistic regression model you found using step-wise selection. [1 mark]

7. Please describe the effect the variable CA has on heart-disease according to this logistic regression model? [1 mark]

8. The file heart.test.ass3.2022.csv contains the data on a further n' = 92 individuals. Using the my.pred.stats() function contained in the file my.prediction.stats.R, compute the pre- diction statistics for both the tree and the step-wise logistic regression model on this test data.

Contrast and compare the two models in terms of the various prediction statistics? Does one seem better than the other? Justify your answer. [2 marks]

9. Calculate the odds of having heart disease for the 10th patient in the test dataset. The odds should be calculated for both:

(a) the tree model found using cross-validation; and

(b) the step-wise logistic regression model.

How do the predicted odds for the two models compare? [2 marks]

10. For the logistic regression model using only those predictors selected by KIC in Question 2.5, use the bootstrap procedure (use at least 5, 000 bootstrap replications) to find a confidence interval for the odds of having heart disease for the 65th and 66th patients in the test data. Use the bca option when computing this confidence interval.

Using these intervals, do you think there is any evidence to suggest that there is a real difference in the population odds of having heart disease between these two individuals? [2 marks]

(5/5)

## Related Questions

##### . Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

##### . The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

##### . Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

##### . SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

##### . Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Hire Me

Hire Me

Hire Me