inla.pmarginal() question

25 views
Skip to first unread message

Drew N

unread,
Sep 23, 2025, 4:28:47 AM (11 days ago) Sep 23
to R-inla discussion group
Hello,

I'm following Ch2 in the Bayesian Inference with INLA book for working with marginal posterior.

For this part, is there a way to scale the code to hypothesis test for all fixed effects (or ones we care about)?

In order to know whether covariate x1 has a (positive) association with the response, the probability of its coefficient being higher than one can be computed:

1 - inla.pmarginal(0, m1$marginals.fixed$x1)

I'd appreciate any help with this, thank you!

Best,
Andrew

Helpdesk (Haavard Rue)

unread,
Sep 23, 2025, 9:48:33 AM (10 days ago) Sep 23
to Drew N, R-inla discussion group
something like this. its not strictly correct from the Bayesian point of view,
but you can kind of do this to check if all coeffs are zero. easist if the
covariates are kind of centered.


n <- 100
x <- rnorm(n)
xx <- rnorm(n)
xxx <- rnorm(n)
y <- 1 + rnorm(n)

r <- inla(y ~ 1 + x + xx + xxx,
data = data.frame(y, x, xx, xxx),
family = "gaussian",
control.fixed = list(correlation.matrix = TRUE))

S <- r$misc$lincomb.derived.covariance.matrix
## remove the contribution from the intercept
S <- S[2:4, 2:4]
est <- r$summary.fixed$mean[2:4]
## this should be chisq_3 when there is no effects (about...)
sq <- as.numeric(est %*% solve(S) %*% est)
## some rough p-value (whatever it mean here)
1-pchisq(sq, df = 3)
> --
> 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/63c8a955-d0d6-41af-88af-1bc2166f7f88n%40googlegroups.com
> .

--
Håvard Rue
he...@r-inla.org

Drew N

unread,
Sep 23, 2025, 11:33:00 AM (10 days ago) Sep 23
to R-inla discussion group
Thank you for your reply Dr. Rue. Apologies as I am more accustomed to tidyverse syntax, but would a lapply function work with inla.pmarginal()? I'm interested in using inla.pmarginal() to obtain the probability of positive and negative associations with reference to 0.  

Håvard Rue

unread,
Sep 24, 2025, 4:17:43 AM (10 days ago) Sep 24
to Drew N, R-inla discussion group

the summary(result), or result$summary.fixed will also compute the quantiles,
which you can check contains 0 or not. this is what you want?
hr...@r-inla.org
Reply all
Reply to author
Forward
0 new messages