---
title: "Appendix: Description of the Assessment Models in MSEtool"
author: "Tom Carruthers (<t.carruthers@oceans.ubc.ca>) 
         Adrian Hordyk  (<a.hordyk@oceans.ubc.ca>),
         Quang Huynh (<q.huynh@oceans.ubc.ca>)"
date: "`r Sys.Date()`"
output: 
  rmarkdown::html_vignette:
    toc: true
    number_sections: true
vignette: >
  %\VignetteIndexEntry{Appendix: Description of the Assessment Models in MSEtool}
  %\VignetteEncoding{UTF-8}
  %\VignetteEngine{knitr::rmarkdown}
---
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: "all"} } });
</script>

<style type="text/css">

body{ /* Normal  */
   font-size: 12px;
}
td {  /* Table  */
   font-size: 8px;
}
h1 { /* Header 1 */
 font-size: 18px;
 color: DarkBlue;
}
h2 { /* Header 2 */
 font-size: 15px;
 color: DarkBlue;
}
h3 { /* Header 3 */
 font-size: 14px;
 color: DarkBlue;
}
code.r{ /* Code block */
  font-size: 10px;
}
pre { /* Code block */
  font-size: 10px
}
</style>


```{r set options, echo = FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
knitr::opts_chunk$set(dpi=85)
options(width = 650)
```

<br>

# Introduction

In MSEtool, assessment models are of class `Assess`. This appendix provides a brief description and references for the `Assess` objects. Further details regarding parameterization, e.g., fixing parameters, and tuning, e.g., adjusting start parameters, are provided in the function documentation.

## Note

For LaTeX equation rendering, it is recommended that this vignette be viewed in a HTML browser. This can be done with the `browseVignettes` function in R:

```{r, eval = FALSE}
browseVignettes("MSEtool")
```

# Delay Difference (DD_TMB) Model

There has been a rich history of development for the delay difference model for catch and index data. For the formulation used in MSEtool, the most relevant citations are Chapter 9 of Hilborn and Walters (1992) and Carruthers et al. (2012).

## Growth
Growth in weight-at-age $w_a$ follows the recursive Ford-Brody equation:
$$w_a = \rho + \tilde\alpha w_{a-1}.$$
We can obtain $\tilde\alpha$ and $\rho$ for the delay difference model if weight is also described by the equation 
$$w_a = W_{\infty}(1 - \exp[K\{a-a_0\}])^b.$$ 
Parameter $\tilde\alpha$ is solved in the limiting case where $w_a = w_{a-1} = W_{\infty}$ as $t \rightarrow \infty$,
$$\tilde\alpha = W_{\infty}(1 - \rho). $$
Substitution of equation 3 into equation 1 solves for $\rho$, 
$$\rho = \dfrac{w_a - W_{\infty}}{w_{a-1} - W_{\infty}}.$$
In MSEtool, $a = k+2$ is arbitrarily chosen to calculate $\rho$, where $k$ is the age of knife-edge selectivity. From catch and effort data alone, the age corresponding to the length of 50% maturity is chosen for $k$.

## Dynamics equations
The population biomass $B_t$ and abundance $N_t$ in year $t$ is given by
$$ \begin{align}
B_t &= s_{t-1}(\tilde{\alpha} N_{t-1} + \rho B_{t-1}) + w_k R_t\\
N_t &= s_{t-1} N_{t-1} + R_t,
\end{align}$$
where $R_t$ is the recruitment (defined in the next section) at age $k$ and $w_k$ is the weight of recruits. Survival $s_t$ is defined as
$$ s_t = (1 - u_t)\exp(-M), $$
where $u_t$ is the annual harvest rate and $M$ is the instantaneous natural mortality rate. By conditioning the model on effort (as the ratio of the catch and index), the harvest rate is
$$ u_t = 1 - \exp(-qf_t), $$
where $q$ is the estimated catchability coefficient and $f_t$ is the effort in year $t$. 

The predicted catch is 
$$\hat{C}_t = \hat{u}_t \hat{B}_t ,$$
where the circumflex $^$ denotes the model estimate.

The log-likelihood $L$ of the observed catch $C_t$ over years $t = 1, ..., T$, assuming a lognormal distribution, is
$$L(C_t)\propto -T \log\sigma - 0.5\sum_{t=1}^{T}\left(\dfrac{\log(C_t/\hat{C}_t)}{\sigma}\right)^2,$$
where $\sigma$ is the standard deviation of the lognormal distribution.

## Stock-recruit parameters


