Residual
Study guides: Exam MAS-I, Exam MAS-II
A Residual is the difference between an observed response and the fitted value a model gives it. The residual of observation i is
e_i = y_i - \hat{y}_i
y_iis the observed response, and\hat{y}_iis its fitted value.
A residual is the observable estimate of the model's error \varepsilon_i. In a least squares fit with an intercept the residuals sum to zero, and the sum of their squares is the residual sum of squares. Every model diagnostic, such as the residual plot and the QQ plot, looks for structure left in the residuals.
A fitted line is
\hat = 2.3 + 0.5x. An observation hasx = 4andy = 3.9. What is its residual?
- The fitted value is
2.3 + 0.5(4) = 4.3.- The residual is
3.9 - 4.3 = -0.4. It is negative because the observation lies below the fitted line.
Standardized residuals and Cook's distance
In linear regression the variance of the residual e_i is \sigma^2(1 - h_{ii}), where h_{ii} is the leverage of observation i. The standardized residual divides each residual by its estimated standard deviation:
r_i = \frac{e_i}{\hat\sigma \sqrt{1 - h_{ii}}}
\hat\sigma^2 = \text{RSS}/(n - p - 1)is the estimate of the error variance.
The studentized residual uses an estimate of \sigma computed without observation i. A standardized or studentized residual greater than 3 in absolute value flags a possible outlier. Cook's distance measures the influence of observation i by combining its standardized residual with its leverage:
D_i = \frac{r_i^2}{p + 1} \cdot \frac{h_{ii}}{1 - h_{ii}}
p + 1is the number of coefficients including the intercept, which is 2 in simple linear regression.
An observation with D_i greater than 1 is usually treated as influential.
A simple linear regression has
\hat\sigma = 0.6. Observations A and B both have residual0.5, with leverages0.20and0.92. What are their standardized residuals and Cook's distances?
- For A,
r_A = 0.5/(0.6\sqrt{0.80}) = 0.93, andD_A = \frac{0.93^2}{2} \cdot \frac{0.20}{0.80} = 0.11.- For B,
r_B = 0.5/(0.6\sqrt{0.08}) = 2.95, andD_B = \frac{2.95^2}{2} \cdot \frac{0.92}{0.08} = 49.9.- The raw residuals are equal, but B's leverage pulls the fit toward it, so its residual is large relative to its standard deviation and B is highly influential.
Pearson and deviance residuals
In a generalized linear model the variance of the response depends on its mean, so raw residuals are not comparable across observations. The Pearson residual divides the raw residual by the standard deviation the model assumes:
r_i^{P} = \frac{y_i - \hat\mu_i}{\sqrt{V(\hat\mu_i)}}
\hat\mu_iis the fitted mean, andVis the variance function.
The sum of the squared Pearson residuals is the Pearson \chi^2 statistic, and dividing it by the residual degrees of freedom estimates the dispersion parameter \phi. Because Pearson residuals are standardized, one that is large in absolute value flags an unusual observation. The deviance residual is
r_i^{D} = \text{sign}(y_i - \hat\mu_i)\sqrt{d_i}
d_iis observationi's contribution to the deviance, so the squared deviance residuals sum toD.
For a Poisson model, observation i's contribution to the deviance is
d_i = 2\left[y_i \ln\frac{y_i}{\hat\mu_i} - (y_i - \hat\mu_i)\right]
- The term
y_i \ln(y_i/\hat\mu_i)is taken as 0 wheny_i = 0.
If the model's distribution is right, the deviance residuals of a continuous response are close to normal, so a QQ plot of them that follows the reference line shows no departure from the assumed distribution.
A Poisson model gives two policies the fitted mean 1.2. One had 3 claims and the other none. What are their Pearson and deviance residuals?
- For
y = 3,r^P = (3 - 1.2)/\sqrt{1.2} = 1.643.- For
y = 3,d = 2[3 \ln(3/1.2) - 1.8] = 1.898, sor^D = \sqrt{1.898} = 1.378.- For
y = 0,r^P = -1.2/\sqrt{1.2} = -1.095.- For
y = 0,d = 2(1.2) = 2.4, sor^D = -\sqrt{2.4} = -1.549.
Residuals of a linear mixed model
In a linear mixed model \mathbf{y} = \mathbf{X}\boldsymbol\beta + \mathbf{Z}\mathbf{b} + \boldsymbol\varepsilon, the conditional errors \boldsymbol\varepsilon have covariance matrix \mathbf{R}, and the marginal errors \mathbf{Z}\mathbf{b} + \boldsymbol\varepsilon have covariance matrix
\mathbf{V} = \mathbf{Z}\mathbf{D}\mathbf{Z}^T + \mathbf{R}
\mathbf{Z}is the design matrix of the random effects\mathbf{b}, and\mathbf{D}is their covariance matrix.
The marginal residuals \mathbf{y} - \mathbf{X}\hat{\boldsymbol\beta} and the conditional residuals \mathbf{y} - \mathbf{X}\hat{\boldsymbol\beta} - \mathbf{Z}\hat{\mathbf{b}} are checked against this covariance structure. With one random intercept per subject, \mathbf{Z}_i is a column of ones and \mathbf{D} is the between-subject variance \sigma_b^2.
A random-intercept model has
\sigma_b^2 = 40and independent conditional errors with\sigma^2 = 160. What covariance matrix does it imply for one subject's three marginal errors, and what is their correlation?
\mathbf{Z}_i \mathbf{D} \mathbf{Z}_i^Tis40in every entry, and\mathbf{R}_i = 160\,\mathbf{I}.
\mathbf{V}_i = \begin{bmatrix} 200 & 40 & 40 \\ 40 & 200 & 40 \\ 40 & 40 & 200 \end{bmatrix}
- The intraclass correlation between any two errors of the subject is
40/200 = 0.20.
Residuals of a time series model
The residuals of a time series model such as an ARIMA model are its one-step-ahead forecast errors:
e_t = y_t - \hat{y}_{t \mid t-1}
\hat{y}_{t \mid t-1}is the forecast ofy_tmade from the observations up to timet - 1.
If the model has captured the dependence in the series, its residuals are white noise, and no autocorrelation of the residuals in the correlogram lies outside \pm 1.96/\sqrt{n}.
The residuals of a model fitted to 100 observations have lag-3 autocorrelation 0.25 and no other large autocorrelation. Are they white noise?
- The bounds are
\pm 1.96/\sqrt{100} = \pm 0.196.- The lag-3 autocorrelation of 0.25 lies outside the bounds, so the residuals are not white noise.
- The model has missed dependence at lag 3.