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 3.749276 -0.5134865 30.20537 14.48993 1.583609 1.836304
#> 2 2 2.437613 -0.8824028 18.67602 14.36332 1.577593 2.124812
#> 3 3 2.643799 -0.6484220 40.34146 14.89017 1.609824 2.481647
#> 4 4 1.720072 -0.6486199 13.61455 15.09968 1.620128 2.860899
#> 5 5 2.557104 -0.6799320 31.43043 14.85466 1.591829 2.126323
#> 6 6 2.713461 -0.8159928 13.68706 15.25929 1.596875 2.902257
head(gather_sims(m, nsim = 10))
#> .iteration .variable .value
#> 1 1 X.Intercept. 3.296844
#> 2 2 X.Intercept. 2.336084
#> 3 3 X.Intercept. 2.407328
#> 4 4 X.Intercept. 2.344606
#> 5 5 X.Intercept. 2.959705
#> 6 6 X.Intercept. 3.163177
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`.