Learn R Programming

modelbased (version 0.5.0)

estimate_response.stanreg: Generates predictions for Bayesian models

Description

Generates predictions for Bayesian models

Usage

# S3 method for stanreg
estimate_response(
  model,
  data = NULL,
  transform = "response",
  include_smooth = TRUE,
  include_random = TRUE,
  length = 25,
  preserve_range = TRUE,
  predict = "response",
  keep_draws = FALSE,
  draws = NULL,
  seed = NULL,
  centrality = "median",
  ci = 0.95,
  ci_method = "hdi",
  ...
)

# S3 method for stanreg estimate_link( model, data = "grid", transform = "response", include_smooth = TRUE, include_random = FALSE, length = 25, preserve_range = TRUE, predict = "link", keep_draws = FALSE, draws = NULL, seed = NULL, centrality = "median", ci = 0.95, ci_method = "hdi", ... )

# S3 method for data.frame estimate_response( model, data = NULL, transform = "response", include_smooth = TRUE, include_random = FALSE, length = 25, preserve_range = TRUE, predict = "link", keep_draws = FALSE, draws = NULL, seed = NULL, centrality = "median", ci = 0.95, ci_method = "hdi", ... )

# S3 method for data.frame estimate_link( model, data = "grid", transform = "response", include_smooth = TRUE, include_random = FALSE, length = 25, preserve_range = TRUE, predict = "link", keep_draws = FALSE, draws = NULL, seed = NULL, centrality = "median", ci = 0.95, ci_method = "hdi", ... )

Arguments

model

A statistical model.

data

A data frame with model's predictors to estimate the response. If NULL, the model's data is used. If "grid", the model matrix is obtained (through visualisation_matrix).

transform

Can be "none" (default for contrasts), "response" (default for means), "mu", "unlink", "log". "none" will leave the values on scale of the linear predictors. "response" will transform them on scale of the response variable. Thus for a logistic model, "none" will give estimations expressed in log-odds (probabilities on logit scale) and "response" in terms of probabilities.

include_smooth

Should the smooth terms (in General Additive Models - GAM) be included?

include_random

Should it take the random effects into account? Can be TRUE, FALSE or a formula indicating which group-level parameters to condition on when making predictions. The data argument may include new levels of the grouping factors that were specified when the model was estimated, in which case the resulting posterior predictions marginalize over the relevant variables (see posterior_predict.stanreg).

length

Passed to visualisation_matrix if data = "grid".

preserve_range

Passed to visualisation_matrix if data = "grid".

predict

Can be "response" (default) or "link". The former predicts the the outcome per se, while the latter predicts the link function (i.e., the regression "line"), equivalent to estimating the fit. In other words, estimate_response(model, predict="link") is equivalent to estimate_link(model).

keep_draws

If FALSE, will summarise the posterior the obtained distributions. If TRUE, will keep all prediction iterations (draws).

draws

An integer indicating the number of draws to return. The default and maximum number of draws is the size of the posterior sample contained in the model.

seed

An optional seed to use.

centrality

The point-estimates (centrality indices) to compute. Character (vector) or list with one or more of these options: "median", "mean", "MAP" or "all".

ci

Credible Interval (CI) level. Default to 0.89 (89%). See ci for further details.

ci_method

The type of index used for Credible Interval. Can be "HDI" (default, see hdi), "ETI" (see eti) or "SI" (see si).

...

Arguments passed to or from other methods.

Value

A dataframe of predicted values.

Examples

Run this code
# NOT RUN {
library(modelbased)
# }
# NOT RUN {
if (require("rstanarm") && require("brms")) {
  model <- stan_glm(Sepal.Width ~ Species * Petal.Length, data = iris)
  estimate_response(model)
  estimate_link(model)

  model <- stan_glmer(Sepal.Width ~ Petal.Length + (1 | Species), data = iris)
  estimate_response(model)
  estimate_link(model)

  library(brms)
  model <- brms::brm(Sepal.Width ~ Petal.Length, data = iris)
  estimate_response(model)
  estimate_link(model)
}
# }

Run the code above in your browser using DataLab