library(knitr) opts_chunk$set(echo=TRUE, warning=FALSE, message=FALSE, width=80) # , autodep=TRUE, cache=TRUE, cache.lazy=FALSE)
The R package GLFC includes functions to estimate indices of adult sea lamprey abundance in the Great Lakes. The Great Lakes Fishery Commission made the decision to switch to a lake-wide index of adult abundance in December 2014 (GLFC-TTF 2014). Prior to that decision, lake-wide population estimates (PE) were generated following Mullett et al. (2003). This vignette walks you through the process of generating Adult Index estimates.
One overarching function, AIpresto
can be used to carry out all the steps of the Adult Index estimation process in one fell swoop. This function prepares and error checks the data, estimates the Adult Index, calculates the targets, and generates a draft report.
Install the latest version of R from CRAN.
Install the latest version of the GLFC package:
install.packages("remotes") remotes::install_github("JVAdams/GLFC")
Dir <- "C:\\JVA\\Lamprey\\Adults\\AdultIndex\\2015" StreamNew <- "AdultStream2015.csv" StreamPrev <- "AdultStreamThru2014.csv" LakePrev <- "AdultLakeThru2014.csv"
Three csv files are needed to generate Adult Index estimates, one each with new stream data, previous stream data, and previous lake data.
(1) STREAMDATANEW
should contain stream mark-recapture estimates of adult sea lampreys for the year of interest.
new <- read.csv(paste(Dir, StreamNew, sep="\\"), as.is=TRUE) new2 <- new[7:11, c("year", "lake", "lscode", "trapcatch", "PEmr", "CVmr", "comments")] new2[1, "comments"] <- "no recaps" knitr::kable(new2, row.names=FALSE)
The first row of STREAMDATANEW
should be a header row with the following column names:
year
- survey yearlake
- lake code (1=Superior, 2=Michigan, 3=Huron, 4=Erie, and 5=Ontario)lscode
- lake-stream code, a combination of lake and stream codes e.g., lscode = 1.064 = lake code + (stream code)/1000trapcatch
= no. of adult sea lampreys capturedPEmr
= stream population estimate of adult sea lampreys from mark-recapture studyCVmr
= coefficient of variation of PEmrcomments
= commentswhere $$ CV_{mr} = 100\% \frac{\sqrt{Var(PE_{mr})}}{PE_{mr}} $$
(2) STREAMDATAPREV
should contain stream mark-recapture estimates of adult sea lampreys for all of the years prior to the year of interest.
old <- read.csv(paste(Dir, StreamPrev, sep="\\"), as.is=TRUE) old2 <- old[c(896:897, 955:957), c("year", "lake", "lscode", "PEmr", "CVmr", "indexContrib", "indexContribCV")] old2$PEmr <- round(old2$PEmr, 0) old2$CVmr <- round(old2$CVmr, 0) old2$indexContrib <- round(old2$indexContrib, 0) old2$indexContribCV<- round(old2$indexContribCV, 0) knitr::kable(old2, row.names=FALSE)
The first row of STREAMDATAPREV
should be a header row with the following column names:
year
- survey yearlake
- lake codelscode
- lake-stream code, a combination of lake and stream codes PEmr
= stream population estimate of adult sea lampreys from mark-recapture studyCVmr
= coefficient of variationindexContrib
= the stream population estimate used in the Adult IndexindexContribCV
= the stream CV used in the 95% confidence interval(3) LAKEDATAPREV
should contain annual lake-wide adult sea lamprey indices for all of the years prior to the year of interest.
lakeprev <- read.csv(paste(Dir, LakePrev, sep="\\"), as.is=TRUE, header=TRUE) lakeprev <- lakeprev[, c("year", "lake", "index", "ilo", "ihi")] lake2 <- lakeprev[119:123, ] lake2$index <- round(lake2$index, 0) lake2$ilo <- round(lake2$ilo, 0) lake2$ihi <- round(lake2$ihi, 0) knitr::kable(lake2, row.names=FALSE)
The first row of LAKEDATAPREV
should be a header row with the following column names:
year
- survey yearlake
- lake codeindex
- estimated lake-wide index of adult sea lamprey abundanceilo
- lower 95% confidence intervalihi
- upper 95% confidence intervalFor all 3 files,
year
, lake
, or lscode
All 3 files should all be stored in a single directory, DIRECTORY
.
Assign the name of the directory (use double backslashes, \\, in the file path) and the names of the three files. For example,
Dir <- "C:\\temp" StreamNew <- "AdultStream2015.csv" StreamPrev <- "AdultStreamThru2014.csv" LakePrev <- "AdultLakeThru2014.csv"
Load the GLFC package to have access to the Adult Index functions.
library(GLFC)
Use the AIpresto()
function to prepare and error check the data, estimate the Adult Index, calculate the targets, and generate a draft report. Simply provide the function with the name of the directory where the files are stored, the names of the new and previous stream data, and the name of the previous lake data.
AIpresto(DIRECTORY=Dir, NEWDATARAW=StreamNew, STREAMDATAPREV=StreamPrev, LAKEDATAPREV=LakePrev)
Within the AIpresto()
function, the following steps are carried out.
The AIprep()
function is used to read in the adult sea lamprey stream trapping data and prepare them for error checking and estimation.
streamall <- AIprep(csvDir=Dir, csvNew=StreamNew, csvOld=StreamPrev)
The AIprep()
function brings in additional information built in to the GLFC package by default, including
trappedStreams
a data frame with stream information,knitr::kable(head(trappedStreams, 5), row.names=FALSE)
lsIndex
a list of lake-stream codes identifying index streams, look <- sapply(lsIndex, function(x) paste(x, collapse=", ")) look <- cbind(lake=Lakenames, index.streams=look) knitr::kable(look, row.names=FALSE)
lsKeep
a list of lake-stream codes identifying streams which will continue to have ongoing trapping even if not part of the Adult Index.m <- sapply(lsKeep, function(x) paste(x, collapse=", ")) m2 <- paste(m[m!=""], collapse=", ") look <- data.frame(lake="All", maintenance.streams=m2) knitr::kable(look, row.names=FALSE)
The returned object from the AIprep()
function is a single data frame (called streamall
in this example) with information from all of the inputs, including new variables:
index
- a logical (TRUE/FALSE) identifying the index streamsmaintain
- a logical identifying the streams that will continue to have ongoing trapping even if not part of the Adult IndexindexContrib
- the stream population estimate that will be used in the Adult Index (initially set to missing for csvNew
)indexContribCV
- the stream CV that will be used in the 95% confidence interval (initially set to missing for csvNew
)complete
- a logical identifying streams and years for which the Adult Index has already been estimated (initially set to FALSE for csvNew
)sel <- !is.na(streamall$indexContrib) look <- tail(streamall[sel, ], 5) look$PEmr <- round(look$PEmr, 0) look$CVmr <- round(look$CVmr, 0) look$indexContrib <- round(look$indexContrib, 0) look$indexContribCV<- round(look$indexContribCV, 0) knitr::kable(look, row.names=FALSE)
The AIcheck()
function is used to check the data for errors and generate a report of tables and figures.
AIcheck(streamDat=streamall, csvDir=Dir)
message( "New RTF document created, C:\\temp/2015 Adult Index - error checking.doc")
The generated report is an rtf (rich text format) file but it has a *.doc extension so that it will be automatically opened by Microsoft Word. The report is named YYYY Adult Index - error checking.doc
, where YYYY is the latest year represented in streamDat
, and placed in the directory csvDir
. In this example, the path to the error checking report is C:\temp\2015 Adult Index - error checking.doc
.
The following conditions are highlighted as potential errors in the data:
The error checking report also includes two multi-panel (one panel per stream) time series plots:
adult sea lamprey trap efficiency estimates (trap catch / mark-recapture PE)
adult sea lamprey mark-recapture estimates
The AIestimate()
function is used to estimate the Adult Index of sea lampreys in a single Great Lake. For example, for Lake Ontario,
ainewOnt <- AIestimate(streamDat=streamall[streamall$lake==5, ])
The annual Adult Index is simply the sum of stream population estimates for each year. Missing stream estimates are estimated by a lake-specific ANOVA model relating the log of the stream estimates to the main effects of each stream and each year, weighted by the inverse of the CV squared.
The 95% confidence interval is estimated from the sum of the mark-recapture variances of the streams.
The returned object from the function (ainewOnt
in this example) is a list with 2 components:
streamPE
- a data frame of stream mark-recapture and Adult Index contributions for the incomplete rows in streamDat
, with the same variables as streamDat
ss <- ainewOnt$streamPE ssc <- strsplit(ss$comments, ",") ssc2 <- sapply(ssc, "[", 1) ss$comments <- gsub("recapture", "recap", ssc2) ss$indexContrib <- round(ss$indexContrib, 0) ss$indexContribCV <- round(ss$indexContribCV, 0) knitr::kable(ss, row.names=FALSE)
lakeIndex
- a data frame of annual lake-wide Adult Indices with 5 columns: lake
, year
, index
, and the 95% confidence intervals ilo
and ihi
knitr::kable(ainewOnt$lakeIndex, row.names=FALSE)
The index estimates for the lakes, lakeainew
, looks like this:
ainew <- lapply(1:5, function(L) AIestimate(streamall[streamall$lake==L, ])) streamainew <- do.call(rbind, lapply(ainew, "[[", 1)) lakeainew <- do.call(rbind, lapply(ainew, "[[", 2)) knitr::kable(tail(lakeainew), row.names=FALSE)
The AItarget()
function is used to calculate lake-wide targets for the Adult Index of sea lamprey populations in the Great Lakes from the mean of specified years. The AItarget()
function takes three arguments, but only the first one needs to be provided.
targ <- AItarget(lakeIndex=lakeprev)
lakeIndex
- a data frame of annual lake-wide Adult Indices with (at least these) 3 columns: lake
, year
, and index
years
- A list of 5 vectors (one for each Great Lake), specifying the 5 years during which there were acceptable sea lamprey wounding rates on lake troutadjust
- A vector of 5 adjustments (one for each Great Lake) to be made to the mean indices when calculating the target (this is needed if the wounding rates were not acceptable during the specified years)Default values are provided for years
and adjust
based on the decisions made by the Great Lakes Fishery Commission. Currently, these values are
a <- as.character(formals(AItarget)$years)[-1] b <- eval(formals(AItarget)$adjust) ab <- data.frame(lake=Lakenames, years=gsub(":", "-", a), adjust=b) knitr::kable(ab, row.names=FALSE)
The returned object from the AItarget()
function (called targ
in this example) is a data frame with the calculated targets for the Adult Index and expanded PE of each Great Lake.
look <- targ look$targInd <- round(look$targInd) knitr::kable(look, row.names=FALSE)
Lake-specific conversion factors built in to the GLFC package, index2pe
, are used to scale up indices of adult sea lamprey abundance in the Great Lakes to lake-wide population estimates.
m <- as.matrix(index2pe) row.names(m) <- Lakenames colnames(m) <- "index2pe" knitr::kable(m)
lakeall <- plyr::rbind.fill(lakeprev, lakeainew) lakeallpe <- merge( lakeall[, c("lake", "year", "index", "ilo", "ihi")], cbind(lake=1:5, i2pe=index2pe)) lakeallpe$pe <- with(lakeallpe, index*i2pe) lakeallpe$pelo <- with(lakeallpe, ilo*i2pe) lakeallpe$pehi <- with(lakeallpe, ihi*i2pe) knitr::kable(tail(lakeallpe, 5), row.names=FALSE)
The AIreport()
function is used to create a draft template-style report of the Adult Index estimates of sea lamprey in the Great Lakes.
streamaiall <- rbind(streamall[streamall$complete==TRUE, ], streamainew) AIreport(streamPEs=streamaiall, lakeIPEs=lakeallpe, targets=targ, csvDir=Dir)
message( "New RTF document created, C:\\temp/2015 Adult Index - draft report.doc")
As with the error checking report, the document generated by AIreport()
is an rtf file with a *.doc extension, named YYYY Adult Index - draft report.doc
.
The report has few paragraphs summarizing the latest estimates, along with 3 tables,
and 3 figures,
5-panel time series plot of adult sea lamprey indices (with 95% confidence intervals) and targets for each Great Lake
5-panel bar plot of adult sea lamprey abundance estimates for index streams
map showing the index streams in the Great Lakes and the relative size of the most recent population estimates
GLFC Sea Lamprey Control Board. 2016. 15-02 Meeting Action Item and Recommendation Summary. in Sea Lamprey Control Board Meeting 16-01, 12-14 Apr 2016, Briefing Item 1 - Attachment 2.
GLFC Trapping Task Force. 2014. Transitioning to the New Adult Index in 2015. in Sea Lamprey Control Board Meeting 14-02, 15-17 Oct 2014, Briefing Item 5 - Attachment 2.
Mullett, K. M., Heinrich, J. W., Adams, J. V., Young, R. J., Henson, M. P., McDonald, R. B., and Fodale, M. F. 2003. Estimating lake-wide abundance of spawning-phase sea lampreys (Petromyzon marinus) in the Great Lakes: extrapolating from sampled streams using regression models. Journal of Great Lakes Research, 29(Supplement 1), 240–252.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.