Regression models the mean relationship between an outcome and its predictors.
A basic linear model is
$$ y=X\beta+\varepsilon, $$
with
$$ E[\varepsilon]=0. $$
In ordinary introductory regression, errors are often treated as independent with common variance:
$$ \mathrm{Cov}(\varepsilon) = \sigma^2 I. $$
Spatial data often violate that assumption because nearby observations can have correlated unexplained variation.
A more general model is
$$ \boxed{ y=X\beta+\varepsilon, \qquad \mathrm{Cov}(\varepsilon)=\Sigma }. $$
Spatial regression becomes important when spatial structure remains after the mean relationship has been modeled.
After this chapter, you should be able to:
Suppose
$$ y_i $$
is an outcome observed at spatial location $s_i$, and
$$ x_i $$
is a predictor.
A linear mean model is
$$ E[y_i\mid X] = \beta_0+\beta_1x_i. $$
In matrix notation,
$$ E[y\mid X] = X\beta. $$
The residual is
$$ e_i = y_i-\hat y_i. $$
Spatial regression is useful when independent errors do not adequately represent the residual structure.
Residual spatial autocorrelation can appear when the mean model is missing systematic spatial structure.
Possible causes include:
These mechanisms have different scientific interpretations.
If the mean model is misspecified, a spatial covariance term can absorb variation that should have been explained by the predictors.

Suppose observations lie at positions
$$ s=0,1,2,3,4. $$
The true mean is
$$ m(s)=5+2s. $$
Suppose the observed values are
$$ y= \begin{bmatrix} 5.2\\ 7.1\\ 9.0\\ 11.2\\ 12.9 \end{bmatrix}. $$
If we incorrectly fit only an intercept, the fitted mean is
$$ \bar y = \frac{5.2+7.1+9.0+11.2+12.9}{5}. $$
The sum is
$$ 45.4, $$
so
$$ \bar y=9.08. $$
The residuals are
$$ -3.88,\ -1.98,\ -0.08,\ 2.12,\ 3.82. $$
These residuals are strongly spatially patterned.
But if we fit the spatial trend
$$ 5+2s, $$
the residuals become approximately
$$ 0.2,\ 0.1,\ 0.0,\ 0.2,\ -0.1. $$
Most of the apparent spatial dependence disappears once the mean structure is modeled correctly.
The OLS estimator is
$$ \boxed{ \hat\beta_{\text{OLS}} = (X^\top X)^{-1}X^\top y }. $$
A common misunderstanding is:
Spatially correlated errors automatically make OLS coefficients biased.
That is not generally true.
If
$$ E[\varepsilon\mid X]=0 $$
and the mean model is correctly specified, OLS can still be unbiased for $\beta$.
However, when the error covariance is non-spherical:
$$ \mathrm{Cov}(\varepsilon)=\Sigma\neq\sigma^2I, $$
OLS is generally:
Under
$$ y=X\beta+\varepsilon $$
with
$$ \mathrm{Cov}(\varepsilon)=\Sigma, $$
the OLS estimator still has
$$ E[\hat\beta_{\text{OLS}}]=\beta $$
under exogeneity.
Its covariance is
$$ \boxed{ \mathrm{Cov}(\hat\beta_{\text{OLS}}) = (X^\top X)^{-1} X^\top\Sigma X (X^\top X)^{-1} }. $$
The familiar formula
$$ \sigma^2(X^\top X)^{-1} $$
is only correct under the much simpler covariance assumption
$$ \Sigma=\sigma^2I. $$
This distinction is fundamental.
Suppose two nearby observations are extremely similar because their errors are strongly correlated.
They do not contain as much independent information as two equally precise observations whose errors are independent.
Ignoring this redundancy often makes the estimated uncertainty too small.
This parallels the logic of kriging: nearby observations can be informative about the same local process, but they can also be redundant.

