[R-sig-Geo] Fitting a SAR model with no covariates

Julian M. Burgos ju||@n@burgo@ @end|ng |rom h@|ogv@tn@|@
Tue May 12 10:58:12 CEST 2020


Thank you Roger for your detailed answer.  Clearly I still have to learn quite a bit about spatial regression.

My best,

Julian Burgos

Roger Bivand writes:

> 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://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fforum%2F%23!topic%2Fopenspace-list%2FRCYcrEcxDWg&data=02%7C01%7C%7C312f8aadce694232b31208d7f42c3a35%7C8e105b94435e4303a61063620dbe162b%7C0%7C0%7C637246343112765266&sdata=SNoQ6Razc%2Bf5JqvcRyCl0A1q8hJI4%2BkuFPWPsaQfBDw%3D&reserved=0.
> 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://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdoi.org%2F10.1111%2Fj.1538-4632.2009.00758.x&data=02%7C01%7C%7C312f8aadce694232b31208d7f42c3a35%7C8e105b94435e4303a61063620dbe162b%7C0%7C0%7C637246343112765266&sdata=kvz3Oknb0GlXwPgKfOUXbYE%2FGN0ib%2F%2FyrBV7u4JIapY%3D&reserved=0).
>
> 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://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-geo&data=02%7C01%7C%7C312f8aadce694232b31208d7f42c3a35%7C8e105b94435e4303a61063620dbe162b%7C0%7C0%7C637246343112775269&sdata=m53vPJn6kBhIMyKtQ1jzjapunUalhuu085LKbDCD1xs%3D&reserved=0
>>


--
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



More information about the R-sig-Geo mailing list