# R package “fishdynr”

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**me nugget**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The

*fishdynr*package allows for the construction of some basic population dynamics models commonly used in fisheries science. Included are models of a single cohort, cohortSim, and a more complex iterative model that incorporates a stock-recruitment relationship, stockSim. The model functions require a list of parameters as the main argument, which contains information about the given population’s dynamics (growth, mortality, recruitment, etc.) and fishery (e.g. selectivity function and related parameters). This allows for a great deal of flexibility in adapting the analyses to particular species or fishery by defining functions of growth, mortality, fishing selectivity, recruitment, etc., outside the analysis. The package (located on GitHub) can be easily installed via the install_github function of the devtools package:

library(devtools)

install_github(“fishdynr”, “marchtaylor”)

The above figure shows the output of the Beverton and Holt’s (1957) yield-per-recruit model (ypr function – wrapper for cohortSim), based on variable fishing mortality (

*F*) and length at first capture (

*Lcap*, knife-edge selection). Length at maturity is shown as a dashed white line for reference. In this example, the maximum yield (

*Ymax*) is defined as the maximum possible yield without depletion of the spawning biomass below 50% of it’s virgin, unfished biomass. This simple cohort model has many additional outputs that can be helpful in visualizing processes of growth and mortality:

I hope to continue to document different models used in fisheries science within the package. Any suggestions or comments are welcome.

**References**

Beverton, R. J. H.; Holt, S. J. (1957), On the Dynamics of Exploited Fish Populations, Fishery Investigations Series II Volume XIX, Ministry of Agriculture, Fisheries and Food

**Script to reproduce the examples**

#library(devtools) #install_github("fishdynr", "marchtaylor") library(fishdynr) # Single cohort simulation data(tilapia) tilapia$N0 <- 1000 res <- cohortSim(tilapia, t_incr=0.1) png("fishdynr_cohortSim.png", width=8, height=5, units="in", res=400, type="cairo") op <- par(mfcol=c(2,3), mar=c(4,4,1,1), ps=10) plot(Lt ~ t, res, t="l") plot(Wt ~ t, res, t="l") plot(pmat ~ t, res, t="l") plot(pcap ~ t, res, t="l") plot(Nt ~ t, res, t="l", log="y") lines(Nt.noF ~ t, res, col=1, lty=2) legend("topright", legend=c("Nt", "Nt; F=0"), col=1, lty=1:2) plot(Bt ~ t, res, t="l") lines(SBt ~ t, res, col=1, lty=2) legend("topright", legend=c("Bt", "SBt"), col=1, lty=1:2) par(op) dev.off() # Yield per recruit model tilapia$N0 <- 1 n <- 30 adj.params <- list(F=seq(0,3,,n), knife_edge_size=seq(0,tilapia$Linf,,n)) res <- ypr(params=tilapia, adj.params) SB_F0 <- res$SB[which(res$F==0),1] res$relSB <- res$SB/SB_F0 Ymax <- which.max(res$Y*(res$relSB > 0.5)) pal <- colorRampPalette(c( rgb(1,0.5,0.5), rgb(1,1,0.5), rgb(0.5,1,1), rgb(0.5,0.5,1) )) png("fishdynr_ypr.png", width=8, height=4, units="in", res=400, type="cairo") op <- par(mfcol=c(1,2), mar=c(3,3,2,1), oma=c(1,1,0,0), ps=10) # Yield image(x=res$F, y=res$knife_edge, z=res$Y, col=pal(100), xlab="", ylab="" ) contour(x=res$F, y=res$knife_edge, z=res$Y, add=TRUE) abline(h=tilapia$Lmat, col="white", lty=2) points(res$adj.params.comb[Ymax,], lwd=2, col="white") text(res$adj.params.comb[Ymax,], labels="Ymax", col="white", cex=1.2, pos=2, font=2) mtext("Yield-Per-Recruit", side=3, line=0.5, cex=1.2, font=2) # Relative spawning biomass image(x=res$F, y=res$knife_edge, z=res$SB/SB_F0, col=pal(100), xlab="", ylab="" ) contour(x=res$F, y=res$knife_edge, z=res$SB/SB_F0, add=TRUE) abline(h=tilapia$Lmat, col="white", lty=2) points(res$adj.params.comb[Ymax,], lwd=2, col="white") text(res$adj.params.comb[Ymax,], labels="Ymax", col="white", cex=1.2, pos=2, font=2) mtext("Rel. Spawning Biomass", line=0.5, side=3, cex=1.2, font=2) mtext("Fishing mortality [F]", side=1, line=0, outer=TRUE) mtext("Length at capture [Lcap]", side=2, line=0, outer=TRUE) par(op) dev.off()

To

**leave a comment**for the author, please follow the link and comment on their blog:**me nugget**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.