Exercise

# Residuals

A linear model should fit the data and leave uncorrelated residuals. This applies to non-spatial models, where, for example, fitting a straight line through points on a curve would lead to serially-correlated residuals. A model on spatial data should aim to have residuals that show no significant spatial correlation.

You can test the model fitted to the flu data using `moran.mc()`

from the `spdep`

package. Monte Carlo Moran tests were previously discussed in the *Spatial autocorrelation test* exercise earlier in the chapter.

Instructions

**100 XP**

The `london`

data is loaded, and has a column `Flu_Resid`

which has the residuals from the model.

Compute the neighborhood structure from the London map data.

- Call
`poly2nb()`

on the`london`

dataset. - Assign the result to
`borough_nb`

.

- Call
Run a Monte-Carlo Moran test on the correlation of the model residuals.

- Call
`moran.mc()`

. - The first argument is the residuals column of the
`london`

data, named`Flu_Resid`

. - The second argument is the neighborhood structure, converted to a weighted neighbor list object using
`nb2listw()`

. - Pass
`nsim = 999`

to run 999 iterations of the simulation. *Are the residuals spatially correlated?*

- Call