Skip to contents

Predict the expected size at the rows of new_data, or at the observed data when new_data = NULL. Equivalent to kb_predict_size().

Usage

# S3 method for class 'kb_fit_size'
predict(
  object,
  new_data = NULL,
  ...,
  new_levels = c("average", "sample"),
  representative_site = NULL,
  conf_level = 0.95,
  estimate = stats::median,
  sig_fig = 3
)

Arguments

object

A kb_fit_size object.

new_data

A data frame with optional site and year columns, one row per prediction, or NULL to predict at 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.

conf_level

A number greater than 0 and less than 1 giving the compatibility-interval level.

estimate

A function that reduces a numeric vector of posterior draws to a single estimate, such as median or mean.

sig_fig

A whole number of significant figures for summary output.

Value

A kb_predictions object.

Examples

predict(fit_size_sim_nereo, data.frame(site = "otter_cove"))
#> <kb_predictions> response: diameter_mm | by: site
#> # A tibble: 1 × 4
#>   site       estimate lower upper
#>   <chr>         <dbl> <dbl> <dbl>
#> 1 otter_cove     25.6  23.3    28