knitr::opts_chunk$set(echo = TRUE)

Install package and set working directory

# Install package
library("devtools")
install_github("pfmc-assessments/nwfscDeltaGLM")

# Load package
library(nwfscDeltaGLM)

Datasets

There's three files needed to run the deltaGLM code. The package includes several that have been used as defaults for west coast assessments. It is critical that any new data used by the package have the same column names.

First, \code{SA3} contains the area, in hectares of 1756 strata, defined by the latitude and longitude (in decimal degrees), depth (in meters). Each strata also has an associated area, in hectares. These individual areas are summed up to define areas for boundaries chosen by the user.

data(SA3)

Second, a \code{strata.limits} data frame needs to be defined, with names \code{NLat} (the northern boundary), \code{SLat} (the southern boundary), \code{MinDepth} (the minimum depth), and \code{MaxDepth} (the maximum depth). An example of generating this data frame is below. Third, a data frame with raw haul data for an individual species needs to be defined. We provide an example in the \code{Example_Species} object.

data(Example_Species)
names(Example_Species)

Load data and strata

# Load data and strata
data(Example_Species)
masterDat = Example_Species

strata.limits = data.frame("STRATA" = c("First", "Second", "Mid", "D", "South"),
  NLat = c(49, 49, 49, 36, 34.5), 
  SLat = c(36, 36, 34.5, 34.5, 34.5),
  MinDepth = c(55, 183, 549, 55, 55),
  MaxDepth = c(183, 549, 700, 549, 549), stringsAsFactors = FALSE)

Modify species names

names(masterDat)

species = "Example_Species"
names(masterDat)[which(names(masterDat)=="EXPANDED_WT_KG")] = "Example_Species"

Run data processing function

This looks for an object named \code{masterDat} in the global environment,

DataList = processData(masterDat = masterDat, strata.limits = strata.limits)

Run model

Define settings for this run

mcmc.control = list(chains=1, thin=1, burnin=10, iterToSave=20)

modelStructure1 = list("StrataYear.positiveTows"="fixed", 
          "VesselYear.positiveTows"="zero",
          "Vessel.positiveTows"="zero",
          "StrataYear.zeroTows"="fixed",
          "VesselYear.zeroTows"="zero",
          "Vessel.zeroTows"="zero",
          "Catchability.positiveTows"="one",
          "Catchability.zeroTows"="zero",
          "year.deviations"="fixed",
          "strata.deviations"="fixed")

Run model

Create a list that could be used to hold additional models,

fitted_models = list()
fitted_models[[1]] = fitDeltaGLM(datalist = DataList, 
  modelStructure=modelStructure1, 
  mcmc.control=mcmc.control, 
  Species=species)

names(fitted_models[[1]])

Process MCMC output

# Make sure that Data is attached prior to running
data(SA3)
doMCMCDiags(datalist=DataList, 
            mods=fitted_models,
            strata.limits=strata.limits)


nwfsc-assess/nwfscDeltaGLM documentation built on July 8, 2023, 4:49 a.m.