For point-referenced spatial regression, one common covariance model is
$$ \Sigma_{ij} = \sigma_s^2 \exp\left( -\frac{d_{ij}}{a} \right) + \sigma_n^2 I(i=j), $$
where
For nearby locations, $d_{ij}$ is small, so the spatial covariance is large.
As distance increases, the spatial covariance decreases.
Suppose
$$ \sigma_s^2=4, \qquad a=2, \qquad \sigma_n^2=1. $$
For two different locations 1 unit apart,
$$ \Sigma_{ij} = 4e^{-1/2}. $$
Since
$$ e^{-1/2}\approx0.6065, $$
$$ \Sigma_{ij} \approx 4(0.6065) = 2.426. $$
At the same location,
$$ \Sigma_{ii} = 4+1 = 5. $$
Therefore the corresponding correlation at distance 1 is approximately
$$ \frac{2.426}{5} = 0.485. $$
The errors therefore have substantial correlation at this distance.
If the covariance matrix $\Sigma$ is known, generalized least squares is
$$ \boxed{ \hat\beta_{\text{GLS}} = (X^\top\Sigma^{-1}X)^{-1} X^\top\Sigma^{-1}y }. $$
If
$$ \Sigma=\sigma^2I, $$
then
$$ \Sigma^{-1} = \frac1{\sigma^2}I, $$
and the constant factor cancels.
GLS therefore reduces to OLS in this special case.
OLS minimizes
$$ (y-X\beta)^\top(y-X\beta). $$
This is the ordinary unweighted sum of squared residuals.
GLS minimizes
$$ \boxed{ (y-X\beta)^\top \Sigma^{-1} (y-X\beta) }. $$
The inverse covariance matrix adjusts the fitting criterion for:
Directions in the residual space with greater redundancy receive less effective weight.
Suppose $L$ satisfies
$$ LL^\top=\Sigma. $$
For example, $L$ can be a Cholesky factor.
Define transformed data
$$ y^*=L^{-1}y $$
and
$$ X^*=L^{-1}X. $$
Then
$$ y^ = X^\beta+\varepsilon^* $$
with
$$ \mathrm{Cov}(\varepsilon^*)=I. $$
GLS is exactly OLS applied to the whitened data:
$$ \hat\beta_{\text{GLS}} = (X^{\top}X^)^{-1}X^{\top}y^. $$
This whitening view is often the clearest way to understand GLS.
Consider three observations.
The design matrix is
$$ X= \begin{bmatrix} 1&0\\ 1&1\\ 1&2 \end{bmatrix} $$
and the outcome is
$$ y= \begin{bmatrix} 1\\ 2\\ 4 \end{bmatrix}. $$
The first column is the intercept, and the second is the predictor.
First calculate
$$ X^\top X. $$
We obtain
$$ X^\top X = \begin{bmatrix} 3&3\\ 3&5 \end{bmatrix}. $$
Also,
$$ X^\top y = \begin{bmatrix} 7\\ 10 \end{bmatrix}. $$
The inverse is
$$ (X^\top X)^{-1} = \frac1{6} \begin{bmatrix} 5&-3\\ -3&3 \end{bmatrix}. $$
Therefore
$$ \hat\beta_{\text{OLS}} = (X^\top X)^{-1}X^\top y. $$
Substitute:
$$ \hat\beta_{\text{OLS}} = \frac1{6} \begin{bmatrix} 5&-3\\ -3&3 \end{bmatrix} \begin{bmatrix} 7\\ 10 \end{bmatrix}. $$
The intercept is
$$ \frac{35-30}{6} = \frac56 \approx0.833. $$
The slope is
$$ \frac{-21+30}{6} = \frac96 = 1.5. $$
Thus
$$ \boxed{ \hat\beta_{\text{OLS}} = \begin{bmatrix} 0.833\\ 1.500 \end{bmatrix} }. $$
Suppose the covariance matrix is
$$ \Sigma = \begin{bmatrix} 1 & 0.6 & 0.2\\ 0.6 & 1 & 0.6\\ 0.2 & 0.6 & 1 \end{bmatrix}. $$
This is a positive-definite covariance matrix in which adjacent observations have strongly correlated errors.
Its inverse is approximately
$$ \Sigma^{-1} = \begin{bmatrix} 1.6667 & -1.2500 & 0.4167\\ -1.2500 & 2.5000 & -1.2500\\ 0.4167 & -1.2500 & 1.6667 \end{bmatrix}. $$
Now calculate
$$ X^\top\Sigma^{-1}X \approx \begin{bmatrix} 1.6667 & 1.6667\\ 1.6667 & 4.1667 \end{bmatrix} $$
and
$$ X^\top\Sigma^{-1}y \approx \begin{bmatrix} 4.1667\\ 7.9167 \end{bmatrix}. $$
Therefore
$$ \hat\beta_{\text{GLS}} = (X^\top\Sigma^{-1}X)^{-1} X^\top\Sigma^{-1}y $$
gives
$$ \boxed{ \hat\beta_{\text{GLS}} = \begin{bmatrix} 1.000\\ 1.500 \end{bmatrix} }. $$
In this example the slope happens to remain 1.5, while the intercept changes from the OLS estimate $0.833$ to $1.000$.
That is specific to this small example and should not be treated as a general result.
The key point is that GLS changes how observations are combined by accounting for error covariance.
Under the correctly specified covariance model, the GLS covariance is
$$ \boxed{ \mathrm{Cov}(\hat\beta_{\text{GLS}}) = (X^\top\Sigma^{-1}X)^{-1} }. $$
Under the assumed covariance model, GLS is the efficient linear unbiased estimator.
In repeated samples, OLS and GLS may both be centered on the true coefficient, while GLS has smaller sampling variance.

