Exercise

# Mapping the spatial effects

As with `glm`

, you can get the fitted values and residuals from your model using the
`fitted`

and `residuals`

functions. `bayesx`

models are a bit more complex, since you
have the linear predictor and terms from `sx`

elements, such as the spatially correlated
term.

The `summary`

function will show you information for the linear model terms and the smoothing terms
in two separate tables. The spatial term is called `"sx(i):mrf"`

- standing for "Markov Random Field".

Bayesian analysis returns samples from a *distribution* for our `S(x)`

term at each of the London boroughs. The `fitted`

function from `bayesx`

models returns summary statistics for each borough. You'll just look at the mean of that distribution for now.

Instructions

**100 XP**

The model from the BayesX output is available as `flu_spatial`

.

- Get a summary of the model and see where the parameter information is. Does the Health Deprivation parameter look significant?
- Add a column named
`spatial`

to`london`

with the mean of the distribution of the fitted spatial term, and map this. - Add another column, named
`spatial_resid`

, with the residuals.- Use the
`"mu"`

column from`residuals`

, as this is based on the rate rather than the number of cases, so can be compared across areas with different populations.

- Use the
- Plot a map of
`spatial_resid`

using`spplot()`

. - Run a Moran statistic Monte-Carlo test on the residuals - do they show spatial correlation?
- Call
`moran.mc()`

, passing the residual vector as the first argument.

- Call