brianstock / MixSIAR

A framework for Bayesian mixing models in R:
http://brianstock.github.io/MixSIAR/
90 stars 75 forks source link

Extract posterior estimates? #333

Open bethanybethke2050 opened 1 year ago

bethanybethke2050 commented 1 year ago

Hi - thanks for maintaining a great package. I'm using MixSIAR with two isotopes (d13C, d15N) from two source habitats (benthic, pelagic) and modeling source contribution to consumers in different lakes (random effect) that are under different conditions (fixed effect). I'd like to run pairwise comparisons on the posterior distributions of the lakes to determine lake-to-lake differences.

I understand that I have the mean estimates for contribution of benthic vs pelagic in the output summary statistics, which includes credible intervals so I can see if the estimates for the means overlap. But I have also seen pairwise comparisons used for the purpose of estimating the likelihood two distributions are different (e.g., pairwiseComparisons function in the package tRophicposition).

Alternatively, it would be great to have a predicted value of proportion contribution of each source for each individual consumer in the dataset. Is that output possible?

Thanks! Bethany

brianstock commented 1 year ago

Yes, you can get all the MCMC draws, see http://brianstock.github.io/MixSIAR/articles/modify_output.html.

If you include individual as a factor then you'll get predicted proportion by individual. Since you already have 2 factors (lake, condition), you can't simply add individual as a 3rd (no good reason, just a limitation when I wrote the code).

We used to have a separate 'individual as RE' option but removed it 8 years ago (https://github.com/brianstock/MixSIAR/commit/277140e12468a90442836ee79e558f09000163a5). You may be able to piece the necessary code together. The JAGS model part is still on lines 352-360 of write_JAGS_model. If doing this, you need to turn off residual error.