Spatial Models

688 views
Skip to first unread message

Jon Wakefield

unread,
May 20, 2016, 3:28:08 AM5/20/16
to Stan users mailing list
Has anyone experience coding spatial models with stan? For example intrinsic CAR models as popularized by Besag, or the Leroux model and its variants.
Jon

Elizaveta Semenova

unread,
May 20, 2016, 4:03:49 AM5/20/16
to stan-...@googlegroups.com
Hi Jon, 

I am working on a spatial model, but a different one: the Log-Gaussian Cox Process (Point Patterns). I had the following issues in STAN so far:

1). My code works for small data (about 30 locations) without the spatial random effect (which makes it from LGCP just a Poisson process) and recovers regression coefficients correctly.

2). For larger data, presumably because of the size of the covariance matrix, STAN occupies all the memory (127G) and never finishes computing. If you have not too many areas in CAR, this should not be a problem.

I would be grateful myself to hear about the limit size of the covariance matrix that STAN can cope with.

Liza

On Fri, May 20, 2016 at 9:28 AM, Jon Wakefield <jonwa...@gmail.com> wrote:
Has anyone experience coding spatial models with stan? For example intrinsic CAR models as popularized by Besag, or the Leroux model and its variants.
Jon

--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Goodrich

unread,
May 20, 2016, 10:51:33 AM5/20/16
to Stan users mailing list
Hi Jon,


On Friday, May 20, 2016 at 3:28:08 AM UTC-4, Jon Wakefield wrote:
Has anyone experience coding spatial models with stan? For example intrinsic CAR models as popularized by Besag, or the Leroux model and its variants.
Jon

In the Google Group for stan-users, put "Kyle Foreman" in the search box who did a bunch of stuff like this a couple of years ago. Jonah Gabry did some similar models, and as I recall, we ran into a weird situation where there were a lot of divergent transitions during the warmup period and none during the sampling period, which suggests that Stan had difficulty adapting at least with that dataset.

Ben
 

Jiang Du

unread,
May 20, 2016, 4:15:03 PM5/20/16
to Stan users mailing list
Hi Liza,

Do you think Stan can handle spatial models very well? I've been reading the manuals for a while and haven't tried yet. And after searching around, it seems Stan is not doing well for large spatial problems. In my case, I have 12 maps with total number of regions more than 800.

Jiang

在 2016年5月20日星期五 UTC-5上午3:03:49,Elizaveta Semenova写道:

Andrew Gelman

unread,
May 20, 2016, 5:02:22 PM5/20/16
to stan-...@googlegroups.com
Hi.  I may be mis-remembering here, but I think that with spatial autoregression models (including the intrinsic CAR model), you _don't_ have to write the covariance matrix.  Instead, the efficient way to compute is to just write the prior directly, not as a multilvariate normal but as a product of normal densities.  The point is that you can take advantage of the locality of the conditional dependence when writing the joint prior density.

Also, intrinsic CAR model has no hyperparameters, so if you do express the prior using a covariance matrix, you only have to compute that matrix once, in the transformed data block.

I guess we should do an example!

A

Jiang Du

unread,
May 21, 2016, 10:28:55 PM5/21/16
to Stan users mailing list, gel...@stat.columbia.edu
HI Andrew,

I just tried to implement a proper CAR model, which has a parameter rho to measure the strength of spatial correlation(i.e. the conditional mean for a region is the mean of the neighbors times rho). The CAR model can be specified on the precision matrix, so the evaluation of the log density is fast (including calculation of determinant and quadratic term).

I'm just wondering if I have some "CAR" models created by myself, which is just a multivariate normal prior on the spatial effect. However, if the covariance matrix is only available (depend on some parameters), not the precision matrix, is there a way to avoid calculating the inverse? Or faster ways to do that in Stan?

The inverse is slow after I tested.

Jiang

在 2016年5月20日星期五 UTC-5下午4:02:22,Andrew Gelman写道:

Ben Goodrich

unread,
May 21, 2016, 11:26:08 PM5/21/16
to Stan users mailing list
On Saturday, May 21, 2016 at 10:28:55 PM UTC-4, Jiang Du wrote:
I'm just wondering if I have some "CAR" models created by myself, which is just a multivariate normal prior on the spatial effect. However, if the covariance matrix is only available (depend on some parameters), not the precision matrix, is there a way to avoid calculating the inverse? Or faster ways to do that in Stan?

There is multi_normal_prec(), which takes a precision matrix. But in CAR models it may be worth it to take the Cholesky factor of the precision matrix and then multiply its inverse by a vector of independent standard normals to get the coefficients.

Ben

Jiang Du

unread,
May 22, 2016, 6:28:02 PM5/22/16
to Stan users mailing list
So  in the case that I only have the covariance matrix, not the precision one, I may just use the Cholesky of the covariance matrix and use it to transform from  standard norm distribution. That may be the fasted way, and how MVN are usually sampled.

Jiang

在 2016年5月21日星期六 UTC-5下午10:26:08,Ben Goodrich写道:

Andrew Gelman

unread,
May 22, 2016, 7:01:54 PM5/22/16
to stan-...@googlegroups.com
For the intrinsic CAR model, there is no covariance matrix (the prior is nonstationary), but the equivalent of the log-prior can still be computed, and it depends on a precision matrix that is determined ahead of time (except for a scale parameter), any Cholesky etc can be done in the transformed data block.  For stationary CAR models, the precision matrix typically depends on hyperparameters.
Again, I guess we should do an example for the manual.
A

Reply all
Reply to author
Forward
0 new messages