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 larval sea lamprey abundance in the St. Marys River using the Deep-Water ElectroFisher Estimation System (DWEFES).

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

directory   <- "C:/temp"
catch.file.name <- "2019_Base_Data.xlsx"
length.file.name <- c("2019_LENGTHS_4.xlsx", "2019_LENGTHS_7.xlsx")
plots.file.name <- "2019_Treat_Plots.xlsx"

Three *.xlsx files with data on larval sea lamprey catches, lengths, and plot treatments in the most recent year are needed to generate larval sea lamprey estimates.

(1) Catch - An * *.xl* * file with the catch data. The catch file should have at least the following 19 columns, named in the header row:

The last three columns are typically added after sampling, in ArcGIS Pro. Missing values are entered as -9999.

fin <- readxl::read_excel(paste(directory, catch.file.name, sep="/"), sheet=1)
knitr::kable(fin[8:12, ], row.names=FALSE)

(2) Lengths - One or more *.xl* files with lengths data. The files should have at least the following 2 columns named in the header row:

len <- readxl::read_excel(paste(directory, length.file.name[1], sep="/"), sheet=1)
knitr::kable(head(len), row.names=FALSE)

(3) Plots - An *.xl* file with information on each plot. The files should have at least the following 3 columns, named in the header row:

plotinfo <- readxl::read_excel(paste(directory, plots.file.name, sep="/"), sheet=1)
knitr::kable(head(plotinfo), row.names=FALSE)

For all 3 files,

All 3 files should be stored in a single directory, directory.

Historic data

catch.all <- "2018-CatchALL.csv"
length.all <- "2018-LengthALL.csv"
plot.all <- "2018-BPlotEstsALL.csv"
whole.river.pe <- "2018-WholeRiverEsts.csv"

Four *.csv files with data on historic catches, lengths, plot treatments, and population estimates will be updated with new information.

(1) Catch - A *.csv file with historic catch data. The required fields are the same as for the catch *.xlsx file, with the following exceptions:

(2) Lengths - A *.csv file with historic lengths data. The required fields are the same as for the lengths *.xlsx file, with the following exceptions:

(3) Plots - A *.csv file with historic plot-specific abundance estimates with the following 15 columns, named in the header row:

(4) PEs - A *.csv file with historic population estimates with the following 14 columns, named in the header row:

All 4 files should be stored in the same directory as the other files, directory.

Read in the data

Load the GLFC package to have access to the DWEFES functions.

library(GLFC)

Assign the name of the directory (using forward slashes, /, in the file path) and the names of the three new and four historic data files. For example:

directory   <- "C:/temp"
catch.file.name <- "2019_Base_Data.xlsx"
length.file.name <- c("2019_LENGTHS_4.xlsx", "2019_LENGTHS_7.xlsx")
plots.file.name <- "2019_Treat_Plots.xlsx"
catch.all <- "2018-CatchALL.csv"
length.all <- "2018-LengthALL.csv"
plot.all <- "2018-BPlotEstsALL.csv"
whole.river.pe <- "2018-WholeRiverEsts.csv"

Use the DWEFprep() function to read in the deep-water electrofishing data (including information on the lamprey catch, the lamprey lengths, and the identification of plots that were treated) and prepare them for estimation. In addition to providing the directory and file names as arguments to this function, you also need to provide information on treatment and survey timing.

Argument TRTtiming is a character scalar identifying the timing of the assessment survey relative to treatment. It should take on one of four values:

Argument b4plots is a numeric vector identifying the plots that were surveyed before they were treated. This is rarely needed (default NULL). A value for this should only be provided if TRTtiming is set to "MIXED". For example, if there were three plots surveyed before treatment, b4plots = c(18, 39, 112).

The output from the DWEFprep() function is a list with recent catch, length, and plot data in three data frames (CAT, LEN, PLT), historic catch, length, plot, and population estimate data in four data frames (CAThist, LENhist, Plothist, PEhist), and a character vector of the directory and file names (SOURCE). The recent plot data is reorganized to have only one row per plot, with the treated variable indicating the number of treatments each plot received that year.

mydat <- DWEFprep(Dir=directory, CatchFile=catch.file.name,
  LengthsFile=length.file.name, PlotsFile=plots.file.name,
  TRTtiming="AFTER", CatchHist=catch.all, LengthHist=length.all,
  PlotHist=plot.all, PEHist=whole.river.pe, b4plots=NULL)
lapply(mydat, head, 2)

