Hidden Markov models with serial correlation for identifying stock-recruitment regime shifts
Data files
Aug 07, 2025 version files 90.60 KB
-
HMSM_AR_1_Data_and_Codes.zip
87.36 KB
-
README.md
3.25 KB
Abstract
Resolving productivity changes is crucial to effective fisheries management as shifts in the stock-recruitment (SR) relationship redefine levels of sustainable removals. Hidden Markov models (HMMs) and state-space models are complementary methodologies for capturing discrete (regime-like) and continuous variations, respectively, in fisheries stock productivity. In this work, we combine the strengths of both approaches by developing HMMs with serial correlation and implementing them efficiently. To account for interactions between SR parameters and other components of stock assessment models, we embed hidden Markov SR models within the broader stock assessment framework. Additionally, we incorporate covariates into the transition probabilities of the HMM to address nonstationarity and substantially reduce model complexity. Simulation and case studies demonstrate the strong performance of this novel methodology.
https://doi.org/10.5061/dryad.31zcrjdxn
Description of the data and file structure
Files and variables
File: HMSM_AR_1_Data_and_Codes.zip
Description: This zip file includes the TMB codes and data used for the simulation studies presented in the paper:
Hidden Markov models with serial correlation for identifying stock-recruitment regime shifts by Shajitha Shahul Hameed, Noel G. Cadigan, Candemir Cigsar, Paul Regular, and Nan Zheng.
This zip file contains two main folders: Simulations and External_Fitting. It also contains an R script to implement the Viterbi algorithm.
1. Simulations
This folder includes the TMB (Template Model Builder)codes and data used for the simulation studies presented in the paper:
Hidden Markov models with serial correlation for identifying stock-recruitment regime shifts by Shajitha Shahul Hameed, Noel G. Cadigan, Candemir Cigsar, Paul Regular, and Nan Zheng.
It contains three subfolders:
- Regime_1: Simulation studies for a single regime.
- Regime_2: Simulation studies for two regimes.
- Regime_3: Simulation studies for three regimes.
Each subfolder contains the following:
- "model.cpp": TMB C++ template file for the regime-specific Hidden Markov Model with AR(1) error.
- "simulation_Regime_X.R": (where X is 1, 2, or 3) R script that:
- Generates simulated data
- Compiles the TMB model
- Runs parameter estimation
- Saves outputs for performance evaluation
2. External_Fitting
This folder contains the data and TMB codes used for the case studies in the paper. It includes two subfolders:
- 3NO_COD: Data and codes for the case study on 3NO cod.
- American_Plaice: Data and codes for the case study on 3LNO American plaice.
Each subfolder contains the following:
- "model.cpp": TMB C++ template file for fitting the regime-specific model to real data
- "fit_model.R": R script to:
- Load the observed stock and recruitment data
- Compile and run the TMB model
- Estimate parameters
- Extract fitted values and key model outputs
- Save results for visualization
3. Viterbi.R
The R script to implement the Viterbi algorithm, which can be used to decode the most probable sequence of hidden regimes (states) given the fitted model and estimated transition probabilities.
Required Packages:
R package: 'TMB'
System requirements: First, ensure that R is installed, then install Rtools, and finally install TMB.
How to run the code
For Simulations:
1. Navigate to the desired subfolder under Simulations/Regime_X.
2. Compile the corresponding C++ file using TMB::compile() in R.
3. Run the simulation script (e.g., simulation_Regime_1.R), which will:
- Generate data
- Fit the model
- Save results
For Case Studies:
1. Go to either External_Fitting/3NO_COD or External_Fitting/American_Plaice.
2. Compile the model.cpp file as instructed in the corresponding R script.
3. Run the R script (e.g., fit_model.R) to fit the model to real-world data.
4. Use Viterbi.R to decode the hidden states based on the fitted model outputs.
