How to take the difference of marginals.fitted.values from two

44 views
Skip to first unread message

Mcewen Khundi

unread,
Nov 14, 2022, 3:47:00 AM11/14/22
to R-inla discussion group
Hi

I am trying to produce the posterior difference of marginals.fitted.values from two SPDE models.

Both models have been fitted to the same spatial points but have used data from two different years. I am interested in knowing whether the prevalence of a disease changed between the two time points. Hence I have opted to do the difference of the posteriors of the  marginals.fitted.values from the two models.

I thought this would be a simple subtraction but the structure of the marginals.fitted.values does not allow this.

Any guidance will be appreciated and sorry I may have used wrong terminology I am new in the field.

My naive approach that did not work, below:
model1$marginals.fitted.values[index] - model2$marginals.fitted.values[index]

Regards,
McEwen Khundi. 

Helpdesk (Haavard Rue)

unread,
Nov 14, 2022, 1:32:28 PM11/14/22
to Mcewen Khundi, R-inla discussion group
if you want the difference point-wise, you can sample for each marginal
(using inla.rmarginal) and do the difference (pointwise). this will
ignore any dependence between the two fitted values, in case there is
any (this would be model spesific).

The 'correct' way is to include the dependence by defining a joint model
and and study the difference of the linear predictors. but this can be
somewhat tedious.

at least in the simple approach, you'll get the mean difference correct
> --
> 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 on the web, visit
> https://groups.google.com/d/msgid/r-inla-discussion-group/9b44ff5f-3a7c-4d39-930f-e2703012fc38n%40googlegroups.com
> .

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

Elias T. Krainski

unread,
Nov 15, 2022, 5:49:55 AM11/15/22
to R-inla discussion group
Hi,
You can do it also using lincombs (if not many) or considering samples from the joint posterior. Considering the inla.make.lincombs() function you can specify a set of contrasts you want and it will be computed by inla(). By considering the posterior samples, using inla.posterior.sample() you can do it by post-processing the samples from the linear predictor.
Elias

Mcewen Khundi

unread,
Nov 15, 2022, 8:47:35 AM11/15/22
to R-inla discussion group
Thanks both for the answers.

About the joint model approach, what would be the best approach to follow?

I am using Demographic Health Surveillance data that is available for the years 2013 and 2018. 

I have checked the joint models chapter from this book ch3.2 https://becarioprecario.bitbucket.io/spde-gitbook/ch-manipula.html#sec:me 

But the models used do not seem to be similar to the model that I have, do you know a tutorial or paper that would assist me to understand the type of model I can use?

Regards,
McEwen.
Reply all
Reply to author
Forward
0 new messages