inlabru-org / inlabru

inlabru
https://inlabru-org.github.io/inlabru/
91 stars 21 forks source link

Inquiry about imposing a global cross-component sum-to-zero constraint on latent effects in INLA/inlabru #187

Open XueqingYin opened 1 year ago

XueqingYin commented 1 year ago

Hi,

We are working on a spatio-temporal model that contains 5 latent random effects, like:

formula = y ~ -1 + f(A1, model = SPDE1, group = ..) + f(A2, model = SPDE2, group = ..)+ f(A3 model = SPDE3 group = ..)+ f(A4, model = SPDE4, group = ..)+ f(A5, model = SPDE5, group = ..).

We would like to apply a sum-to-zero linear constraint across multiple effects, for example f(A1,…) + f(A2…)+ f(A3…) + f(A4…)=0. Comments from INLA discussion group indicated that this likely needs to be done by creating a "fake" zero observation, which is observed with fixed large observation precision. I tried this approach but got an error that appears to be memory issues. The error message has been attached here.

It would be beneficial to impose such a constraint for our analysis, so we are wondering if you have any ideas on how this could be fixed, or if the global cross-component constraint feature might be added into INLA/inlabru at some point later.

Many thanks in advance,

Xueqing Yin

error message

finnlindgren commented 1 year ago

The proper solution will be to implement joint constraints in R-INLA, so that one could specify e.g. a list of linear combination matrices list(comp1 = Acomp1, comp2=Acomp2, ...) and a vector e, that would define a joint set of linear constraints $$\sum_k\mathbf{A}_k \mathbf{u}_k = \mathbf{e}$$ where $\mathbf{u}_k$ is the latent vector for component nr $k$.

In the inlabru interface, we then need to allow the user to specify such constraints in a similar or possibly identical way to how predictor expressions are specified with R expressions. It can then internally construct the needed matrices and e-vector to feed onwards to inla().