Constraints in spatial models

361 views
Skip to first unread message

arantxa urdangarin

unread,
Dec 29, 2020, 12:00:02 PM12/29/20
to nimble-users
Hi to all,
I'm trying to implement a model with lcar prior distribution for spatial random effects. To solve the identifiability problem I want to add the following constraint in my model: sum(ler[1:N])=0.
In the code below you can see how I have implemented the contraints (similar idea as in winbugs) but it doesn't fulfill sum(ler[1:N])=0 condition. I would appreciate any idea/suggestion.
Thanks in advance!
Arantxa


for(i in 1:N) {
    gamma[i] <- expected[i] * exp(alpha0+ler[i])
    RR[i] <- exp(alpha0+ler[i])
    y[i] ~ dpois(gamma[i])

    # Constraints
    cond ~ dnorm(sum.ler, 1000)
    sum.ler <- sum(ler[1:N])
    constraint_data ~ dconstraint(cond = 0)
  }


data <- list(y = y, constraint_data = 1)

Daniel Turek

unread,
Dec 30, 2020, 3:33:21 PM12/30/20
to arantxa urdangarin, nimble-users
Yes, Arantxa, assuming that the ler[1:N] is the vector of spatial random effects, and that you're using the improper (icar) distribution for these effect (which is the dcar_normal distribution in NIMBLE), then you might just want the zero-mean constraint for these, which is an option with the dcar_normal distribution, which is used as:

ler[1:N] ~ dcar_normal(..., zero_mean = 1)

You can read more about this option, and the dcar_normal distribution in general, by getting the help on the distribution as:

library(nimble)
help(dcar_normal)


As for manually implementing this zero-sum constraint, as you were were doing, I think what you'd want is almost the same as you had, but rather:

code <- modelCode({
    sum.ler <- sum(ler[1:N])
    one ~ constraint(sum.ler = 0)
})

data <- list(..., one = 1)

This approach, using dconstraint to impose the sum-to-zero, could also be used with other distributions for the random effects, for example the dcar_proper distribution.

Hope this gets it working for you!  Let us know if you have other questions.

Cheers,
Daniel


--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/f520a95f-20a2-4221-a2f5-4424fbd0be19n%40googlegroups.com.

Daniel Turek

unread,
Dec 31, 2020, 2:17:15 PM12/31/20
to arantxa urdangarin, nimble-users
Arantxa, thanks again for following up.  It looks like you're running into a nuanced case of the dconstraint distribution, and making that work for you would be another discussion.

But more importantly, after sending my email yesterday, I realized that using the dconstraint distribution to impose the sum-to-zero will lead to other, bigger, problems, with the spatial CAR process.  Basically, if we correctly were to use the dconstraint distribution to impose this, then during the course of MCMC sampling, none of the spatial components (the elements of ler[]) would be able to transition (since no proposed transition to a single element of lew[] would satisfy this constraint), and essentially the MCMC would fail to correctly sample.  This approach wouldn't work.

Instead, the best mechanism I think would be making use of the zero_mean argument, as we also discussed.  This will impose a zero mean, and hence also sum-to-zero, for the spatial components, but also will allow correct MCMC sampling.  Is that what you're after?

Daniel

Reply all
Reply to author
Forward
0 new messages