In real applications, $\Sigma$ is almost never known exactly.
Instead, its parameters must be estimated.
The workflow is then roughly:
This is often called feasible GLS.
Uncertainty should ideally account for the fact that $\Sigma$ was estimated rather than known.
The companion simulation uses the true $\Sigma$ only as a teaching device.
For areal data, spatial dependence is often represented through a spatial weights matrix $W$.
A spatial error model can be written
$$ y=X\beta+u, $$
with
$$ u=\lambda Wu+\varepsilon. $$
Rearrange:
$$ (I-\lambda W)u=\varepsilon. $$
Therefore
$$ \boxed{ u=(I-\lambda W)^{-1}\varepsilon }. $$
The parameter
$$ \lambda $$
describes spatial dependence in the disturbance process.
A local shock in $\varepsilon$ can propagate through the disturbance process.
This can represent:
It does not imply that neighboring observed outcomes directly cause one another.

Suppose three regions are arranged in a line:
$$ A-B-C. $$
Use row-standardized weights
$$ W= \begin{bmatrix} 0&1&0\\ 1/2&0&1/2\\ 0&1&0 \end{bmatrix}. $$
Let
$$ \lambda=0.4. $$
Suppose the independent innovations are
$$ \varepsilon= \begin{bmatrix} 1\\ 0\\ 0 \end{bmatrix}. $$
Then
$$ u = (I-0.4W)^{-1}\varepsilon. $$
Numerically,
$$ u \approx \begin{bmatrix} 1.095\\ 0.238\\ 0.095 \end{bmatrix}. $$
A shock originating in region A creates correlated disturbance components in B and C.
The propagation occurs in the error process.
A spatial autoregressive outcome model is
$$ \boxed{ y=\rho Wy+X\beta+\varepsilon }. $$
The term
$$ Wy $$
is the spatial lag of the outcome.
Rearrange:
$$ (I-\rho W)y = X\beta+\varepsilon. $$
Therefore
$$ \boxed{ y = (I-\rho W)^{-1} (X\beta+\varepsilon) }. $$
The matrix
$$ (I-\rho W)^{-1} $$
is called the spatial multiplier.
In the SAR model,
$$ Wy $$
contains neighboring outcomes.
But those neighboring outcomes are themselves determined simultaneously by:
$$ y=\rho Wy+X\beta+\varepsilon. $$
Therefore $Wy$ is generally correlated with the disturbance term.
This creates an endogeneity problem.
Ordinary OLS applied directly to
$$ y=\rho Wy+X\beta+\varepsilon $$
does not generally estimate $\rho$ consistently.
SAR models therefore require methods designed for the simultaneous spatial system, such as maximum likelihood or suitable instrumental-variable or GMM methods.
It is tempting to interpret
$$ \rho Wy $$
as if neighboring outcomes were an ordinary predictor.
But $Wy$ is endogenous because it is constructed from the same jointly determined outcome vector.
The model determines all locations simultaneously.
This changes both estimation and interpretation.
Suppose there is one predictor $x$:
$$ y = \rho Wy+\beta x+\varepsilon. $$
Then
$$ E[y\mid x] = (I-\rho W)^{-1}\beta x. $$
The derivative of expected outcomes with respect to $x$ is
$$ \boxed{ \frac{\partial E[y]}{\partial x^\top} = (I-\rho W)^{-1}\beta }. $$
The result is a matrix.
Its diagonal entries describe effects on the same location.
Its off-diagonal entries describe spillover effects on other locations.
Again use
$$ A-B-C $$
with
$$ W= \begin{bmatrix} 0&1&0\\ 1/2&0&1/2\\ 0&1&0 \end{bmatrix}. $$
Let
$$ \rho=0.4 $$
and
$$ \beta=2. $$
Then
$$ S = (I-0.4W)^{-1}. $$
Numerically,
$$ S \approx \begin{bmatrix} 1.095 & 0.476 & 0.095\\ 0.238 & 1.190 & 0.238\\ 0.095 & 0.476 & 1.095 \end{bmatrix}. $$
Multiply by
$$ \beta=2. $$
The impact matrix is approximately
$$ 2S = \begin{bmatrix} 2.190 & 0.952 & 0.190\\ 0.476 & 2.381 & 0.476\\ 0.190 & 0.952 & 2.190 \end{bmatrix}. $$
Suppose $x_A$ increases by one unit.
The first column of the impact matrix gives the effect:
$$ \Delta E[y] \approx \begin{bmatrix} 2.190\\ 0.476\\ 0.190 \end{bmatrix}. $$
So:
The ordinary coefficient
$$ \beta=2 $$
is therefore not, by itself, the total effect at A or across the system.

