Skip to contents

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.

Usage

spread_sims(object, nsim = 200, n_sims = deprecated())

gather_sims(object, nsim = 200, n_sims = deprecated())

Arguments

object

Output from sdmTMB().

nsim

The number of simulation draws.

n_sims

Deprecated: please use nsim.

Value

A data frame. gather_sims() returns a long-format data frame:

  • .iteration: the sample ID

  • .variable: the parameter name

  • .value: the parameter sample value

spread_sims() returns a wide-format data frame:

  • .iteration: the sample ID

  • columns for each parameter with a sample per row

Examples

m <- sdmTMB(density ~ depth_scaled,
  data = pcod_2011, mesh = pcod_mesh_2011, family = tweedie())
head(spread_sims(m, nsim = 10))
#>   .iteration X.Intercept. depth_scaled    range      phi tweedie_p  sigma_O
#> 1          1     2.947281   -0.6113464 21.28292 14.96395  1.579234 2.649385
#> 2          2     2.867277   -0.7282022 50.56038 15.63864  1.583225 1.871312
#> 3          3     2.570547   -0.5759993 81.02526 13.86308  1.582175 1.204293
#> 4          4     3.305925   -0.5416168 26.01008 16.21788  1.588699 1.674452
#> 5          5     2.870912   -0.7513359 35.35486 15.06749  1.595577 2.000633
#> 6          6     2.901625   -0.7516155 25.05987 14.38858  1.614982 2.741510
head(gather_sims(m, nsim = 10))
#>   .iteration    .variable   .value
#> 1          1 X.Intercept. 3.120602
#> 2          2 X.Intercept. 3.072890
#> 3          3 X.Intercept. 2.688049
#> 4          4 X.Intercept. 3.006871
#> 5          5 X.Intercept. 3.120740
#> 6          6 X.Intercept. 2.509646
samps <- gather_sims(m, nsim = 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`.