---
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:
    toc: true
    toc_float: true
---

## Implementation Parameters
```{r, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(dplyr)
Pars <- params$Pars
nsim <- Pars$TAESD %>% length()

# ImpList <- list()
# ImpList$TACbias <- array(Pars$Imp$TACFrac, c(nsim, nyears + proyears))  
# ImpList$TACsd <- array(rlnorm((nyears + proyears) * nsim, 
#                      mconv(1, rep(Pars$Imp$TACSD, (nyears + proyears))), 
#                      sdconv(1, rep(Pars$Imp$TACSD, nyears + proyears))), 
#               c(nsim, nyears + proyears))  
# 
# ImpList$TAEbias <- array(Pars$Imp$TAEFrac, c(nsim, nyears + proyears))  
# ImpList$TAEsd <- array(rlnorm((nyears + proyears) * nsim, 
#                      mconv(1, rep(Pars$Imp$TAESD, (nyears + proyears))), 
#                      sdconv(1, rep(Pars$Imp$TAESD, nyears + proyears))), 
#               c(nsim, nyears + proyears)) 
# 
# ImpList$SizeLimFrac <- array(Pars$Imp$SizeLimFrac, c(nsim, nyears + proyears))  
# ImpList$SizeLimSD <- array(rlnorm((nyears + proyears) * nsim, 
#                      mconv(1, rep(Pars$Imp$SizeLimSD, (nyears + proyears))), 
#                      sdconv(1, rep(Pars$Imp$SizeLimSD, nyears + proyears))), 
#               c(nsim, nyears + proyears)) 
```



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


#### Sampled Parameters
Histograms of `r nsim` simulations of inter-annual variability in TAC implementation error (`TACSD`) and persistent bias in TAC implementation (`TACFrac`), with vertical colored lines indicating `r nsamp` randomly drawn values used in other plots:

```{r, echo=FALSE}
par(mfrow=c(1,2))
hist2(Pars$Imp$TACSD, main="TACSD", col=params$plotPars$col, axes=params$plotPars$axes,
      breaks=params$plotPars$breaks, cex.main=params$plotPars$cex.main)
abline(v=Pars$Imp$TACSD[params$its], col=1:nsamp, lwd=params$plotPars$lwd)
axis(side=1) 

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

```

#### Time-Series
Time-series plots of `r nsim` samples of TAC implementation error by year:

```{r, echo=FALSE}

par(mfrow=c(1,1), oma=c(3,3,1,1), mar=c(1,1,1,1))
years <- seq(nyears+1, to=nyears+proyears,1)

ylim <- c(0, max(Pars$Imp$TAC_y[params$its, ]))
matplot(years, t(Pars$Imp$TAC_y[params$its, ]),
        type="l", lty=1, bty="l", main="TAC discrepancy by Year", 
        lwd=params$plotPars$lwd, ylab="Observed/Real", xlab="Years", las=1, xpd=NA,
        ylim=ylim)
abline(v=0, col="darkgray", lty=2)
abline(h=1, col="darkgray", lty=2)
```



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


#### Sampled Parameters
Histograms of `r nsim` simulations of inter-annual variability in TAE implementation error (`TAESD`) and persistent bias in TAC implementation (`TAEFrac`), with vertical colored lines indicating `r nsamp` randomly drawn values used in other plots:

```{r, echo=FALSE}
par(mfrow=c(1,2))
hist2(Pars$Imp$TAESD, main="TAESD", col=params$plotPars$col, axes=params$plotPars$axes,
      breaks=params$plotPars$breaks, cex.main=params$plotPars$cex.main)
abline(v=Pars$Imp$TAESD[params$its], col=1:nsamp, lwd=params$plotPars$lwd)
axis(side=1) 

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

```

#### Time-Series
Time-series plots of `r nsim` samples of TAE implementation error by year:

```{r, echo=FALSE}
par(mfrow=c(1,1), oma=c(3,3,1,1), mar=c(1,1,1,1))
years <- seq(nyears+1, to=nyears+proyears,1)

ylim <- c(0, max(Pars$Imp$E_y[params$its, ]))
matplot(years, t(Pars$Imp$E_y[params$its, ]),
        type="l", lty=1, bty="l", main="TAE discrepancy by Year", 
        lwd=params$plotPars$lwd, ylab="Observed/Real", xlab="Years", las=1, xpd=NA,
        ylim=ylim)
abline(v=0, col="darkgray", lty=2)
abline(h=1, col="darkgray", lty=2)
```


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


#### Sampled Parameters
Histograms of `r nsim` simulations of inter-annual variability in size limit implementation error (`SizeLimSD`) and persistent bias in size limit implementation (`SizeLimFrac`), with vertical colored lines indicating `r nsamp` randomly drawn values used in other plots:

```{r, echo=FALSE}
par(mfrow=c(1,2))
hist2(Pars$Imp$SizeLimSD, main="SizeLimSD", col=params$plotPars$col, axes=params$plotPars$axes,
      breaks=params$plotPars$breaks, cex.main=params$plotPars$cex.main)
abline(v=Pars$Imp$SizeLimSD[params$its], col=1:nsamp, lwd=params$plotPars$lwd)
axis(side=1) 

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

```

#### Time-Series
Time-series plots of `r nsim` samples of Size Limit implementation error by year:

```{r, echo=FALSE}

par(mfrow=c(1,1), oma=c(3,3,1,1), mar=c(1,1,1,1))
years <- seq(nyears+1, to=nyears+proyears,1)

ylim <- c(0, max(Pars$Imp$SizeLim_y[params$its, ]))
matplot(years, t(Pars$Imp$SizeLim_y[params$its, ]),
        type="l", lty=1, bty="l", main="Size Limit discrepancy by Year", 
        lwd=params$plotPars$lwd, ylab="Observed/Real", xlab="Years", las=1, xpd=NA,
        ylim=ylim)
abline(v=0, col="darkgray", lty=2)
abline(h=1, col="darkgray", lty=2)
```

