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.460469 -0.6777886 29.11551 14.67822 1.588879 2.228489
#> 2 2 2.524983 -0.8146981 107.42087 15.56548 1.588288 1.469703
#> 3 3 2.740701 -0.7210002 18.92312 16.19061 1.580775 2.203863
#> 4 4 2.142063 -0.7580820 23.89079 15.76858 1.593325 2.238889
#> 5 5 3.239527 -0.7837840 20.59849 15.03114 1.576873 2.911885
#> 6 6 2.706899 -0.5103612 107.55594 15.35006 1.588056 1.571194
head(gather_sims(m, nsim = 10))
#> .iteration .variable .value
#> 1 1 X.Intercept. 3.079103
#> 2 2 X.Intercept. 3.114810
#> 3 3 X.Intercept. 3.144996
#> 4 4 X.Intercept. 2.264473
#> 5 5 X.Intercept. 2.592692
#> 6 6 X.Intercept. 3.480357
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`.