By fishR Blog

**fishR Blog**, and kindly contributed to R-bloggers)

A **fishR** user recently asked me

In the book that you published, I frequently use the stock-recruit curve code. The interface that shows both the Ricker/Beverton-Holt figure with the recruit per spawner to spawner figure (i.e., the dynamic plot for

`srStarts()`

) has not been working for quite some time. Additionally, I can get the recruits versus spawner plot for the Beverton-Holt or Ricker curve with confidence bounds around the curve, but how do you do the same for the recruit per spawner to spawner curve?

Below I answer both questions. First, however, I load required packages …

… and obtain the same data (in PSalmonAK.csv available from here) used in the Stock-Recruitment chapter of my **Introductory Fisheries Analyses with R** (IFAR) book. Note that I created two new variables here: `retperesc`

is the “recruits per spawner” and `logretperesc`

is the natural log of the recruits per spawner variable.

## Dynamic Plot Issue

The first question about the dynamic plot is due to a change in functionality in the **FSA** package since **IFAR** was published. The `dynamicPlot=`

argument was removed because the code for that argument relied on the **tcltk** package, which I found difficult to reliably support. A similar, though more manual, approach is accomplished with the new `fixed=`

and `plot=`

arguments. For example, using `plot=TRUE`

(without `fixed=`

) will produces a plot of “recruits” versus “stock” with the chosen stock-recruitment model evaluated at the automatically chosen parameter starting values superimposed.

The user, however, can show the stock-recruitment model evaluated at manually chosen parameter starting values by including those starting values in a list that is supplied to `fixed=`

. These values can be iteratively changed in subsequent calls to `srStarts()`

to manually find starting values that provide a model that reasonably fits (by eye) the stock-recruit data.

Note however that `srStarts()`

no longer supports the simultaneously plotting of spawners versus recruits and recruits per spawner versus recruits.

## Plot of Recruits per Spawner versus Spawners

The first way that I can imagine plotting recruits per spawners versus spawners with the fitted curve and confidence bands is to first follow the code for fitting the stock-recruit function to the stock and recruit data as described in **IFAR**. In this case, the stock-recruit function is fit on the log scale to adjust for a multiplicative error structure (as described in **IFAR**).

As described in the book, the plot of spawners versus recruits is made by (i) constructing a sequence of “x” values that span the range of observed numbers of spawners, (ii) predicting the number of recruits at each spawner value using the best-fit stock-recruitment model, (iii) constructing lower and upper confidence bounds for the predicted number of recruits at each spawner value with the bootstrap results, (iv) making a schematic plot on which to put (v) a polygon for the confidence band, (vi) the raw data points, and (vii) the best-fit curve. The code below follows these steps and reproduces Figure 12.4 in the book.

These results can be modified to plot recruits per spawner versus spawners by replacing the “recruits” in the code above with “recruits per spawner.” This is simple for the actual data as `ret`

is simply replaced with `retperesc`

. However, the predicted number of recruits (in `pR`

) and the confidence bounds (in `LCI`

and `UCI`

) from above must be divided by the number of spawners (in `x`

). As the `/`

symbol has a special meaning in R formulas, this division must be contained within `I()`

as when it appears in a formula (see the `lines()`

code below). Of course, the y-axis scale range must also be adjusted. Thus, a plot of recruits per spawner versus spawners is produced from the previous results with the following code.

Alternatively, the Ricker stock-recruitment model could be reparameterized by dividing each side of the function by “spawners” such that the right-hand-side becomes “recruits per spawner” (this is a fairly typical reparameterization of the model). This model can be put into an R function, with model parameters then estimated with nonlinear regression similar to above. The results below show that the paramter point estimates are identical and the bootsrapped confidence intervals are similar to what was obtained above.

With this, a second method for plotting recruits per spawner versus spawners is the same as how the main plot from the book was constructed but modified to use the results from this “new” model.

The two methods described above for plotting recruits per spawner versuse spawners are identical for the best-fit curve and nearly identical for the confidence bounds (slight differences likely due to the randomness inherent in bootstrapping). Thus, the two methods produce nearly the same visual.

**leave a comment**for the author, please follow the link and comment on their blog:

**fishR Blog**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more…

Source:: R News