lppd {bbsBayes}R Documentation

Calculate log posterior predictive density

Description

lppd Calculate log posterior preditive density (LPPD) for the supplied model.

Usage

lppd(jags_data = NULL, jags_mod = NULL, pointwise = FALSE)

Arguments

jags_data

Data prepared by prepare_jags_data, used for input to the JAGS model

jags_mod

JAGS list generated by run_model

pointwise

If set to TRUE, a data frame is returned that contains the pointwise LPPD for each count. Defaults to FALSE

Details

NOTE: in order to calculated LPPD, the model MUST track the parameter "lambda". In species that are data-rich, such as Wood Thrush, this produces extremely large JAGS objects, and takes up a considerable amount of memory when simulating with run_model

Value

Data frame of pointwise LPPD by count if pointwise is set to TRUE. Double precision numerical value of LPPD if pointwise is set to FALSE.

Examples

# Toy example with Pacific Wren sample data
# First, stratify the sample data

strat_data <- stratify(by = "bbs_cws", sample_data = TRUE)

# Prepare the stratified data for use in a JAGS model.
jags_data <- prepare_jags_data(strat_data = strat_data,
                               species_to_run = "Pacific Wren",
                               model = "firstdiff",
                               min_year = 2014,
                               max_year = 2018)

# Now run a JAGS model. Make sure to track the lambda parameter here

jags_mod <- run_model(jags_data = jags_data,
                      n_adapt = 0,
                      n_burnin = 0,
                      n_iter = 5,
                      n_thin = 1,
                      parameters_to_save = c("n",
                                             "lambda"))

# Output LPPD
lppd(jags_data = jags_data,
     jags_mod = jags_mod)


[Package bbsBayes version 2.3.6.2020 Index]