[R-sig-Geo] Fitting a SAR model with no covariates
Roger Bivand
Roger@B|v@nd @end|ng |rom nhh@no
Sat May 9 17:17:57 CEST 2020
On Fri, 8 May 2020, Julian M. Burgos wrote:
> Dear list,
>
> I am trying to fit a very simple spatial autoregressive (SAR) model to
> measure the degree of spatial correlation in some dataset. The data
> consists of location (x, y) and some environmental parameter. The model
> I want to fit is of the form
>
> y = rho * W * y + e
>
> where y is a vector with the values of the environmental parameter, W is
> the matrix of spatial weights given by the inverse of squared distances
> among locations, rho is the autoregressive coefficient, and e is an
> error term. The model does not have any covariates.
>
> I can get W (as a listw object) using the chooseCN function from the
> adelspatial package, doing something like this:
>
> #---------------------------------------------------
> data(OLD.COL)
> xy <- as.matrix(COL.OLD[, c("X", "Y")])
>
> W <- chooseCN(xy = xy, ask = FALSE, type = 7, dmin = 1,
> plot.nb = FALSE, a = 2)
> #---------------------------------------------------
>
> But then I am a bit confused about how to fit the model itself using
> some of the functions from the spatialreg package, in particular because
> my model does not have covariates. The only thing I want to obtain is
> the rho parameter.
Please see the full reprex I provided for a direct questioner who prefered
to post on OpenSpace rather than here:
https://groups.google.com/forum/#!topic/openspace-list/RCYcrEcxDWg. In
your case:
data(oldcol, package="spdep")
xy <- as.matrix(COL.OLD[, c("X", "Y")])
listw <- adespatial::chooseCN(xy=xy, ask=FALSE, type=7, dmin=1,
plot.nb=FALSE, a=2)
listw
library(spatialreg)
(sar_intercept <- lagsarlm(CRIME ~ 1, data=COL.OLD, listw=listw))
which fails because adespatial::chooseCN() does not construct an spdep
compliant listw object. Further, it is almost completely dense, so always
a very bad choice (see Tony Smith's article
https://doi.org/10.1111/j.1538-4632.2009.00758.x).
dnb <- dnearneigh(xy, 0, 100)
dists <- nbdists(dnb, xy)
dists_idw2 <- lapply(dists, function(x) 1/(x^2))
listw1 <- nb2listw(dnb, glist=dists_idw2, style="W")
all.equal(listw$weights, listw1$weights, check.attributes=FALSE)
(sar_intercept <- lagsarlm(CRIME ~ 1, data=COL.OLD, listw=listw1))
and so on following the reply on OpenSpace.
You cannot fit a no-covariate, no-intercept model of this kind. You can
centre the response and estimate a (close-to) zero intercept model. If you
look at fitting APLE ?aple, you'll see that it also centres first, and
expects a detrended response, that is that relevant covariates have
already been taken into account:
y <- c(scale(COL.OLD$CRIME, scale = FALSE))
mean(y)
aple(y, listw1)
Hope this clarifies,
Roger
>
> Any guidance will be welcomed!
>
> Julian
>
> --
> Julian Mariano Burgos, PhD
> Hafrannsóknastofnun, rannsókna- og ráðgjafarstofnun hafs og vatna/
> Marine and Freshwater Research Institute
> Botnsjávarsviðs / Demersal Division
> Skúlagata 4, 121 Reykjavík, Iceland
> Sími/Telephone : +354-5752037
> Netfang/Email: julian.burgos using hafogvatn.is
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: Roger.Bivand using nhh.no
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
More information about the R-sig-Geo
mailing list