spread_sims() returns a wide-format data frame. gather_sims() returns a long-format data frame. The format matches the format in the tidybayes spread_draws() and gather_draws() functions.

spread_sims(object, n_sims = 200)

gather_sims(object, n_sims = 200)

Arguments

object

Output from sdmTMB().

n_sims

The number of simulation draws.

References

Code for simulating from the joint precision matrix adapted from:

Osgood-Zimmerman, A. and Wakefield, J. 2021. A Statistical introduction to Template Model Builder: a flexible tool for spatial modeling. arXiv 2103.09929. https://arxiv.org/abs/2103.09929.

Examples

if (inla_installed()) {
m <- sdmTMB(density ~ 0 + depth_scaled + depth_scaled2,
  data = pcod_2011, mesh = pcod_mesh_2011, family = tweedie(link = "log"),
  spatiotemporal = "AR1", time = "year")
head(spread_sims(m, n_sims = 10))
head(gather_sims(m, n_sims = 10))
samps <- gather_sims(m, n_sims = 1000)

if (require("ggplot2", quietly = TRUE)) {
  ggplot(samps, aes(.value)) + geom_histogram() +
    facet_wrap(~.variable, scales = "free_x")
}
}
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> Warning: Removed 329 rows containing non-finite values (stat_bin).