Skip to contents

Draws of the expected response.

Usage

# S3 method for class 'kb_fit'
posterior_epred(
  object,
  new_data = NULL,
  ...,
  new_levels = c("average", "sample"),
  representative_site = NULL
)

Arguments

object

A kb_fit object.

new_data

A data frame with the fit's predictor column (and optional site and year columns), or NULL for the observed data. year may be numeric or character: 2022 and "2022" match the same fitted year.

...

These dots are for future extensions and must be empty.

new_levels

A string giving how uncertainty is estimated for a site or year not in the data used to fit the model, or when new_data has no site or year column. Sites and years in the model fit always use their own estimates. One of:

  • "average" (the default): the typical site or year. The site and year effects are set to 0, their mean, so the interval does not include among-site or among-year variation. Use it to describe an average site or year.

  • "sample": a new effect for each new site or year, drawn from the estimated variation among sites or among years (the random-effect standard deviation). The point estimate is equivalent, but the interval is wider since it also includes that variation. Use it to get realistic uncertainty about a particular site or year that the model has no information on. The interval varies slightly between calls; use set.seed() to reproduce it.

representative_site

A character vector of sites in the fit whose effects a new site adopts (averaged when several are named), or NULL (the default) to follow new_levels.

Value

A draws-by-observations (D x N) matrix.

Details

Each draw is the expected response, the mean of the fit's likelihood (see kb_model_describe()), given that draw's parameters. For a cover calibration with a presence part, it includes the probability that the plot has plants present. For a Nereocystis weight fit, which is modelled on the log scale, it is the mean weight, not the median.

For draws of new observations, which include residual variation, use posterior_predict().

A site (and optionally year) column in new_data with levels in the fit gives predictions for those levels. With new_data = NULL the observed data is used, with its sites and years.

Examples

ep <- posterior_epred(fit_weight_sim_nereo)
dim(ep)
#> [1] 1500  660