Error check the data

Use the DWEFerror() function to error check the deep-water electrofishing data (including information on the lamprey catch, the lamprey lengths, and the identification of plots that were treated) prior to estimation.

In addition to providing output from the DWEFprep() function as arguments to this function, you also need to indicate whether you want to create a stand alone error report (Continue=FALSE) or if you want to start a report that will left open for the estimates to be added in the next step (Continue=TRUE).

The output from the DWEFerror() function is a list with cleaned (errors removed) DWEF catch and lengths in two data frames (CAT2, LEN2), a character vector of the table references for any remaining errors (ERR), a character vector of the directory and file names (SOURCE), and a character vector of the output file names (OUT).

If Continue=FALSE, a rich text file will be saved to directory with error checking text, tables, and figures. If Continue=TRUE, the same rich text file will be started, but left open, typically to add in more text, tables, and figures generated by the DWEFreport() function.

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 DWEFES Report dd-Mon-YYYY.doc, where YYYY is the latest year represented in the input data, and placed in directory.

The following conditions and graphs are used to highlight potential errors in the data:

myclean <- DWEFerror(Dir=mydat$SOURCE["Dir"], Catch=mydat$CAT,
  Lengths=mydat$LEN, Source=mydat$SOURCE, Continue=TRUE)
lapply(myclean, head, 2)

Estimate larval abundance

Use the DWEFreport() function to generate estimates of larval sea lamprey abundance from the deep-water electrofishing data.

In addition to providing output from the DWEFprep() and DWEFerror() functions as arguments to this function, you also need to (1) indicate whether the downstream portion of the St. Marys River was surveyed (Downstream=TRUE) or if only the upstream portion of the river was surveyed (Downstream=FALSE) and (2) provide a data frame of stratum areas, StratArea, with three variables:

SMRStratArea

It is assumed that this function will be run immediately after the DWEFerror() function, in which case the *.rtf file created by DWEFerror() will be continued and completed by DWEFreport().

The report has a few paragraphs summarizing the latest estimates, along with 3 tables:

and 3 figures:

In addition pre- and post-treatment whole-river estimates are printed to the screen (along with any relevant messages regarding the estimation process). And three *.csv files are written to directory, with the final catch (YYYYCatchesSMR.csv), lengths (YYYYLengthsSMR.csv), and plot data (YYYYBPlotEstsSMR.csv).

DWEFreport(Dir=mydat$SOURCE["Dir"], CatchClean=myclean$CAT2,
  LengthsClean=myclean$LEN2, Plots=mydat$PLT, CatHist=mydat$CAThist,
  LenHist=mydat$LENhist, PlotHist=mydat$Plothist, PEHist=mydat$PEhist,
  Downstream=FALSE, Errors=myclean$ERR, Outfiles=myclean$OUT, 
  StratArea=SMRStratArea)

Summary

Below is the pared down version of the R code above needed to estimate larval sea lamprey abundance in the St. Marys River.

library(GLFC)

# read in the new data
directory   <- "C:/temp"
catch.file.name <- "2019_Base_Data.xlsx"
length.file.name <- c("2019_LENGTHS_4.xlsx", "2019_LENGTHS_7.xlsx")
plots.file.name <- "2019_Treat_Plots.xlsx"

# read in the historic data
catch.all <- "2018-CatchALL.csv"
length.all <- "2018-LengthALL.csv"
plot.all <- "2018-BPlotEstsALL.csv"
whole.river.pe <- "2018-WholeRiverEsts.csv"

mydat <- DWEFprep(Dir=directory, CatchFile=catch.file.name,
  LengthsFile=length.file.name, PlotsFile=plots.file.name,
  CatchHist=catch.all, LengthHist=length.all,
  PlotHist=plot.all, PEHist=whole.river.pe)

# error check the data
myclean <- DWEFerror(Dir=mydat$SOURCE["Dir"], Catch=mydat$CAT,
  Lengths=mydat$LEN, Source=mydat$SOURCE, Continue=TRUE)

# estimate larval abundance
DWEFreport(Dir=mydat$SOURCE["Dir"], CatchClean=myclean$CAT2,
  LengthsClean=myclean$LEN2, Plots=mydat$PLT, CatHist=mydat$CAThist,
  LenHist=mydat$LENhist, PlotHist=mydat$Plothist, PEHist=mydat$PEhist,
  Downstream=FALSE, Errors=myclean$ERR, Outfiles=myclean$OUT)


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