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 ~ 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.853368     -1.112498 58.93430 13.14827  1.560257 0.9143472
#> 2          2    -1.748583     -1.214493 60.36433 13.03163  1.565090 0.8961654
#> 3          3    -1.667642     -1.243943 71.31743 12.53397  1.557068 0.9085065
#> 4          4    -2.066448     -1.292050 56.91780 13.00500  1.553739 0.8649357
#> 5          5    -1.480406     -1.215753 62.47297 12.62660  1.583245 0.9351529
#> 6          6    -1.850197     -1.251386 50.50230 12.18955  1.560707 0.9031239
#>         sigma_O  sigma_E
#> 1           Inf 3.064918
#> 2  9.235953e-10 2.438492
#> 3 1.190969e+131 2.361526
#> 4           Inf 2.681569
#> 5 8.740008e-149 2.622513
#> 6           Inf 3.271738
head(gather_sims(m, nsim = 10))
#>   .iteration    .variable    .value
#> 1          1 depth_scaled -1.762952
#> 2          2 depth_scaled -1.813336
#> 3          3 depth_scaled -1.800826
#> 4          4 depth_scaled -1.788979
#> 5          5 depth_scaled -1.772511
#> 6          6 depth_scaled -2.086623
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 328 rows containing non-finite values (`stat_bin()`).