---
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, echo=FALSE, results="asis"}
if (params$tabs) {
  cat('### Recruitment Parameters {.tabset .tabset-fade .tabset-pills}' )
} else {
  cat('### Recruitment Parameters')
}

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

nsamp <- length(params$its)

if (Pars$SRrel[1] == 1) SR <- "Beverton-Holt"
if (Pars$SRrel[1] == 2) SR <- "Ricker"

```

#### Sampled Parameters 
Histograms of `r nsim` simulations of steepness (`h`), recruitment process error (`Perr`) and auto-correlation (`AC`) for the `r SR` stock-recruitment relationship, with vertical colored lines indicating `r nsamp` randomly drawn values used in other plots:

```{r, echo=FALSE}
par(mfrow=c(1,3))
hist2(Pars$hs, col=params$plotPars$col, axes=params$plotPars$axes, main="Steepness (h)", breaks=params$plotPars$breaks)
abline(v=Pars$hs[params$its], col=1:nsamp, lwd=params$plotPars$lwd)
axis(side=1)  

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

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

```

#### Time-Series

```{r, echo=FALSE}
years <- c(seq(-nyears+1, 0, by=1), seq(1, proyears,1))

matplot(years, t(Pars$Perr_y[params$its,(maxage):(maxage+length(years)-1)]), type="l", bty="l", main="Rec Devs by Year", 
        lwd=params$plotPars$lwd, lty=1, ylab="Rec Devs", xlab="Years")
abline(h=1, col="lightgray", lty=2)
abline(v=0, col="lightgray", lty=2)
```

