Chapter 19 Creating Your Own Data Object
DLMtool has a series of functions to make importing data and applying data-limited Management Procedures relatively straightforward.
There are two approaches:
- Fill out a .csv data file in excel or a text editor and use a DLMtool function to create a properly formatted
Data
object (classData
), or - Create a blank
Data
object and populate it in R.
19.1 Creating a Data File in Excel
Probably the easiest way to get your data into the DLMtool is to populate a data table in an Excel workbook.
You can create a Data workbook using the DataInit
function, for example:
This will create a file ‘MyData.xlsx’ in your current working directory, which can be populate with your fishery data.
Remember, to see the help documentation for information on the slots in the Data object:
You do not have to enter data for every line of the data file, if data are not available simply put an ‘NA’ next to any given field.
19.2 Importing the Data object
Once populated, the Excel Data file can be imported into R:
In this case we get an error because the Data file is empty: we haven’t populated it with an data yet. Luckily for us, DLMtool includes several example Data files.
19.3 Example Fishery Data Files
One example Data file is the China rockfish. You can download this Data file to your current working directory and import into R:
The CSV files for the other example Fishery Data objects are also included in the DLMtool package. To find the location where these files are located on your machine, use the DLMDataDir
function:
## [1] "C:/Users/User/Documents/R/win-library/3.6/DLMtool"
We can then load one of the example CSV files using the XL2Data
function:
## Warning in XL2Data(file.path(DLMDataDir(), "China_rockfish.csv")): These rows in the Data file are not valid names and were not imported:
## MSY, BMSY, Sigma length composition
or the new
function:
## Warning in XL2Data(stock, ...): These rows in the Data file are not valid names and were not imported:
## MSY, BMSY, Sigma length composition
Alternatively, you can navigate to the data directory (DLMDataDir()
) on your machine and examine the contents and structure of the CSV data files in MS Excel or other software.
19.4 Populating a Data Object in R
You can create a blank Data
object and fill the slots directly in R. For example:
Madeup <- new('Data') # Create a blank DLM object
Madeup@Name <- 'Test' # Name it
Madeup@Cat <- matrix(20:11*rlnorm(10,0,0.2),nrow=1) # Generate fake catch data
Madeup@Units <- "Million metric tonnes" # State units of catch
Madeup@AvC <- mean(Madeup@Cat) # Average catches for time t (DCAC)
Madeup@t <- ncol(Madeup@Cat) # No. yrs for Av. catch (DCAC)
Madeup@Dt <- 0.5 # Depletion over time t (DCAC)
Madeup@Dep <- 0.5 # Depletion relative to unfished
Madeup@vbK <- 0.2 # VB maximum growth rate
Madeup@vbt0 <- (-0.5) # VB theoretical age at zero length
Madeup@vbLinf <- 200 # VB maximum length
Madeup@Mort <- 0.1 # Natural mortality rate
Madeup@Abun <- 200 # Current abundance
Madeup@FMSY_M <- 0.75 # Ratio of FMSY/M
Madeup@L50 <- 100 # Length at 50% maturity
Madeup@L95 <- 120 # Length at 95% maturity
Madeup@BMSY_B0 <- 0.35 # BMSY relative to unfished