Skip to contents

This function does simulates from the posterior of a created stan model, therefore providing a fast and efficient way to project coefficients obtained from Bayesian models to new/novel contexts.

Usage

posterior_predict_stanfit(
  obj,
  form,
  newdata,
  type = "predictor",
  family = NULL,
  offset = NULL,
  draws = NULL,
  intercept = NULL,
  link = NULL,
  feature_names = NULL
)

Arguments

obj

A "stanfit" object from rstan or a "CmdStanFit" object from cmdstanr.

form

A formula object created for the DistributionModel.

newdata

A data.frame with new data to be used for prediction.

type

A character of whether the linear predictor or the response is to be summarized.

family

A character giving the family for simulating linear response values (Default: NULL)

offset

A vector with an optionally specified offset.

draws

numeric indicating whether a specific number of draws should be taken.

intercept

Optional intercept parameter name or fixed numeric intercept.

Optional inverse-link name. Supports "log", "logit", "cloglog", and "identity".

feature_names

Optional ordered feature names matching the Stan beta vector.

Value

A data.frame of posterior predictions summarized over draws.

Examples

if (FALSE) { # \dontrun{
newdata <- data.frame(temperature = c(0.1, 0.4, 0.8))
posterior_predict_stanfit(
  obj = stan_fit,
  form = observed ~ temperature,
  newdata = newdata,
  family = "binomial",
  type = "response"
)
} # }