R/tidy_draws.R
tidy_draws.map.Rd
Implementation of tidybayes::tidy_draws()
for rethinking::map()
and rethinking::quap()
models. Extract draws from a Bayesian fit into a wide-format data frame with a
.chain
, .iteration
, and .draw
column, as well as all variables as columns.
While this function can be useful for quick glances at models (especially
combined with gather_variables()
and median_qi()
), it is
generally speaking not as useful as spread_draws()
or
gather_draws()
for most applications, and is mainly used internally.
# S3 method for map tidy_draws(model, n = 5000, ...) # S3 method for quap tidy_draws(model, n = 5000, ...) # S3 method for map2stan tidy_draws(model, ...) # S3 method for ulam tidy_draws(model, ...)
model | A model fit using |
---|---|
n | For |
... | Further arguments passed to other methods (mostly unused). |
The main additional functionality compared to tidybayes::tidy_draws()
when used on
other models is that since draws must be generated on-the-fly,
an argument (n
) is provided to indicate how many draws to take. The .chain
and
.iteration
columns are also always NA
, since they have no meaning for these model
types (use the .draw
column if you need to index draws). Otherwise, the result of
this function follows the same format as tidybayes::tidy_draws()
; see that
documentation for more information.
#>#>#> #>#>#> #> #> #> #> #>#>#>#>#> #>#>#> #>#> #>#>#> #>#>#> #>m = quap(alist( mpg ~ dlnorm(mu, sigma), mu <- a + b*wt, c(a,b) ~ dnorm(0, 10), sigma ~ dexp(1) ), data = mtcars, start = list(a = 4, b = -1, sigma = 1) ) m %>% tidy_draws() %>% gather_variables() %>% median_qi()#> # A tibble: 3 x 7 #> .variable .value .lower .upper .width .point .interval #> <chr> <dbl> <dbl> <dbl> <dbl> <chr> <chr> #> 1 a 3.83 3.67 3.99 0.95 median qi #> 2 b -0.271 -0.319 -0.224 0.95 median qi #> 3 sigma 0.132 0.0995 0.163 0.95 median qi