### Beverton-Holt relationship
Assuming a Beverton-Holt stock recruit relationship and spawning occurring after fishing in each annual time step, then recruitment (at age $k$) in year $t$ is:
$$ R_t = \dfrac{\alpha B_{t-k}(1 - u_{t-k})}{1 + \beta B_{t-k}(1 - u_{t-k})},$$
where $B_{t-k}(1-u_{t-k})$ is the population biomass after fishing in year $t-k$ and
$$ \begin{align}
\alpha &= \dfrac{4hR_0}{(1-h)B_0}\\
\beta &= \dfrac{5h-1}{(1-h)B_0},
\end{align}$$

Virgin recruitment $R_0$ and steepness $h$ are estimated parameters, with virgin biomass $B_0$ calculated as
$$B_0 =  R_0 \phi_0.$$
The virgin biomass per recruit $\phi_0$ is
$$\phi_0 = \dfrac{\tilde{\alpha} \exp(-M) + w_k (1 - \exp(-M))}{1 - \rho \exp(-M)}$$
and is obtained by solving the equilibrium equation for biomass, $B_0 = \exp(M)(\tilde{\alpha}N_0 + \rho B_0) + w_k R_0$, is solved for $B_0/R_0$, with $N_0 = R_0/(1−\exp(-M))$.


### Ricker equation
Assuming a Ricker stock-recruit relationship, the recruitment is
$$ R_t = \alpha B_{t-k}(1 - u_{t-k})\exp[-\beta B_{t-k}(1 - u_{t-k})],$$
where
$$ \begin{align}
\alpha &= \dfrac{(5h)^{1.25} R_0}{B_0}\\
\beta &= \dfrac{5}{4B_0}\log(5h),
\end{align}$$

and $B_0$ is calculated as in equation 14.

## State-space version (DD_SS)
In the state-space version, annual recruitment deviates from the stock-recruit relationship are estimated. The recruitment in year $t$ is
$$ R_t = \dfrac{\alpha B_{t-k}}{1 + \beta B_{t-k}} \exp(\delta_t - 0.5 \tau^2)$$
or
$$ R_t = \alpha B_{t-k}\exp(-\beta B_{t-k})\exp(\delta_t - 0.5 \tau^2),$$
where $\delta_t \sim N(0, \tau^2)$ are recruitment deviations in lognormal space and $\tau$ is the standard deviation of the recruitment deviations.

The log-likelihood of the log-recruitment deviations $\delta_t$ over years $t=k,\ldots...,T$ is
$$L(\delta_t) \propto -(T-k) \log\tau - 0.5\sum_{t=k}^{T}\left(\dfrac{\log(\delta_t)}{\tau}\right)^2.$$


# Surplus-production (SP) model
## Dynamics equations
The surplus production model uses the Fletcher (1978) formulation. The biomass $B_t$ in year $t$ is 
$$B_t = B_{t-1} + P_{t-1} - C_{t-1},$$
where $C_t$ is the observed catch and $P_t$ is the surplus production given by:
$$P_t = \gamma MSY \left(\dfrac{B_t}{K}-\left[\dfrac{B_t}{K}\right]^n\right), $$
where $K$ is the carrying capacity, $MSY$ is the estimated maximum sustainable yield, and $n$ is the parameter that controls shape of the production curve, and
$\gamma$ is
$$\gamma = \dfrac{1}{n-1}n^{n/(n-1)}.$$ 

By conditioning the model on observed catch, the predicted index $\hat{I}_t$ is
$$\hat{I}_t = \hat{q} \hat{B}_t $$
and the harvest rate is
$$\hat{u}_t = \dfrac{C_t}{\hat{B}_t}.$$
The log-likelihood $L$ of the observed index $I_t$ over years $t = 1, ..., T$, assuming a lognormal distribution, is
$$L(I_t)\propto -T \log\sigma - 0.5\sum_{t=1}^{T}\left(\dfrac{\log(I_t/\hat{I}_t)}{\sigma}\right)^2,$$

## Derivation of SP model parameters from MSY and UMSY estimates

From estimates of leading parameters $u_{MSY}$ and $MSY$, the biomass $B_{MSY}$ at $MSY$ is
$$B_{MSY} = \dfrac{MSY}{u_{MSY}},$$
the carrying capacity $K$ is
$$K = n^{1/(n-1)} B_{MSY} ,$$
and the intrinsic rate of population increase $r$ is
$$ r = n u_{MSY}.$$
The production parameter $n$ is typically fixed and the model has a symmetric productive curve ($B_{MSY}/K = 0.5$) when $n = 2$.

## State-space version (SP_SS)
In the state-state version, annual biomass deviates are estimated as random effects. Similar to Meyer and Millar (1999), the biomass $B_t$ in year $t$ is 
$$B_t = (B_{t-1} + P_{t-1} - C_{t-1})\exp(\delta_t - 0.5 \tau^2),$$
where $\delta_t \sim N(0, \tau^2)$ are biomass deviations in lognormal space and $\tau$ is the standard deviation of the biomass deviations.

