Search for question
Question

Exercise 4. (30 points) For this exercise, the only extra package allowed is ISLR2. The dataset

Default will be used throughout the exercise and is accessible through the ISLR2 package. We

will only look at the variables default and balance in this exercise.

1. Write the R code to reproduce the following figure

normal de

0.0012

0.0010

0.0009

90000

POODO

20000

0.0000

no default

500

1000

1500 g1

grid for the balance variable

2000

2500

typing ppr (x=1800, p1, g1, g2, s1, s2) yields 0.329938

typing ppr (x=1500, p1, g1,g2, s1, s2) yields 0.1016933

typing ppr (x=1000, p1, g1,g2, s1, s2) yields 0.004558713

3000

Figure 2. The distribution of the balance variable.

2. Using the same values for g1 and g2 as in the figure, and with obvious meanings for the

variable names p1, s1 and s2, write your own R function that has the name ppr and

that can be used for predictions in the following way: For example, when balance takes

either one of the values 1800, 1500 or 1000, then the function syntax and output is

Explain thoroughly how the function ppr works and use it to compute the training

error rate.

Fig: 1