Exercise

# Fitted values and residuals

Once you have fit a regression model, you are often interested in the fitted values (\(\hat{y}_i\)) and the residuals (\(e_i\)), where \(i\) indexes the observations. Recall that:

$$ e_i = y_i - \hat{y}_i $$

The least squares fitting procedure guarantees that the mean of the residuals is zero (n.b., numerical instability may result in the computed values not being *exactly* zero). At the same time, the mean of the fitted values must equal the mean of the response variable.

In this exercise, we will confirm these two mathematical facts by accessing the fitted values and residuals with the `fitted.values()`

and `residuals()`

functions, respectively, for the following model:

```
{r, eval=FALSE}
mod <- lm(wgt ~ hgt, data = bdims)
```

Instructions

**100 XP**

`mod`

(defined above) is available in your workspace.

- Confirm that the mean of the body weights equals the mean of the fitted values of
`mod`

. - Compute the mean of the residuals of
`mod`

.