Skip to contents

Draws from the expectation of the posterior predictive distribution (response-scale expected weight, exp of the linear predictor).

Usage

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

Arguments

object

A kb_fit_weight object.

new_data

A data frame with a diameter column (and optional site / year columns), or NULL for the observed data.

...

Unused.

new_levels

A string, one of "sample" or "average", controlling how random effects that are not conditioned on are treated (factors absent from the prediction, and any new level not seen in the fit). "sample" draws a new random effect from Normal(0, sd), widening the interval to include between-group variation; "average" holds the random effects at zero, giving the typical group. Known levels are always conditioned on. "sample" draws fresh randomness on each call, so set a seed with set.seed() for a reproducible interval.

representative_site

A character vector of site levels present in the fit, or NULL (the default). When supplied, a new or absent site takes its site main effects (intercept and slope) from the named reference site (the per-draw average when several are named), instead of the new_levels treatment; the site:year interaction still follows new_levels.

Value

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

Details

Conditioning is inferred from the grouping columns present in new_data: a site (and optionally year) column with known levels is conditioned on; factors with no column are handled by new_levels. With new_data = NULL the observed data is used and conditioned on its site and year, so the central estimate agrees with augment().

Examples

ep <- posterior_epred(fit_weight_sim_nereo)
dim(ep)
#> [1] 800 234