This demo gives more information on how to format the data, and how to use the data checking beta code.
library(tidyverse) library(BycatchEstimator) library(MuMIn) library(flextable)
Read in some fake observer data to see data formatting
obsdatlong<-read.csv("observerDataLong.csv") obsdatlong %>% flextable()%>% colformat_num(j="Year",big.mark="")
This data is in "long" format, meaning that there are multiple lines per set to report the catch of each species. If sets are the sample unit, we need to have one line per set. The following code converts form "long" to "wide", requiring the tidyverse library.
obsdatwide<-pivot_wider(obsdatlong,names_from=Species,values_from=Number,values_fill=0) write_csv(obsdatwide,"observerDataWide.csv") obsdatwide %>% flextable()%>% colformat_num(j="Year",big.mark="")
We now have one row per set, and columns with catch of BUM, SWO and SMA, with zeros filled in for sets where they were not caught. This is the right format if we want sets as the sample unit. If we want trips as the sample unit, we can aggregate the data to trips.
obsdattrip<-obsdatlong %>% group_by(TripID) %>% summarize(Year=min(Year), sets=length(unique(Set)), hooks=sum(Hooks), BUM=sum(Number[Species=="BUM"])) obsdattrip %>% flextable() %>% colformat_num(j="Year",big.mark="")
The following code runs the dataCheck function in the bycatchEstimator tool.
Step 1, run the setupObj function.
setupObj<-bycatchSetup( modelTry = c("TMBnbinom1","TMBtweedie"), obsdat = droplevels(LLSIM_BUM_Example_observer[LLSIM_BUM_Example_observer$Year>2010 &LLSIM_BUM_Example_observer$fleet==2,]), logdat = droplevels(LLSIM_BUM_Example_logbook[LLSIM_BUM_Example_logbook$Year>2010 & LLSIM_BUM_Example_logbook$fleet==2,]), yearVar = "Year", obsEffort = "hooks", logEffort = "hooks", logUnsampledEffort = "unsampledEffort", includeObsCatch = FALSE, factorNames = c("Year","area","fleet"), EstimateIndex = TRUE, EstimateBycatch = TRUE, logNum = NA, sampleUnit = "trips", complexModel = formula(y~Year+area+fleet+hbf+SWO), simpleModel = formula(y~Year), indexModel = formula(y~Year), designMethods =c("Ratio","Delta"), designVars=c("Year","area"), designPooling = FALSE, minStrataUnit=1, baseDir = getwd(), runName = "LLSIMBUMtripExample", runDescription = "LLSIm BUM by trip, with 5% observer coverage ", common = c("Swordfish","Blue marlin")[2], sp = c("Xiphias gladius","Makaira nigricans")[2], obsCatch = c("SWO","BUM")[2], catchUnit = "number", catchType = "catch" )
Step 2, run the dataCheck function
dataCheck(setupObj)
An html file with the data check figures will be printed to the output directory.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.