The log-likelihood of the deviations $\delta_t$ is
$$L(\delta_t) \propto -T \log\tau - 0.5\sum_{t=1}^{T}\left(\dfrac{\log(\delta_t)}{\tau}\right)^2.$$

# Statistical catch-at-age model (SCA and SCA2) 
## Dynamics equations
The statistical catch-at-age model used in MSEtool assumes pulse fishing at the beginning of each annual time-step, following the parameterization of Forrest et al. (2008). The model uses a time series of total catch (in weight), index, and catch-at-age observations, as well as information on weight, maturity, natural mortality at age.

The population abundance $N_{a,t}$ of age $a$ in year $t$ is
$$ N_{a,t} = 
\begin{cases} 
      R_t & a = 1\\
      N_{a-1,t-1} (1 - v_{a-1} u_{t-1}) \exp(-M_{a-1}) & a = 2, \ldots, A-1\\
      N_{a-1,t-1} (1 - v_{a-1} u_{t-1}) \exp(-M_{a-1}) + N_{a,t-1} (1 - v_a u_{t-1}) \exp(-M_a) & a = A 
\end{cases},
$$
where $R_t$ is the recruitment (age-1), $v_a$ is the vulnerability at age $a$, $u_t$ is the annual harvest rate, $M_a$ is the instantaneous natural mortality rate at age $a$, and $A$ is the maximum age in the model as a plus-group accumulator age.

Assuming logistic vulnerability, the vulnerability is:
$$v_a = \left[1 + \exp\left(-\log(19) \dfrac{a - a_{50}}{a_{95} - a_{50}}\right)\right]^{-1}, $$
where $a_{50}$ and $a_{95}$ are the estimated ages of 50% and 95% vulnerability, respectively.

Assuming dome vulnerability, a double Gaussian formulation is used:
$$ v_a = 
\begin{cases} 
      f(a; a_{asc}, \sigma_{asc}) & a \le a_{asc}\\
      1 & a_{asc} \lt a \le a_{des}\\
      f(a; a_{des}, \sigma_{des}) & a \gt a_{des}
\end{cases},
$$
where $f(a; \mu, \sigma) = \exp(-0.5 (a - \mu)^2/\sigma^2)$ is the normal probability density function scaled to one at $\mu$. Four parameters are estimated: $a_{50}$ the age of 50% vulnerability (ascending limb), $a_{asc}$ the first age of full vulnerability, $a_{des}$ the last age of full vulnerability, and $v_A$ the vulnerability at the maximum age in the model. The $\mu$ and $\sigma$ for both the ascending and descending limbs of the double-normal equation are estimated parameters. From these four parameters, $\sigma_{asc} = \sqrt{(a_{50} - \mu_{asc})^2/\log(4)}$ and $\sigma_{des} = \sqrt{-0.5(A - \mu_{des})^2/\log(v_A)}$ can be derived.

The vulnerable biomass $VB_t$ in year $t$ is
$$VB_t = \sum_{a=1}^A v_a w_a N_{a,t},$$
where weight-at-age $w_a$ is given by 
$$w_a = W_{\infty}(1 - \exp[K\{a-a_0\}])^b.$$ 

The mature spawning biomass $E_t$ is given by
$$E_t = \sum_{a=1}^A m_a w_a N_{a,t},$$
where maturity at age $m_a$ is
$$m_a = \left[1 + \exp\left(-\log(19) \dfrac{a - \tilde{a}_{50}}{\tilde{a}_{95} - \tilde{a}_{50}}\right)\right]^{-1}, $$
where $\tilde{a}_{50}$ and $\tilde{a}_{95}$ are the ages of 50% and 95% maturity, respectively.

By conditioning the model on catch in weight $Y_t$, the estimated annual harvest rate $\hat{u}_t$ is
$$\hat{u}_t = Y_t / \widehat{VB}_t .$$
The estimated catch at age $\hat{C}_{a,t}$ is
$$\hat{C}_{a,t} = \hat{v}_a \hat{u}_t \hat{N}_{a,t}.$$
The log-likelihood $L$ of the observed catch at age $C_{a,t}$ over years $t = 1, ..., T$, assuming a multinomial distribution, is
$$L(C_{a,t})\propto \sum_{t=1}^T \left(N_t \sum_{a=1}^A p_{a,t} \log(\hat{p}_{a,t}) \right),$$
where $N_t$ is the sample size of catch-at-age observations in year $t$, $p_{a,t}$ and $\hat{p}_{a,t}$ are the observed and predicted
proportions of catch-at-age.

If a lognormal distribution for the observed catch at age proportions is assumed, then the likelihood is
$$L(p_{a,t})\propto -\log\left(\sqrt{\dfrac{0.01}{\hat{p}_{a,t}}}\right) -0.5\left(\log(p_{a,t}/\hat{p}_{a,t})/\sqrt{\dfrac{0.01}{\hat{p}_{a,t}}}\right)^2 $$

