The function supports three types of prediction. In-sample prediction is the computation of predictors on the data used to fit the model (newdata=NULL
). Prevision, also called forecast, is the computation of some predictors (“trend”, in-sample “TC” and out-of-sample “TS”) on the same spatial units than the ones used to fit the model, but with different observations of the variables in the model (row names of newdata
should have the same row names than the data frame used to fit the model). And out-of-sample prediction is the computation of predictors on other spatial units than the ones used to fit the model (newdata
has different row names). For extensive definitions, see Goulard et al. (2017).
pred.type
of predictors are available according to the model of object
an to the type of prediction. In the two following tables, “yes” means that the predictor can be used with the model, “no” means that predict.Sarlm()
will stop with an error, and “yes*” means that the predictor is not designed for the specified model, but it can be used with predict.Sarlm()
. In the last case, be careful with the computation of a inappropriate predictor.
In-sample predictors by models
pred.type | sem (mixed) | lag (mixed) | sac (mixed) |
| | | |
“trend” | yes | yes | yes |
“TS” | yes | yes | no |
“TC” | no | yes | yes* |
“BP” | no | yes | yes* |
Note that only “trend” and “TC” are available for prevision.
Out-of-sample predictors by models
pred.type | sem (mixed) | lag (mixed) | sac (mixed) |
| | | |
“trend” | yes | yes | yes |
“TS” | yes | yes | no |
“TS1” or “KP4” | no | yes | yes |
“TC” | no | yes | yes* |
“TC1” or “KP1” | yes | yes | yes |
“BP” | no | yes | yes* |
“BP1” | no | yes | yes* |
“BPW” | no | yes | yes* |
“BPW1” | no | yes | yes* |
“BN” | no | yes | yes* |
“BPN1” | no | yes | yes* |
“KP2” | yes | yes | yes |
“KP3” | yes | yes | yes |
“KP5” | yes | no | yes* |
Values for pred.type=
include “TS1”, “TC”, “TC1”, “BP”, “BP1”, “BPW”, “BPW1”, “BPN”, “BPN1”, following the notation in Goulard et al. (2017), and for pred.type=
“KP1”, “KP2”, “KP3”, “KP4”, “KP5”, following the notation in Kelejian et al. (2007). pred.type="TS"
is described bellow and in Bivand (2002).
In the following, the trend is the non-spatial smooth, the signal is the
spatial smooth, and the noise is the residual. The fit returned by pred.type="TS"
is the
sum of the trend and the signal.
When pred.type="TS"
, the function approaches prediction first by dividing invocations between
those with or without newdata. When no newdata is present, the response
variable may be reconstructed as the sum of the trend, the signal, and the
noise (residuals). Since the values of the response variable are known,
their spatial lags are used to calculate signal components (Cressie 1993, p. 564). For the error
model, trend = \(X \beta\), and signal = \(\lambda W y -
\lambda W X \beta\). For the lag and mixed
models, trend = \(X \beta\), and signal = \(\rho W y\).
This approach differs from the design choices made in other software, for
example GeoDa, which does not use observations of the response variable,
and corresponds to the newdata situation described below.
When however newdata is used for prediction, no observations of the response
variable being predicted are available. Consequently, while the trend
components are the same, the signal cannot take full account of the spatial
smooth. In the error model and Durbin error model, the signal is set to zero, since the spatial smooth is expressed in terms of the error:
\((I - \lambda W)^{-1} \varepsilon\).
In the lag model, the signal can be expressed in the following way (for legacy=TRUE):
$$(I - \rho W) y = X \beta + \varepsilon$$
$$y = (I - \rho W)^{-1} X \beta + (I - \rho W)^{-1} \varepsilon$$
giving a feasible signal component of:
$$\rho W y = \rho W (I - \rho W)^{-1} X \beta$$
For legacy=FALSE, the trend is computed first as:
$$X \beta$$
next the prediction using the DGP:
$$(I - \rho W)^{-1} X \beta$$
and the signal is found as the difference between prediction and trend. The numerical results for the legacy and DGP methods are identical.
setting the error term to zero. This also means that predictions of the
signal component for lag and mixed models require the inversion of an
n-by-n matrix.
Because the outcomes of the spatial smooth on the error term are
unobservable, this means that the signal values for newdata are
incomplete. In the mixed model, the spatially lagged RHS variables
influence both the trend and the signal, so that the root mean square
prediction error in the examples below for this case with newdata is
smallest, although the model was not the best fit.
If newdata
has more than one row, leave-one-out predictors (pred.type=
include “TS1”, “TC1”, “BP1”, “BPW1”, “BPN1”, “KP1”, “KP2”, “KP3”, “KP4”, “KP5”) are computed separatly on each out-of-sample unit.
listw
should be provided except if newdata=NULL
and pred.type=
include “TS”, “trend”, or if newdata
is not NULL
, pred.type="trend"
and object
is not a mixed model.
all.data
is useful when some out-of-sample predictors return different predictions for in-sample units, than the same predictor type computed only on in-sample data.