Learn R Programming

spdep (version 0.5-74)

errorsarlm: Spatial simultaneous autoregressive error model estimation

Description

Maximum likelihood estimation of spatial simultaneous autoregressive error models of the form:

$$y = X \beta + u, u = \lambda W u + \varepsilon$$

where $\lambda$ is found by optimize() first, and $\beta$ and other parameters by generalized least squares subsequently. With one of the sparse matrix methods, larger numbers of observations can be handled, but the interval= argument may need be set when the weights are not row-standardised. When etype is emixed, a so-called spatial Durbin error model is fitted, while lmSLX fits an lm model augmented with the spatially lagged RHS variables, including the lagged intercept when the spatial weights are not row-standardised. create_WX creates spatially lagged RHS variables, and is exposed for use in model fitting functions.

Usage

errorsarlm(formula, data=list(), listw, na.action, etype="error",
 method="eigen", quiet=NULL, zero.policy=NULL,
 interval = NULL, tol.solve=1.0e-10, trs=NULL, control=list())
lmSLX(formula, data = list(), listw, na.action, zero.policy=NULL)
create_WX(x, listw, zero.policy=NULL, prefix="")

Arguments

formula
a symbolic description of the model to be fit. The details of model specification are given for lm()
data
an optional data frame containing the variables in the model. By default the variables are taken from the environment which the function is called.
listw
a listw object created for example by nb2listw
na.action
a function (default options("na.action")), can also be na.omit or na.exclude with consequences for residuals and fitted values - in these cases the weights list will be subsetted to remove NAs in the data. It may be
etype
default "error", may be set to "emixed" to include the spatially lagged independent variables added to X; when "emixed", the lagged intercept is dropped for spatial weights style "W", that is row-standardised weights, but otherwise included
method
"eigen" (default) - the Jacobian is computed as the product of (1 - rho*eigenvalue) using eigenw, and "spam" or "Matrix_J" for strictly symmetric weights lists of styles "B" and "C", or made symmetric by similarity (Ord, 1975, Appendix C) if
quiet
default NULL, use !verbose global option value; if FALSE, reports function values during optimization.
zero.policy
default NULL, use global option value; if TRUE assign zero to the lagged value of zones without neighbours, if FALSE assign NA - causing errorsarlm() to terminate with an error
interval
default is NULL, search interval for autoregressive parameter
tol.solve
the tolerance for detecting linear dependencies in the columns of matrices to be inverted - passed to solve() (default=1.0e-10). This may be used if necessary to extract coefficient standard errors (for instance lowering to 1e-12), but errors
trs
default NULL, if given, a vector of powered spatial weights matrix traces output by trW; when given, insert the asymptotic analytical values into the numerical Hessian instead of the approximated values; may be used to get around some problem
control
list of extra control arguments - see section below
x
model matrix to be lagged
prefix
default empty string, may be lag in some cases

Value

  • A list object of class sarlm
  • type"error"
  • lambdasimultaneous autoregressive error coefficient
  • coefficientsGLS coefficient estimates
  • rest.seGLS coefficient standard errors (are equal to asymptotic standard errors)
  • LLlog likelihood value at computed optimum
  • s2GLS residual variance
  • SSEsum of squared GLS errors
  • parametersnumber of parameters estimated
  • logLik_lm.modelLog likelihood of the linear model for $\lambda=0$
  • AIC_lm.modelAIC of the linear model for $\lambda=0$
  • coef_lm.modelcoefficients of the linear model for $\lambda=0$
  • tarXmodel matrix of the GLS model
  • taryresponse of the GLS model
  • yresponse of the linear model for $\lambda=0$
  • Xmodel matrix of the linear model for $\lambda=0$
  • methodthe method used to calculate the Jacobian
  • callthe call used to create this object
  • residualsGLS residuals
  • optobject returned from numerical optimisation
  • fitted.valuesDifference between residuals and response variable
  • aseTRUE if method=eigen
  • se.fitNot used yet
  • lambda.seif ase=TRUE, the asymptotic standard error of $\lambda$
  • LMtestNULL for this model
  • aliasedif not NULL, details of aliased variables
  • LLNullLlmLog-likelihood of the null linear model
  • HcovSpatial DGP covariance matrix for Hausman test if available
  • intervalline search interval
  • fdHessfinite difference Hessian
  • optimHessoptim or fdHess used
  • insertlogical; is TRUE, asymptotic values inserted in fdHess where feasible
  • timingsprocessing timings
  • f_callsnumber of calls to the log likelihood function during optimization
  • hf_callsnumber of calls to the log likelihood function during numerical Hessian computation
  • intern_classica data frame of detval matrix row choices used by the SE toolbox classic method
  • zero.policyzero.policy for this model
  • na.action(possibly) named vector of excluded or omitted observations if non-default na.action argument used
  • The internal sar.error.* functions return the value of the log likelihood function at $\lambda$.

    The lmSLX function returns an lm object.

Details

