@@ -121,6 +121,30 @@ To convert an existing draws object to a different format use the
121121` posterior::as_draws_*() ` functions.
122122
123123To manipulate the ` draws ` objects use the various methods described in the
124- posterior package [ vignettes] ( https://mc-stan.org/posterior/articles/index.html )
124+ ** posterior** package [ vignettes] ( https://mc-stan.org/posterior/articles/index.html )
125125and [ documentation] ( https://mc-stan.org/posterior/reference/index.html ) .
126126
127+ ### Structured draws similar to ` rstan::extract() `
128+
129+ The ** posterior** package's ` rvar ` format provides a multidimensional,
130+ sample-based representation of random variables. See
131+ https://mc-stan.org/posterior/articles/rvar.html for details.
132+ In addition to being useful in its own right, this format also allows CmdStanR
133+ users to obtain draws in a similar format to ` rstan::extract() ` .
134+
135+ Suppose we have a parameter ` matrix[2,3] x ` . The ` rvar ` format lets you
136+ interact with ` x ` as if it's a ` 2 x 3 ` matrix and automatically applies operations
137+ over the many posterior draws of ` x ` . To instead directly access the draws of ` x `
138+ while maintaining the structure of the matrix use ` posterior::draws_of() ` .
139+ For example:
140+
141+ ``` {r structured-draws, eval = FALSE}
142+ draws <- posterior::as_draws_rvars(fit$draws())
143+ x_rvar <- draws$x
144+ x_array <- posterior::draws_of(draws$x)
145+ ```
146+
147+ The object ` x_rvar ` will be an ` rvar ` that can be used like a ` 2 x 3 ` matrix,
148+ with the draws handled behind the scenes. The object ` x_array ` will be a
149+ ` 4000 x 2 x 3 ` array (assuming ` 4000 ` posterior draws), which is the same as it
150+ would be after being extracted from the list returned by ` rstan::extract() ` .
0 commit comments