Question 1

Describe the null hypotheses to which the p-values given in Table 3.4 correspond. Explain what conclusions you can draw based on these p-values. Your explanation should be phrased in terms of sales, TV, radio, and newspaper, rather than in terms of the coefficients of the linear model.

For intercept, the null hypothesis is \(\beta_0 = 0\). For the other predictors, the null hypothesis is \(\beta_n = 0\) (for \(n = 1, 2, 3\)), where \(\beta_1\), \(\beta_2\), and \(\beta_3\) correspond to TV, radio, and newspaper, respectively.

Based on the p-values, we can conclude that there is evidence that the intercept is not zero, meaning that some sales are expected even without any spending on TV, radio, or newspaper. Furthermore, spending on TV and radio is significantly associated with increased sales, while spending on newspaper is not.

Question 2

Carefully explain the differences between the KNN classifier and KNN regression methods.

Question 3

We have a data set with five predictors: \(X_1\) = GPA, \(X_2\) = IQ, \(X_3\) = Level (1 for College, 0 for High School), \(X_4\) = Interaction between GPA and IQ, and \(X_5\) = Interaction between GPA and Level. The response is starting salary after graduation (in thousands of dollars). Suppose we use least squares to fit the model, and get the following estimates:

\(\hat\beta_0 = 50\), \(\hat\beta_1 = 20\), \(\hat\beta_2 = 0.07\), \(\hat\beta_3 = 35\), \(\hat\beta_4 = 0.01\), \(\hat\beta_5 = -10\).

a. Which answer is correct, and why?

The model is given by:

\[ y = \beta_0 + \beta_1 \cdot GPA + \beta_2 \cdot IQ + \beta_3 \cdot Level + \beta_4 \cdot GPA \cdot IQ + \beta_5 \cdot GPA \cdot Level \]

Fixing IQ and GPA, changing Level from 0 (high school) to 1 (college) will change the outcome by:

\[ \Delta y = \beta_3 + \beta_5 \cdot GPA \]

Substituting the values:

\[ \Delta y = 35 + (-10) \cdot GPA \]

Setting \(\Delta y > 0\) to find when college graduates earn more than high school graduates:

\[ 35 - 10 \cdot GPA > 0 \Rightarrow GPA < 3.5 \]

Thus, option iii is correct: high school graduates earn more on average than college graduates, provided GPA is high enough (GPA > 3.5).

Visualization

library(plotly)

model <- function(gpa, iq, level) {
  50 + gpa * 20 + iq * 0.07 + level * 35 + gpa * iq * 0.01 + gpa * level * -10
}

x <- seq(1, 5, length = 100)
y <- seq(80, 140, length = 100)
college <- outer(x, y, model, level = 1)
high_school <- outer(x, y, model, level = 0)

plot_ly(x = x, y = y) %>%
  add_surface(z = ~college, colorscale = "Blues", colorbar = list(title = "College")) %>%
  add_surface(z = ~high_school, colorscale = "Reds", colorbar = list(title = "High School")) %>%
  layout(scene = list(xaxis = list(title = "GPA"),
                      yaxis = list(title = "IQ"),
                      zaxis = list(title = "Salary")))

b. Predict the salary of a college graduate with IQ of 110 and GPA of 4.0

model(gpa = 4, iq = 110, level = 1)
## [1] 137.1

c. True or False: Since the coefficient for the GPA/IQ interaction term is very small, there is very little evidence of an interaction effect. Justify your answer.

This is false. Even though the coefficient for the interaction is small, GPA and IQ operate on different scales. Therefore, we should test the significance of the interaction or visualize its impact to fully understand its effect.

Question 5

Consider the fitted values that result from performing linear regression without an intercept. In this setting, the ith fitted value takes the form:

\[ \hat{y}_i = x_i \hat{\beta} \]

where

\[ \hat{\beta} = \frac{\sum_{i=1}^{n} x_i y_i}{\sum_{i'=1}^{n} x^2_{i'}}. \]

Show that we can write:

\[ \hat{y}_i = \sum_{i'=1}^{n} a_{i'} y_{i'} \]

and determine the value of \(a_{i'}\).

Solution

\[\begin{align} \hat{y}_i & = x_i \frac{\sum_{i=1}^nx_iy_i}{\sum_{i' = 1}^n x^2_{i'}} \\ & = x_i \frac{\sum_{i'=1}^n x_{i'}y_{i'}}{\sum_{i'' = 1}^n x^2_{i''}} \\ & = \frac{\sum_{i'=1}^n x_i x_{i'} y_{i'}}{\sum_{i'' = 1}^n x^2_{i''}} \\ & = \sum_{i'=1}^n \frac{x_i x_{i'}}{\sum_{i'' = 1}^n x^2_{i''}} y_{i'} \end{align}\]

Thus, we have:

\[ a_{i'} = \frac{x_i x_{i'}}{\sum x^2}. \]