The asymptotic standard error of $\lambda$ is only computed when method=eigen, because the full matrix operations involved would be costly for large n typically associated with the choice of method="spam" or "Matrix". The same applies to the coefficient covariance matrix. Taken as the asymptotic matrix from the literature, it is typically badly scaled, being block-diagonal, and with the elements involving $\lambda$ being very small, while other parts of the matrix can be very large (often many orders of magnitude in difference). It often happens that the tol.solve argument needs to be set to a smaller value than the default, or the RHS variables can be centred or reduced in range.

Note that the fitted() function for the output object assumes that 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). This differs from other software, including GeoDa, which does not use knowledge of the response variable in making predictions for the fitting data.

References

Cliff, A. D., Ord, J. K. 1981 Spatial processes, Pion; Ord, J. K. 1975 Estimation methods for models of spatial interaction, Journal of the American Statistical Association, 70, 120-126; Anselin, L. 1988 Spatial econometrics: methods and models. (Dordrecht: Kluwer); Anselin, L. 1995 SpaceStat, a software program for the analysis of spatial data, version 1.80. Regional Research Institute, West Virginia University, Morgantown, WV; Anselin L, Bera AK (1998) Spatial dependence in linear regression models with an introduction to spatial econometrics. In: Ullah A, Giles DEA (eds) Handbook of applied economic statistics. Marcel Dekker, New York, pp. 237-289; Cressie, N. A. C. 1993 Statistics for spatial data, Wiley, New York; LeSage J and RK Pace (2009) Introduction to Spatial Econometrics. CRC Press, Boca Raton.

See Also

lm, lagsarlm, similar.listw, summary.sarlm, predict.sarlm, residuals.sarlm, do_ldet

Examples

Run this code
data(oldcol)
lw <- nb2listw(COL.nb, style="W")
COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="eigen", quiet=FALSE)
summary(COL.errW.eig, correlation=TRUE)
ev <- eigenw(similar.listw(lw))
COL.errW.eig_ev <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="eigen", control=list(pre_eig=ev))
all.equal(coefficients(COL.errW.eig), coefficients(COL.errW.eig_ev))
COL.errB.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 nb2listw(COL.nb, style="B"), method="eigen", quiet=FALSE)
summary(COL.errB.eig, correlation=TRUE)
W <- as(as_dgRMatrix_listw(nb2listw(COL.nb)), "CsparseMatrix")
trMatc <- trW(W, type="mult")
COL.errW.M <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="Matrix", quiet=FALSE, trs=trMatc)
summary(COL.errW.M, correlation=TRUE)
COL.SDEMW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="eigen", etype="emixed")
summary(COL.SDEMW.eig, correlation=TRUE)
COL.SLX <- lmSLX(CRIME ~ INC + HOVAL, data=COL.OLD, listw=lw)
summary(COL.SLX)
COL.SLX <- lmSLX(CRIME ~ INC + HOVAL + I(HOVAL^2), data=COL.OLD, listw=lw)
summary(COL.SLX)
crds <- cbind(COL.OLD$X, COL.OLD$Y)
mdist <- sqrt(sum(diff(apply(crds, 2, range))^2))
dnb <- dnearneigh(crds, 0, mdist)
dists <- nbdists(dnb, crds)
f <- function(x, form, data, dnb, dists, verbose) {
  glst <- lapply(dists, function(d) 1/(d^x))
  lw <- nb2listw(dnb, glist=glst, style="B")
  res <- logLik(lmSLX(form=form, data=data, listw=lw))
  if (verbose) cat("power:", x, "logLik:", res, "\n")
  res
}
opt <- optimize(f, interval=c(0.1, 4), form=CRIME ~ INC + HOVAL,
 data=COL.OLD, dnb=dnb, dists=dists, verbose=TRUE, maximum=TRUE)
glst <- lapply(dists, function(d) 1/(d^opt$maximum))
lw <- nb2listw(dnb, glist=glst, style="B")
SLX <- lmSLX(CRIME ~ INC + HOVAL, data=COL.OLD, listw=lw)
summary(SLX)
NA.COL.OLD <- COL.OLD
NA.COL.OLD$CRIME[20:25] <- NA
COL.err.NA <- errorsarlm(CRIME ~ INC + HOVAL, data=NA.COL.OLD,
 nb2listw(COL.nb), na.action=na.exclude)
COL.err.NA$na.action
COL.err.NA
resid(COL.err.NA)
system.time(COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="eigen"))
system.time(COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="eigen", control=list(LAPACK=TRUE)))
system.time(COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="eigen", control=list(compiled_sse=TRUE)))
system.time(COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="Matrix_J", control=list(super=TRUE)))
system.time(COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="Matrix_J", control=list(super=FALSE)))
system.time(COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="Matrix_J", control=list(super=as.logical(NA))))
system.time(COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="Matrix", control=list(super=TRUE)))
system.time(COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="Matrix", control=list(super=FALSE)))
system.time(COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="Matrix", control=list(super=as.logical(NA))))
system.time(COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="spam", control=list(spamPivot="MMD")))
system.time(COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="spam", control=list(spamPivot="RCM")))
system.time(COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="spam_update", control=list(spamPivot="MMD")))
system.time(COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
 lw, method="spam_update", control=list(spamPivot="RCM")))

Run the code above in your browser using DataLab