The estimated index $\hat{I}_t$, assuming that it is an index for total biomass, is
$$ \hat{I}_t = \hat{q} \hat{B}_t,$$
where $B_t = \sum_{a=1}^A w_a N_{a,t}$. A function argument allows for the user to specify that the observed index is for vulnerable or spawning biomass. 

The log-likelihood $L$ of the observed index $I_t$ over years $t = 1, ..., T$, assuming a lognormal distribution, is
$$L(I_t)\propto -T \log\sigma - 0.5\sum_{t=1}^{T}\left(\dfrac{\log(I_t/\hat{I}_t)}{\sigma}\right)^2.$$

## Estimation of recruitment and reference points

There are two variants of the statistical catch-at-age model for estimation of recruitment and reference points. In function `SCA`, productivity parameters $R_0$ and $h$ are estimated in the assessment model. Annual recruitment is estimated as deviations from the resulting stock-recruitment relationship within the model. MSY reference points are derived from the estimates of $R_0$ and $h$.

In `SCA2`, no stock-recruit relationship is assumed in the assessment model, i.e., annual recruitment is estimated as deviations from the mean recruitment over the observed time series, similar to Cadigan (2016). After the assessment, a stock-recruit function can be fitted post-hoc to the recruitment and spawning stock biomass estimates from the assessment model to obtain MSY reference points. 

### Stock-recruit function in assessment model (SCA)

#### Beverton-Holt stock-recruit function

Recruitment $R_t$ in year $t$ is
$$ R_t = \dfrac{\alpha E_{t-1}}{1 + \beta E_{t-1}} \exp(\delta_t - 0.5 \tau^2),$$
where $\delta_t \sim N(0, \tau^2)$ are recruitment deviations from the stock-recruit relationship in lognormal space and $\tau$ is the standard deviation of the recruitment deviations. Parameters $\alpha$ and $\beta$ are defined as
$$ \begin{align}
\alpha &= \dfrac{4hR_0}{(1-h)B_0}\\
\beta &= \dfrac{5h-1}{(1-h)B_0},
\end{align}$$
where $B_0 = R_0 \phi_0$. The biomass per recruit $\phi_0$ is calculated as $\phi_0 = \sum_{a=1}^A m_a w_a l_a$, where
$$
l_a = 
\begin{cases} 
      1 & a = 1\\
      l_{a-1} \exp(-M_{a-1}) & a = 2, \ldots, A-1\\
      \dfrac{l_{a-1} \exp(-M_{a-1})}{1 - \exp(-M_a)} & a = A \\
\end{cases}. 
$$

#### Ricker stock-recruit function

Recruitment $R_t$ in year $t$ is
$$ R_t = \alpha E_{t-1} \exp(-\beta E_{t-1}) \exp(\delta_t - 0.5 \tau^2),$$
where
$$ \begin{align}
\alpha &= \dfrac{(5h)^{1.25} R_0}{B_0}\\
\beta &= \dfrac{5}{4B_0}\log(5h).
\end{align}$$


### No stock-recruit function in assessment model (SCA2)

Recruitment $R_t$ in year $t$ is
$$R_t = \bar{R} \exp(\delta_t - 0.5 \tau^2), $$
where $\delta_t \sim N(0, \tau^2)$ are recruitment deviations in lognormal space from the estimated mean recruitment $\bar{R}$ and $\tau$ is the standard deviation of the recruitment deviations. Typically, $\tau$ is set to 1 so that recruitment is estimated almost as free parameters (Cadigan, 2016).

### Likelihood of recruitment deviations
The log-likelihood of the log-recruitment deviations $\delta_t$ over years $t=1,\ldots...,T$ is
$$L(\delta_t) \propto -T \log\tau - 0.5\sum_{t=1}^{T}\left(\dfrac{\log(\delta_t)}{\tau}\right)^2.$$

# References

Cadigan, N.G. 2016. A state-space stock assessment model for northern cod, including under-reported catches and variable natural mortality rates. Canadian Journal of Fisheries and Aquatic Science 72:296-308.

Carruthers, T, Walters, C.J,, and McAllister, M.K. 2012. Evaluating methods that classify fisheries stock status using only fisheries catch data. Fisheries Research 119-120:66-79.

Fletcher, R. I. 1978. On the restructuring of the Pella-Tomlinson system. Fishery Bulletin 76:515:521.

Forrest, R.E., Martell, S.J.D., Melnychuk, M.C., and Walters, C.J. 2008. An age-structured model with leading management parameters, incorporating age-specific selectivity and maturity. Canadian Journal of Fisheries and Aquatic Science 65:286-296.

Hilborn, R., and Walters, C., 1992. Quantitative Fisheries Stock Assessment: Choice, Dynamics and Uncertainty. Chapman and Hall, New York.
