Extracting Posterior Distribution

Skip to first unread message

Bethke, Bethany (DNR)

Aug 4, 2020, 4:30:36 PM8/4/20
to trophicposi...@googlegroups.com



I’m using tRophicPosition and wondering if it’s possible to get the posterior distribution estimates out of the model, for both alpha and TP (and for multiple species, if possible). Essentially I want the numbers that make up the panels on the right side of this plot:

Love the package – thanks so much for your work!


Bethany Bethke

Fisheries Research Scientist | Fish and Wildlife


Claudio Quezada Romegialli

Aug 6, 2020, 10:11:08 AM8/6/20
to Bethke, Bethany (DNR), trophicposi...@googlegroups.com
Hi Bethany

It depends on how you got those plots. If you have posterior estimates for your variables, let say like this:
isotopeData <- "Your data for one species"
model.string <- jagsBayesianModel()
model <- TPmodel(data = isotopeData, model.string = model.string,
                 n.adapt = 5000)
posterior.samples <- posteriorTP(model = model, n.iter = 20000,
                                 variable.names = c("TP", "muDeltaN"))

Then you have to combine the chains (by default TPmodel runs 2 chains in parallel):
posterior.combined <- coda::mcmc(do.call(rbind, posterior.samples))

posterior.combined is an mcmc object with the number of objects declared in posteriorTP (see variable.names above). So in this case, we have 2 objects, the first is TP, and the second is muDeltaN:

If you want the "raw posterior data" just use as.numeric:
as.numeric(posterior.combined[,1]) #for TP
as.numeric(posterior.combined[,2]) #for muDeltaN

When you have multiple species or multiple models, then you will have a dataframe with the results, in this case called "models":
isotopeData <- generateTPData()
models <- multiModelTP(isotopeData, n.adapt = 200, n.iter = 200,
                       burnin = 200)
credibilityIntervals(models$gg, x = "model")

models$TP is a list with the raw posterior TP data (a list)
models$alpha is a list with the raw posterior alpha data (a list)
models$gg is a dataframe with some summary results of the models run; and
models$samples are the raw data but as mcmc objects

I believe this is what you want. If you have any doubt, take a look at the vignettes attached.



To download tRophicPosition package visit https://github.com/clquezada/tRophicPosition
You received this message because you are subscribed to the Google Groups "tRophicPosition" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trophicposition-s...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/trophicposition-support/BN8PR09MB3572D4F1C06C04E152206983DE4A0%40BN8PR09MB3572.namprd09.prod.outlook.com.
Reply all
Reply to author
0 new messages