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

Install the latest version of R from CRAN.

Install the latest version of the GLFC package:

install.packages("remotes")
remotes::install_github("JVAdams/GLFC")

Prepare the data

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:

where $$ 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:

(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:

For all 3 files,

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"

Run the works

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)

Behind the scenes

Within the AIpresto() function, the following steps are carried out.

Manipulate the data

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

knitr::kable(head(trappedStreams, 5), row.names=FALSE)
look <- sapply(lsIndex, function(x) paste(x, collapse=", "))
look <- cbind(lake=Lakenames, index.streams=look)
knitr::kable(look, row.names=FALSE)
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:

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)

Error checking the data

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:

Estimating the Adult Index

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:

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)
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)

Determining the targets

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)

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)

Scaling up indices to PEs

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)

Generating a draft report

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,

References



JVAdams/GLFC documentation built on Jan. 5, 2023, 12:59 a.m.