prepare_inseason_inputs.RdPrepares 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)A valid DBI database connection to the SRJPE model run database.
The stream identifier (character) for which the model is to be fit.
The site identifier (character) corresponding to the sampling location.
Logical; if TRUE, includes covariate effects (e.g., flow) in the model.
Logical; if TRUE, fits an autocorrelated version of the model (adds lag-1 structure).
A named list containing:
inputsList with data and inits used by STAN.
covariate_effectLogical indicating covariate inclusion.
autocorrelationLogical indicating autocorrelation.
model_nameCharacter name of the selected STAN model.
streamInput stream name.
siteInput site name.
year_lookupVector of years used to match indices to results.
week_lookupVector of weeks used to match indices to results.
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.
Other Prepare Model Inputs:
prepare_P2S_inputs(),
prepare_pCap_inputs(),
prepare_stock_recruit_inputs(),
prepare_survival_inputs()