A significant Moran statistic on OLS residuals indicates that spatial structure remains in the residuals.
It does not, by itself, identify which spatial model should be used.
Several explanations are possible.
Maybe a spatially varying covariate was omitted.
Maybe unobserved disturbances are spatially correlated.
Maybe the scientific mechanism genuinely implies simultaneous outcome spillovers.
For point-referenced data, a distance-based covariance model may be more natural than a discrete $W$.
Model choice should follow the scientific mechanism and data support, not only the residual Moran statistic.
Before adding a spatial dependence term, ask:
The answers help narrow the appropriate model class.
Spatial predictors often vary smoothly over space.
Latent spatial effects also vary smoothly.
The two components can therefore explain similar spatial patterns in the outcome.
Suppose
$$ y(s) = \beta x(s) + u(s) + \varepsilon(s), $$
where
If $x(s)$ and $u(s)$ have similar spatial scales, the model may struggle to decide which component should explain a broad spatial pattern.
This is called spatial confounding.

A coefficient estimate can change when we change:
This does not automatically mean that the spatial model is wrong.
It means that the predictor and latent spatial effect are competing to explain similar variation.
Coefficient interpretation should therefore be accompanied by sensitivity analysis.
Suppose an observational study estimates
$$ y = \beta x + \text{spatial random effect} + \varepsilon. $$
Modeling spatial autocorrelation can improve:
But it does not automatically solve problems such as:
Causal interpretation requires a separate identification argument.
After fitting a spatial model, the diagnostics should match the model structure.
For a standard OLS fit, inspect ordinary residuals.
For a GLS model,
$$ e=y-X\hat\beta_{\text{GLS}} $$
can still be spatially correlated because the model explicitly says the errors have covariance $\Sigma$.
It is therefore often useful to inspect whitened residuals:
$$ e^* = L^{-1}e, \qquad LL^\top=\Sigma. $$
If the covariance model is adequate, $e^*$ should be much closer to uncorrelated noise.

