Add 1D first and second order random walk x iid models (BYM2 style parameterization)#122
Add 1D first and second order random walk x iid models (BYM2 style parameterization)#122szego wants to merge 31 commits into
Conversation
Merge branch 'antonio/2026-04-25/rw1o1diid' into antonio/2026-04-26/rwNo1diid # Conflicts: # rinla/DESCRIPTION # rinla/NAMESPACE
|
Looks like the common practice in this repo is to squash PRs into a single commit. Happy to do that, if so. |
|
Thank you, looking good! Just one comment, I think the RW2 case can be implemented as you do for the RW1, as inla.rw(order=<>,n=<>, scale.model=T), do the right thing, and passing eigenvalues/vectors to the prior calculation (then set scale.model=FALSE, as your RW model is already scaled), and then there would be no need for 'rgeneric' (which is slow and break parallel....) what u think? |
|
aaah, now I see why this is needed for rw2... my bad. |
|
Let me check the internal C-code is something can be done |
|
Thank you! I'll revert this to draft for now. |
|
I think an alternative option is to add in the C-code the RW2+IID construction,
and then the RW1+IID, will follow as a special case. The little tricky thing is
the prior computations, but this is fine as we can use eigenvalues/vectors. I'll
put this on the list, and try to have it done soon
…On Sun, 2026-05-03 at 09:25 -0700, Antonio R. Vargas wrote:
szego left a comment (hrue/r-inla#122)
Thank you! I'll revert this to draft for now.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID:
***@***.***>
--
Håvard Rue
Professor of Statistics
Chair of the Statistics Program
CEMSE Division
King Abdullah University of Science and Technology
Thuwal 23955-6900
Kingdom of Saudi Arabia
***@***.***
Office: +966 (0)12 808 0640
Mobile: +966 (0)54 470 0421
Research group: bayescomp.kaust.edu.sa
R-INLA project: www.r-inla.org
Zoom: kaust.zoom.us/my/haavard.rue
--
This message and its contents, including attachments are intended solely
for the original recipient. If you are not the intended recipient or have
received this message in error, please notify me immediately and delete
this message from your computer system. Any unauthorized use or
distribution is prohibited. Please consider the environment before printing
this email.
|
|
I've implemented the PC prior for this precision mixture model. The code now uses that instead of using the not-exactly-appropriate |
This PR adds two new models:
inla.rw1o1diidandinla.rw2o1diid. The names are formatted like:I've wanted to implement these for a while, ever since I saw this old post on the google group: https://groups.google.com/g/r-inla-discussion-group/c/girUuJhS-Q8/m/3VOkGQ2NAAAJ
The
inla.rw2o1diidmodel is what the poster there was asking for (and what I wanted too, which lead me to that post).Both models use BYM2-style parameterizations
with PC priors.
There is an existing
rw2diidmodel but it doesn't support 1D grids.inla.rw1o1diidThis is just a wrapper around the existing BYM2 model, as suggested by Elias T. Krainski in the link above. It builds the chain graph internally.
inla.rw2o1diidThis is implemented as an rgeneric and uses
inla.pc.dprecfor the prior on tau and a newinla.pc.rw2o1diid.phifor the PC prior on phi.The main difference between this and the RW1 model is that this uses an n-parameter latent field combining the rw and iid components, as opposed to the 2n parameters in the RW1 case. So the user can't get just the RW2 parameter estimates or just the iid parameter estimates like they can for the RW1 model.
One consequence of the n-parameter latent field is that we actually end up doing a BYM2-style mixture of the precision matrices, like
Q = tau * ( phi * R + (1 - phi) * I ), whereRis the (scaled) RW2 structure matrix. So we're not mixing the variances as in pure BYM2, we're mixing precisions, andtauandphihave slightly different interpretations. The marginal variance of the field is only approximately1/tauandphiis only approximately the structured-variance fraction.The new helper
inla.pc.rw2o1diid.phiimplements a PC prior forphiderived from the Gaussian KLD between the precision-mixture flexible model and the iid base model:where the
lambda_iare the eigenvalues ofR. The PC distance issqrt(2*KLD(phi)), the prior on the distance isExp(lambda), andlambdais calibrated so thatP(phi < u) = alpha(default(0.5, 0.5)).There is also a helper function
inla.rw2o1diid.hyperparto get back the user-scale posteriors forphiandtau- see example below.Example