Extract parameters from a single draw
extract_parameters_from_draw(fit, param, draw)
Stanfit object.
Vector of parameter names.
Index of the draw to extract the parameters from.
Dataframe
Useful for to generate fake data.
The 'tidybayes' package offers an alternative to this function, for example:
fit %>% tidy_draws() %>% gather_variables() %>% filter(.draw == draw & .variable %in% param)
However, the 'tidybayes' version is less efficient as all draws and parameters are extracted and then filtered (also the draw IDs are not the same).
Using 'tidybayes' would be more recommended when we only want to extract specific parameters,
and that it does not matter which draw are extracted (in that case using tidybayes::spread_draws()
).