---
params: 
    title: ""
    Pars: "`r list()`"
    plotPars: "`r list()`"
    tabs: "`r TRUE`"
    its: " `r numeric()`"
    nyears: " `r numeric()`"
    proyears: " `r numeric()`"
    date: "`r Sys.Date()`"
title: "`r params$title`"
date: "`r params$date`"
output:
  html_document
---


```{r catchability, echo=FALSE, results="asis"}
if (params$tabs) {
  cat('### Future Catchability {.tabset .tabset-fade .tabset-pills}' )
} else {
  cat('### Future Catchability')
}

dd <- params$Pars$M_ageArray %>% dim()
nsim <- dd[1]
maxage <- dd[2]

nsamp <- length(params$its)
```

#### Sampled Parameters
Histograms of `r nsim` simulations of inter-annual variability in fishing efficiency (`qcv`) and average annual change in fishing efficiency (`qinc`), with vertical colored lines indicating `r nsamp` randomly drawn values used in the time-series plot:

```{r q_parameters, echo=FALSE}
par(mfrow=c(1,2))

hist2(Pars$qcv, col=params$plotPars$col, axes=params$plotPars$axes, main="qcv", breaks=params$plotPars$breaks)
abline(v=Pars$qcv[params$its], col=1:nsamp, lwd=params$plotPars$lwd)
axis(side=1) 

hist2(Pars$qinc, col=params$plotPars$col, axes=params$plotPars$axes, main="qinc", breaks=params$plotPars$breaks)
abline(v=Pars$qinc[params$its], col=1:nsamp, lwd=params$plotPars$lwd)
axis(side=1)

```


#### Time-Series
Time-series plot showing `r nsamp` trends in future fishing efficiency (catchability):
```{r q_time-series, echo=FALSE}
par(mfrow=c(1,1))

ind <- as.matrix(expand.grid(params$its, 1:proyears, 1:nsamp))
Qfuture <- matrix(NA, nrow=proyears, ncol=nsamp)
X <- 0 
for (sim in params$its) {
   X <- X + 1 
  Qfuture[,X] <- Pars$qvar[sim,] * (1 + Pars$qinc[sim]/100)^(1:proyears)
  Qfuture[,X] <- Qfuture[,X]/Qfuture[1,X]
}

CurrentYr <- Pars$CurrentYr
futYr <- (CurrentYr+1):(CurrentYr+proyears)

ylim <- range(Qfuture) %>% abs() %>% max()

matplot(futYr, Qfuture,  type="l", lwd=params$plotPars$lwd, bty="l", lty=1,
        ylab="Change in Efficiency (%)", xlab="Year", ylim=c(-ylim, ylim))
abline(h=1, lty=2, col="lightgray")
```
