Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Hierarchal SLM model in INLA?

42 views
Skip to first unread message

Samuel Reiterbund-Olley

unread,
Apr 17, 2025, 4:00:39 PMApr 17
to R-inla discussion group

Dear INLA helpdesk

I’m trying to fit a Hierarchal SLM in INLA for repeated measurements. Each area of interest has multiple house sales. I’ve also attempted this method using the HSAR package developed by Dong, but ran into issues with run time, as it uses MCMC estimation. I’m therefore keen to know whether this is possible in INLA or whether this might be developed in future INLA updates. I have successfully applied this hierarchical approach using CAR models in INLA.

I have attempted to use the SLM method/argument within INLA but have encountered errors presumably as my data has repeated measurements for each subject (area) and is unbalanced (each subject has a variable number of repeated observations (i.e. sales).

If required, please see the HSAR vignette and paper from Dong 2015 for further information, and the approach is also reviewed by your colleague Bivard 2017.

Example

I’m not able to share my data but have provided an example using the Boston dataset, and simply duplicated the dataset twice therefore, creating a repeated measurement type dataset. Please see attached notepad file for code, if required.

Many thanks

Samuel Reiterbund-Olley

References

https://cran.r-project.org/web/packages/HSAR/vignettes/HSAR.html

Dong, G. and Harris, R., 2015. Spatial autoregressive models for geographically hierarchical data structures. Geographical Analysis47(2), pp.173-191.

Bivand, R., Sha, Z., Osland, L. and Thorsen, I.S., 2017. A comparison of estimation methods for multilevel models of spatially structured data. Spatial Statistics21, pp.440-459
example.txt

Virgilio Gómez-Rubio

unread,
Apr 18, 2025, 4:09:38 PMApr 18
to Samuel Reiterbund-Olley, R-inla discussion group
Hi,

Thanks for your question. Your code is not reproducible because object boston.tr is not created before it is used. In any case, if you have observations nested within areas you can simply use an index from 1 to n when creating the sim latent effect and then assign to each observation the index corresponding to its area. I believe this is what you want to do.

In your code boston.tr$idx should NOT go from 1 to the number of rows but, instead, define the indices according to the area. There are different ways in which this can be done depending how your data is organized.

Best,

Virgilio

lyh...@gmail.com

unread,
Apr 20, 2025, 11:02:51 AMApr 20
to R-inla discussion group
Hi,
I do not think SLM can fit this hierarchal SLM model. The hierarchal SLM has a particular covariance structure, which does not equal the one in SLM model.
However, the hierarichal SLM model can be fitted by INLA coupled with MCMC.

Zazaland

unread,
Apr 22, 2025, 11:48:03 AMApr 22
to R-inla discussion group
Om

Samuel Reiterbund-Olley

unread,
Apr 25, 2025, 3:19:10 PMApr 25
to R-inla discussion group
Virgilio,

thanks for your reply,

apologies, yes, you are correct about the error in the code,

I've added an updated version of code. Hopefully this new version works if required. The boston dataset belongs to the spData package.

The original dataset consists of 1 record (each row) for each area and therefore the duplication dataset consists of 2 records for each region. 

so based on your suggestion the new index (new_idx) should consist as below??

table.png

thanks 

Samuel
example_updated.txt

Virgilio Gómez-Rubio

unread,
Apr 25, 2025, 3:21:37 PMApr 25
to Samuel Reiterbund-Olley, R-inla discussion group
Hi,

>
> so based on your suggestion the new index (new_idx) should consist as below??


Yes, this should work provided that the model that you want to fit has nested observations within areas, so that the observations in the same area share the value of the random effect. I cannot recall seeing this model in the literature but it looks reasonable to me.

Best,

Virgilio

Samuel Reiterbund-Olley

unread,
Apr 25, 2025, 3:36:05 PMApr 25
to R-inla discussion group
Thanks for your reply,

yes, I wasn't sure if it was possible. I have some real world data to test on, and compare performance against CAR models. If I an get it to work, I'll feed back the result.

As explained in my introduction, I have tried Dong's full MCMC approach, but came up against run time issues. 

Are you referring to the INLABMA method? I found a paper by Teng 2023 where he used INLABMA for repeated measurements (i.e. more than one measurement per region), but it seemed to require a balanced dataset (i.e. equal number of observations per region). He also helpfully provided code in the paper, but not the starting dataset. 

ref
Teng, J., Ding, S., Zhang, H. and Hu, X., 2023. MCMCINLA estimation of varying coefficient spatial lag model—A study of China’s economic development in the context of population aging. Plos one18(5), p.e0279504. 

thanks

Samuel

Samuel Reiterbund-Olley

unread,
Apr 25, 2025, 3:37:10 PMApr 25
to R-inla discussion group
Thanks,

I'll try it out next week and feed back.

Many thanks for your help

Samuel

Samuel Reiterbund-Olley

unread,
May 12, 2025, 3:57:58 PMMay 12
to R-inla discussion group
Hi Virgilio,

I tried the SLM function with the new coding for region, but still threw off a similar error for 2 data points per region. As a comparison, I successfully ran the code with only one value per region and this is included at the end of the attached code.

I have uploaded the code again, if you have any time to run it yourself. If you try hopefully it runs successfully. 

thanks 

Samuel
(FYI - I wont be available for the next month)
updated code with new ID.docx
Reply all
Reply to author
Forward
0 new messages