Fitting a SAR model with no covariates

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Fitting a SAR model with no covariates

Julian M. Burgos
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.

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: [hidden email]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Fitting a SAR model with no covariates

Roger Bivand
Administrator
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: [hidden email]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> 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: [hidden email]
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: Fitting a SAR model with no covariates

Julian M. Burgos
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&amp;data=02%7C01%7C%7C312f8aadce694232b31208d7f42c3a35%7C8e105b94435e4303a61063620dbe162b%7C0%7C0%7C637246343112765266&amp;sdata=SNoQ6Razc%2Bf5JqvcRyCl0A1q8hJI4%2BkuFPWPsaQfBDw%3D&amp;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&amp;data=02%7C01%7C%7C312f8aadce694232b31208d7f42c3a35%7C8e105b94435e4303a61063620dbe162b%7C0%7C0%7C637246343112765266&amp;sdata=kvz3Oknb0GlXwPgKfOUXbYE%2FGN0ib%2F%2FyrBV7u4JIapY%3D&amp;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: [hidden email]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-geo&amp;data=02%7C01%7C%7C312f8aadce694232b31208d7f42c3a35%7C8e105b94435e4303a61063620dbe162b%7C0%7C0%7C637246343112775269&amp;sdata=m53vPJn6kBhIMyKtQ1jzjapunUalhuu085LKbDCD1xs%3D&amp;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: [hidden email]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo