Adds draws from the posterior link-level predictor of a rethinking model to a data frame. Provides support for tidybayes::linpred_draws() / tidybayes::add_linpred_draws() / for models from the rethinking package.

# S3 method for ulam
linpred_draws(
  object,
  newdata,
  value = ".value",
  ...,
  post = NULL,
  ndraws = NULL,
  seed = NULL,
  dpar = FALSE,
  re_formula = NULL,
  category = ".category"
)

# S3 method for quap
linpred_draws(
  object,
  newdata,
  value = ".value",
  ...,
  post = NULL,
  ndraws = NULL,
  seed = NULL,
  dpar = FALSE,
  re_formula = NULL,
  category = ".category"
)

# S3 method for map
linpred_draws(
  object,
  newdata,
  value = ".value",
  ...,
  post = NULL,
  ndraws = NULL,
  seed = NULL,
  dpar = FALSE,
  re_formula = NULL,
  category = ".category"
)

# S3 method for map2stan
linpred_draws(
  object,
  newdata,
  value = ".value",
  ...,
  post = NULL,
  ndraws = NULL,
  seed = NULL,
  dpar = FALSE,
  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::link(). The most pertinent are:

  • replace: Optional named list of samples to replace inside posterior samples. See examples in rethinking::link().

post

Optional samples from posterior. When missing, linpred_draws() extracts these in advance, bypassing rethinking::link()'s normal process (rethinking::link() uses rstan::extract(), which unfortunately permutes samples, breaking the ability of the .draw column to be meaningfully joined with output from other methods, like spread_draws()).

ndraws

The number of draws per fit 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).

dpar

Should distributional regression parameters be included in the output? In rethinking models, these correspond to the linear submodels returned by rethinking::link(). If TRUE, distributional regression parameters are included in the output as additional columns named after each parameter (alternative names can be provided using a list or named vector, e.g. c(sigma.hat = "sigma") would output the "sigma" parameter from a model as a column named "sigma.hat"). If FALSE (the default), distributional regression parameters are not included; instead, just the first linear submodel returned by rethinking::link() is used.

re_formula, category

Not used with this model type.