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 ~ 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.723420 -1.239501 59.20573 13.56981 1.535910 0.7677258
#> 2 2 -1.975947 -1.337013 51.06758 12.67182 1.573140 0.8312792
#> 3 3 -1.471611 -1.161968 68.90814 13.73527 1.525259 0.8790436
#> 4 4 -1.807872 -1.260145 67.47024 12.62994 1.563359 0.8887063
#> 5 5 -2.027082 -1.342981 62.47076 13.30531 1.564159 0.9195087
#> 6 6 -1.793759 -1.282912 53.66913 12.96081 1.549470 0.8483883
#> sigma_O sigma_E
#> 1 Inf 2.578915
#> 2 2.659516e-83 3.078770
#> 3 0.000000e+00 3.240282
#> 4 4.158774e-107 2.755055
#> 5 0.000000e+00 3.025966
#> 6 9.386198e-129 3.144829
head(gather_sims(m, nsim = 10))
#> .iteration .variable .value
#> 1 1 depth_scaled -1.926309
#> 2 2 depth_scaled -1.625672
#> 3 3 depth_scaled -1.590939
#> 4 4 depth_scaled -1.979694
#> 5 5 depth_scaled -1.368575
#> 6 6 depth_scaled -2.177121
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 397 rows containing non-finite values (`stat_bin()`).