Draws from the posterior predictive distribution: replicate responses
(weights, plant sizes, dry:wet ratios, carbon or nitrogen fractions, or in
situ survey biomass)
carrying both parameter uncertainty and observation noise from the model's
likelihood. With new_data = NULL the replicates are at the observed data,
as plotted by pp_check().
Usage
# S3 method for class 'kb_fit'
posterior_predict(
object,
new_data = NULL,
...,
new_levels = c("average", "sample"),
representative_site = NULL
)Arguments
- object
A
kb_fitobject.- new_data
A data frame with the fit's predictor column (and optional
siteandyearcolumns;canopy_area_m2,plot_area_m2, andcanopy_tide_height_mfor a cover calibration fit), orNULLto predict at the observed data.yearmay be numeric or character:2022and"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_datahas nositeoryearcolumn. 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; useset.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 follownew_levels.
Details
Site and year columns in new_data are handled as in posterior_epred().
The observation noise follows the likelihood of the fit's model (see
kb_model_describe()). A cover calibration fit with a presence part also
draws whether each survey holds plants, and a survey drawn without plants
is 0. Each row's spread includes the coefficient of variation of its survey
biomass, from biomass_kg_m2 and biomass_sd_kg_m2 columns or a
biomass_kg_m2 column of draws, and the residual alone when new_data has
neither.
Repeated calls return different draws; use set.seed() to reproduce them.
Examples
set.seed(1)
pp <- posterior_predict(fit_weight_sim_nereo)
dim(pp)
#> [1] 1500 660