Fits and predictions from samples and newdata

pp_eval(
  object,
  newdata = NULL,
  summary = TRUE,
  type = "fitted",
  probs = TRUE,
  rate = TRUE,
  prior = FALSE,
  which_y = "ct",
  varying = TRUE,
  arma = TRUE,
  nsamples = NULL,
  samples_format = "tidy",
  scale = "response",
  ...
)

Arguments

object

An mcpfit object.

newdata

A tibble or a data.frame containing predictors in the model. If NULL (default), the original data is used.

summary

Summarise at each x-value

type

One of:

  • "fitted": return fitted values. See also fitted()

  • "predict": return predicted values, using random dispersion around the central tendency (e.g., y_predict = rnorm(N, y_fitted, sigma_fitted) for family = gaussian()). See also predict().

  • "residuals": same as "predict" but the observed y-values are subtracted. See also residuals()

probs

Vector of quantiles. Only in effect when summary == TRUE.

rate

Boolean. For binomial models, plot on raw data (rate = FALSE) or response divided by number of trials (rate = TRUE). If FALSE, linear interpolation on trial number is used to infer trials at a particular x.

prior

TRUE/FALSE. Plot using prior samples? Useful for mcp(..., sample = "both")

which_y

What to plot on the y-axis. One of

  • "ct": The central tendency which is often the mean after applying the link function (default).

  • "sigma": The variance

  • "ar1", "ar2", etc. depending on which order of the autoregressive effects you want to plot.

varying
  • TRUE: All varying effects (fit$pars$varying).

    • FALSE: No varying efects (c()).

    • Character vector: Only include specified varying parameters - see fit$pars$varying.

arma

Whether to include autoregressive effects.

  • TRUE: Compute autoregressive residuals. Requires the response variable in newdata.

  • FALSE: Disregard the autoregressive effects. For family = gaussian(), predict() just use sigma for residuals.

nsamples

Integer or NULL. Number of samples to return/summarise. If there are varying effects, this is the number of samples from each varying group. NULL means "all". Ignored if both are FALSE. More samples trade speed for accuracy.

samples_format

One of "tidy" or "matrix". Controls the output format when summary == FALSE. See more under "value"

scale

One of

  • "response": return on the observed scale, i.e., after applying the inverse link function.

  • "linear": return on the parameter scale (where the linear trends are modelled).

...

Currently unused

Value

  • If summary = TRUE: A tibble with the posterior mean for each row in newdata, If newdata is NULL, the data in fit$data is used.

  • If summary = FALSE and samples_format = "tidy": A tidybayes tibble with all the posterior samples (Ns) evaluated at each row in newdata (Nn), i.e., with Ns x Nn rows. If there are varying effects, the returned data is expanded with the relevant levels for each row.

    The return columns are:

    • Predictors from newdata.

    • Sample descriptors: ".chain", ".iter", ".draw" (see the tidybayes package for more), and "data_row" (newdata rownumber)

    • Sample values: one column for each parameter in the model.

    • The estimate. Either "predict" or "fitted", i.e., the name of the type argument.

  • If summary = FALSE and samples_format = "matrix": An N_draws X nrows(newdata) matrix with fitted/predicted values (depending on type). This format is used by brms and it's useful as yrep in bayesplot::ppc_* functions.

See also