Adds draws from the posterior predictive distribution of a rethinking model to a data frame. Provides support for tidybayes::predicted_draws() / tidybayes::add_predicted_draws() for models from the rethinking package.

# S3 method for ulam
predicted_draws(
  object,
  newdata,
  value = ".prediction",
  ...,
  ndraws = NULL,
  seed = NULL,
  re_formula = NULL,
  category = ".category"
)

# S3 method for quap
predicted_draws(
  object,
  newdata,
  value = ".prediction",
  ...,
  ndraws = NULL,
  seed = NULL,
  re_formula = NULL,
  category = ".category"
)

# S3 method for map
predicted_draws(
  object,
  newdata,
  value = ".prediction",
  ...,
  ndraws = NULL,
  seed = NULL,
  re_formula = NULL,
  category = ".category"
)

# S3 method for map2stan
predicted_draws(
  object,
  newdata,
  value = ".prediction",
  ...,
  ndraws = NULL,
  seed = NULL,
  re_formula = NULL,
  category = ".category"
)

Arguments

object

A model fit using rethinking::quap(), rethinking::ulam(), rethinking::map(), or rethinking::map2stan().

newdata

Data frame to generate predictions from.

value

The name of the output column:

  • for [add_]epred_draws(), defaults to ".epred".

  • for [add_]predicted_draws(), defaults to ".prediction".

  • for [add_]linpred_draws(), defaults to ".linpred".

  • for [add_]residual_draws(), defaults to ".residual"

...

Optional parameters passed on to rethinking::sim(). The most pertinent are:

  • post: Optional samples from posterior. If missing, simulates samples using ndraws.

ndraws

The number of draws per prediction to return. When NULL (the default), rethinking::ulam() and rethinking::map2stan() models return all draws; rethinking::quap() and rethinking::map() models return 5000 draws.

seed

A seed to use when subsampling draws (i.e. when ndraws is not NULL).

re_formula, category

Not used with this model type.