Question 1 (8 marks)
This question will require you to analyse a regression dataset. In particular, you will be looking at predicting the fuel effiffifficiency 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 effiffifficiency tables for car models available for sale during the years 2017 through to 2020. The target is the fuel effiffifficiency of the car measured in kilometers per litre. The higher this score, the better the fuel effiffifficiency of the car. The data dictionary for this dataset is given in Table 1. Provide working/R code/justififications for each of these questions as required.
- Fit a multiple linear model to the fuel effiffifficiency data using R. Using the results of fifitting the linear model, which predictors do you think are possibly associated with fuel effiffifficiency, and why? Which three variables appear to be the strongest predictors of fuel effiffifficiency, and why?
- How would your assessment of which predictors are associated change if you used the Bonferroni procedure with α = 0.05? [1 marks]
- Describe what effffect engine displacement (Eng.Displacement) appears to have on the mean fuel effiffifficiency of a car. Describe the effffect that the Drive.SysF variable has on the mean fuel effiffifficiency of a car. [2 marks]
- Use the stepwise selection procedure with the BIC penalty (using direction=”both”) to prune out potentially unimportant variables. Write down the fifinal regression equation obtained after pruning. [1 mark]
- 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 effiffifficiency for this new car. Provide a 95% confifidence interval for this prediction. [1 mark]
(b) The current car that you own has a mean fuel effiffifficiency of 11km/l (measured over the life time of your ownership). Does your model suggest that the new car will have better fuel effiffifficiency than your current car? [1 mark]
Variable name Description Values
Year of sale
2017 − 2020
Engine Displacement (litres, l)
0.9 − 8.4
Number of Cylinders
3 − 16
Engine Aspiration (Oxygen intake)
Number of Gears
1 − 10
Lockup torque converter present?
N∗ and Y
4∗ : 4-wheel drive
Maximum % of Ethanol allowed
10 − 85
Type of Fuel
G∗ : Regular Unleaded
GM: Mid-grade Unleaded Recommended
GP: Premium Unleaded Recommended
GPR: Premium Unleaded Required
Fuel Effiffifficiency (km/l)
4.974 − 26.224
Table 1: Fuel effiffifficiency 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 classifification 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 fifile wrappers.R. Don’t forget to source this fifile to get access to the function.
- Using the techniques you learned in Studio 9, fifit 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]
- 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]
- For classifification 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 fifile. [1 mark]
- According to your tree, which predictor combination results in the lowest probability of having heart-disease? [1 mark]
- We will also fifit a logistic regression model to the data. Use the glm() function to fifit a logistic 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 fifinal 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]
- Write down the regression equation for the logistic regression model you found using step-wise selection. [1 mark]
- Please describe the effffect the variable CA has on heart-disease according to this logistic regression model? [1 mark]
- The fifile heart.test.ass3.2022.csv contains the data on a further n0 = 92 individuals. Using the my.pred.stats() function contained in the fifile my.prediction.stats.R, compute the prediction 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]
- 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]
- 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 fifind a confifidence 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 confifidence 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]
本网站支持 Alipay WeChatPay PayPal等支付方式
E-mail: firstname.lastname@example.org 微信号:vipnxx