
Extract parameter simulations from the joint precision matrix
Source:R/gather-spread.R
gather_sims.Rd
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 IDcolumns 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.266213 -0.7238414 60.55531 14.53894 1.607782 1.751851
#> 2 2 2.753081 -0.6773062 38.69599 16.34944 1.595390 1.712716
#> 3 3 2.804002 -0.8767018 23.69324 16.09331 1.569319 2.801673
#> 4 4 2.850459 -0.7198302 33.79501 15.90992 1.591263 1.703641
#> 5 5 3.053531 -0.4808541 41.66564 15.91765 1.565976 1.897514
#> 6 6 2.935834 -0.4422661 35.64105 16.55391 1.557440 2.352120
head(gather_sims(m, nsim = 10))
#> .iteration .variable .value
#> 1 1 X.Intercept. 3.190661
#> 2 2 X.Intercept. 2.980947
#> 3 3 X.Intercept. 2.845583
#> 4 4 X.Intercept. 2.647753
#> 5 5 X.Intercept. 2.042331
#> 6 6 X.Intercept. 2.632511
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`.