An important point:
A good GLS model does not necessarily make the raw residual map look spatially independent.
The raw residuals are estimates of a process that the model explicitly allows to be spatially correlated.
The more relevant question is whether the remaining unexplained structure, after accounting for the fitted covariance, is compatible with the model.
Whitened or innovation residuals provide one way to check this.
For point-referenced regression, another useful diagnostic is the residual variogram.
After fitting the mean model, calculate residuals
$$ e_i=y_i-\hat y_i. $$
Then examine whether residual semivariance changes with distance.
If strong structure remains and was not included in the covariance model, the model may be incomplete.
Spatial dependence and heteroskedasticity are separate features of the error structure.
A model can have:
Therefore residual diagnostics should inspect both:
Spatial data can contain influential observations.
An observation may be influential because it has:
Influence diagnostics should therefore be interpreted together with the observation's spatial location.
A model can predict well because location acts as a proxy for omitted processes.
That does not mean its regression coefficients have strong scientific interpretations.
For example, a flexible spatial effect may absorb most of the broad pattern and yield excellent prediction.
But the estimated coefficient for a smooth exposure may become unstable.
Prediction asks:
Can we accurately estimate outcomes at new locations?
Parameter inference asks:
What does $\beta$ tell us about the relationship between predictors and outcome?
These goals can conflict.
Suppose nearby locations are strongly correlated.
In ordinary random cross-validation, a held-out point may still have training observations only a short distance away.
A spatial model may predict it very well using nearby information.
But if the deployment task is to predict in a new geographic region, that validation result may be much too optimistic.
Use spatially blocked validation when geographic transfer is the actual prediction goal.

If the goal is coefficient inference, compare:
If the goal is spatial prediction, compare:
Do not choose a model only because it has the smallest in-sample residual sum of squares.
A practical spatial-regression analysis can proceed as follows.
Decide whether data are:
Map:
Check:
Use:
Possibilities include:
Do not fit an endogenous SAR lag with ordinary OLS.
Use:
Check sensitivity to:
Use spatial validation when extrapolation across space matters.
The spatial term may absorb an omitted trend.
Under correct mean specification and exogeneity, OLS can remain unbiased, although usual OLS standard errors are generally invalid and OLS is inefficient.
It describes dependence in the disturbance process.
$Wy$ is generally endogenous.
Effects propagate through
$$ (I-\rho W)^{-1}. $$
The fitted covariance model explicitly allows correlation in the raw residual process.
Causal identification requires more than residual spatial adjustment.
Nearby training observations can make performance look unrealistically good.
Suppose the true data-generating model is
$$ y_i = 3+1.5x_i+\varepsilon_i $$
with
$$ \mathrm{Cov}(\varepsilon_i,\varepsilon_j) = 2e^{-d_{ij}/5}. $$
An OLS fit gives
$$ \hat\beta_1=1.47. $$
The coefficient can be close to the true value because the mean model is correctly specified.
However, the naive OLS standard error assumes independent errors and reports
$$ SE_{\text{naive}}=0.08. $$
A covariance-aware analysis gives
$$ SE=0.18. $$
The main problem with the naive analysis is not necessarily the point estimate.
It is the claim of excessive precision.
The logic is
$$ \text{spatial outcome + predictors} $$
$$ \downarrow $$
$$ \text{specify mean }X\beta $$
$$ \downarrow $$
$$ \text{diagnose residual spatial structure} $$
$$ \downarrow $$
$$ \text{ask why dependence remains} $$
$$ \downarrow $$
$$ \begin{array}{ccc} \text{continuous covariance} & \text{spatial error} & \text{SAR/lag} \end{array} $$
$$ \downarrow $$
$$ \text{fit with an estimator appropriate to that structure} $$
$$ \downarrow $$
$$ \text{inspect model-appropriate residuals} $$
$$ \downarrow $$
$$ \text{separate coefficient inference from prediction}. $$
The central lesson is:
Spatial regression is not one model. It is a family of strategies for separating the mean relationship from spatially structured residual or outcome dependence.