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, 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 ~ 0 + depth_scaled + depth_scaled2,
  data = pcod_2011, mesh = pcod_mesh_2011, family = tweedie(),
  spatiotemporal = "AR1", time = "year")
head(spread_sims(m, nsim = 10))
#>   .iteration depth_scaled depth_scaled2    range      phi tweedie_p   ar1_rho
#> 1          1    -1.853246     -1.112426 58.93429 13.14827  1.560257 0.9143473
#> 2          2    -1.748585     -1.214495 60.36432 13.03163  1.565090 0.8961658
#> 3          3    -1.667609     -1.243924 71.31742 12.53397  1.557068 0.9085067
#> 4          4    -2.066385     -1.292014 56.91777 13.00500  1.553739 0.8649369
#> 5          5    -1.480440     -1.215773 62.47298 12.62660  1.583245 0.9351527
#> 6          6    -1.850135     -1.251349 50.50230 12.18955  1.560707 0.9031242
#>        sigma_O  sigma_E
#> 1          Inf 3.064904
#> 2  5.04351e-11 2.438509
#> 3 2.32420e+138 2.361540
#> 4          Inf 2.681585
#> 5  0.00000e+00 2.622512
#> 6          Inf 3.271721
head(gather_sims(m, nsim = 10))
#>   .iteration    .variable    .value
#> 1          1 depth_scaled -1.762974
#> 2          2 depth_scaled -1.813378
#> 3          3 depth_scaled -1.800810
#> 4          4 depth_scaled -1.789012
#> 5          5 depth_scaled -1.772530
#> 6          6 depth_scaled -2.086558
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`.
#> Warning: Removed 338 rows containing non-finite values (stat_bin).