Discrepancy between posteriors from INLA and brms

36 views
Skip to first unread message

Klaus Oberauer

unread,
Mar 9, 2026, 6:49:41 AM (3 days ago) Mar 9
to R-inla discussion group
Hi,
I'm new to INLA and wanted to test whether it produces the same results as brms. I simulated data from a linear model with 2 predictors (one between, one within subjects) and applied brms and INLA with the same priors. The two methods produce posteriors with matching means but the SD of the posteriors for the within-subjects predictor and the interaction was much narrower from INLA than brms. Any ideas why that is? 
I attach the R script in case this is useful.  
All the best
Klaus

LinearModel.INLA.brms.R

Elias T. Krainski

unread,
Mar 9, 2026, 7:15:36 AM (3 days ago) Mar 9
to R-inla discussion group
Hi, 

You are not fitting the same model. In brm(dv ~ iv1 * iv2 + (1 + iv1 || subj)), you specify a random intercept and a random slope, whereas with INLA you specify only a random intercept. 

You do need a f() term for that, something like f(subj_cp, iv1, ...) where subj_cp is the same as subj (as INLA needs unique index names). 

BTW: You have 'SD' in both lines 38 and 40 (one may be "Sd" instead?), and it seems that you didn't used interPrior in the brm.

Elias

--
You received this message because you are subscribed to the Google Groups "R-inla discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/r-inla-discussion-group/62f11414-279e-49b4-a2b5-98b72b27af03n%40googlegroups.com.

Klaus Oberauer

unread,
Mar 9, 2026, 9:57:59 PM (2 days ago) Mar 9
to R-inla discussion group
Dear Elias,
thank you for your response, this has been super helpful. I had misunderstood how to configure random slopes in INLA. I think I now figured it out. The posteriors from brms and INLA now converge reasonably well (those from INLA are still a bit narrower). I attach my updated script because it might be useful for others. 
All the best
Klaus
LinearModel.INLA.brms.R

Helpdesk (Haavard Rue)

unread,
Mar 10, 2026, 2:58:49 AM (2 days ago) Mar 10
to Klaus Oberauer, R-inla discussion group
With Gaussian likelihood there are not approximations in the latent, just the
hyperparameters and the integration.

I would suggest to fix all hyperparameters and check. the results for the latent
should be identical.

Then you can un-fix one and one (or in blocks) and see what happen.

to run the identical same model, is actually more challenging than one might
think.
Håvard Rue
he...@r-inla.org

Elias T. Krainski

unread,
Mar 10, 2026, 3:06:01 AM (2 days ago) Mar 10
to R-inla discussion group
But now you have two random slopes with INLA, but only one on brms.

--
You received this message because you are subscribed to the Google Groups "R-inla discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion...@googlegroups.com.

Klaus Oberauer

unread,
Mar 10, 2026, 3:40:18 AM (2 days ago) Mar 10
to R-inla discussion group
Yes, you're right. IV2 should not have a random slope because it is a between-subjects variable. I removed the random slope for IV2 from the INLA model. The outcome is the same (I would have been surprised if not, as this random slope cannot do anything). INLA still produces somewhat narrower posteriors than brms. I'll try to figure out why by experimenting a bit. If you have any idea, please let me know. Thanks for all your help!
Klaus

Helpdesk (Haavard Rue)

unread,
Mar 10, 2026, 3:56:43 AM (2 days ago) Mar 10
to Klaus Oberauer, R-inla discussion group
the reason is given in my previous response "On Tue, 10 Mar 2026 at 09:58,
Helpdesk (Haavard Rue)"

you may also use the model 'intslope' (see inla.doc('intslope')) that sometimes
is helpful

fix all hyperparameters, and then add them back sequensially...
Håvard Rue
he...@r-inla.org

Klaus Oberauer

unread,
Mar 10, 2026, 4:57:28 AM (2 days ago) Mar 10
to R-inla discussion group
Dear Haavard,
sorry, I must have failed to understand your previous response. Are you saying that INLA produces narrower posteriors than brms because it does not involve approximations (whereas brms does)? Why should that lead to narrower posteriors in INLA? 
You suggested to fix all hyperparameters - do you mean in INLA or in brms? How do I fix the hyperparameters beyond what I'm doing already? 
All the best, 
Klaus
Reply all
Reply to author
Forward
0 new messages