Prepares data inputs required to fit the hierarchical Bayesian in-season STAN model for estimating fish abundance across multiple years and weeks. This includes transforming model results, constructing covariate matrices, and assembling input structures required by the STAN model.

prepare_inseason_inputs(con, stream, site, covariate_effect, autocorrelation)

Arguments

con

A valid DBI database connection to the SRJPE model run database.

stream

The stream identifier (character) for which the model is to be fit.

site

The site identifier (character) corresponding to the sampling location.

covariate_effect

Logical; if TRUE, includes covariate effects (e.g., flow) in the model.

autocorrelation

Logical; if TRUE, fits an autocorrelated version of the model (adds lag-1 structure).

Value

A named list containing:

inputs

List with data and inits used by STAN.

covariate_effect

Logical indicating covariate inclusion.

autocorrelation

Logical indicating autocorrelation.

model_name

Character name of the selected STAN model.

stream

Input stream name.

site

Input site name.

year_lookup

Vector of years used to match indices to results.

week_lookup

Vector of weeks used to match indices to results.

Details

This function extracts juvenile abundance estimates from the model database, aligns them with a custom week-based calendar, calculates summary statistics (e.g., mean, CV, log-scale SD) for annual and weekly abundance, processes covariate values (e.g., early season flows), and assembles the data and initial values for the in-season STAN model.

The function optionally includes covariate effects and autocorrelation, which are passed as flags and incorporated into the model specification.