2 R objects and example data sets
The main functions in the package rely on life histories and length composition objects. The life history object LifeHistoryObj
is an S4 object that holds the description of a life history. It gathers information about life history traits of each species such as the parameters of the length-weight relationship, von Bertalanffy growth parameters, length at 50% maturity, natural mortality, and others. The LifeHistoryObj
belongs to the class LifeHistory
in the fishSimGTG R package.
To create a new object of class LifeHistory
, use the new()
function as follows:
# Load the package
library(fishSimGTG)
library(fishLengthAssess)
LifeHistoryObj <- new("LifeHistory")
The user can see the elements or slots of the LifeHistoryObj
using the slotNames()
function.
## [1] "title" "speciesName" "shortDescription"
## [4] "L_type" "L_units" "Walpha_units"
## [7] "Linf" "K" "t0"
## [10] "L50" "L95delta" "M"
## [13] "MK" "LW_A" "LW_B"
## [16] "Tmax" "Steep" "R0"
## [19] "recSD" "recRho" "isHermaph"
## [22] "H50" "H95delta"
The user can access the help file for classes by using ?
symbol
An example of class LifeHistory
can be accessed within the fishSimGTG package (LifeHistoryExample
) and the user can see the elements or slots of the object using the slotNames()
function.
# use function slotNames to see elements of LifeHistoryObj example
slotNames(fishSimGTG::LifeHistoryExample)
## [1] "title" "speciesName" "shortDescription"
## [4] "L_type" "L_units" "Walpha_units"
## [7] "Linf" "K" "t0"
## [10] "L50" "L95delta" "M"
## [13] "MK" "LW_A" "LW_B"
## [16] "Tmax" "Steep" "R0"
## [19] "recSD" "recRho" "isHermaph"
## [22] "H50" "H95delta"
## An object of class "LifeHistory"
## Slot "title":
## [1] "Example fish"
##
## Slot "speciesName":
## [1] "Example fish"
##
## Slot "shortDescription":
## [1] "Simulated life history of a fish based on B-H invariants"
##
## Slot "L_type":
## [1] "TL"
##
## Slot "L_units":
## [1] "cm"
##
## Slot "Walpha_units":
## [1] "g"
##
## Slot "Linf":
## [1] 100
##
## Slot "K":
## [1] 0.2
##
## Slot "t0":
## [1] 0
##
## Slot "L50":
## [1] 66
##
## Slot "L95delta":
## [1] 1
##
## Slot "M":
## [1] 0.3
##
## Slot "MK":
## [1] 1.5
##
## Slot "LW_A":
## [1] 0.01
##
## Slot "LW_B":
## [1] 3
##
## Slot "Tmax":
## [1] 15
##
## Slot "Steep":
## [1] 0.99
##
## Slot "R0":
## [1] 1000
##
## Slot "recSD":
## [1] 0.6
##
## Slot "recRho":
## [1] 0
##
## Slot "isHermaph":
## [1] FALSE
##
## Slot "H50":
## numeric(0)
##
## Slot "H95delta":
## numeric(0)
The values of the slots can be edited by the user using the @
symbol.
# store LifeHistoryExample as a variable
LifeHistory_example <- fishSimGTG::LifeHistoryExample
# change slot speciesName
LifeHistory_example@speciesName <- "Example species"
LifeHistory_example@speciesName
## [1] "Example species"
More details on the life history object can be found in the user guide of the fishSimGTG R package in here.
The LengthCompObj
belongs to the class LengthComp
in fishLengthAssess R package and holds a length data set that can be structured either as raw data (i.e. individual length measurements) or length frequency data (i.e. numbers of fish per length bin).
To create a new object of class LengthComp
, use the new()
function as follows:
The user can see the elements or slots of the LengthCompObj
using the slotNames()
function.
## [1] "title" "description" "L_units"
## [4] "L_type" "L_source" "dataType"
## [7] "observationGroup" "header" "dt"
The user can access the help file for classes by using ?
symbol
The raw length data is a collection of length measurements stored as a vector. These are typically original length measurements of fish, which have not been binned. Multiple columns can be used, with each column pertaining to a level of a grouping variable, such as year or fleet.
An example of class LengthComp
containing raw length data can be accessed within the fishLengthAssess package (LengthCompExampleLength
).
# Example data set with length composition defined as raw length measurements by year
slotNames(LengthCompExampleLength)
## [1] "title" "description" "L_units"
## [4] "L_type" "L_source" "dataType"
## [7] "observationGroup" "header" "dt"
## 2015 2016 2017 2018 2019
## 1 55 49 51 43 29
## 2 55 53 53 43 31
## 3 55 53 53 45 31
## 4 57 57 55 45 33
## 5 57 57 57 45 33
## 6 59 57 59 47 33
The length frequency data is a collection of length measurements organized using two or more columns. The left-most column must contain bin mid points. The next column contains the number of length measurement observations in each bin. While the first column is reserved for the bin mid points, multiple columns to its right can be used with each pertaining to a level of a grouping variable, such as year or fleet.
An example of class LengthComp
containing length frequency data can be accessed within the fishLengthAssess package (LengthCompExampleFreq
).
# Example data set with length composition defined as length frequencies by year
slotNames(LengthCompExampleFreq)
## [1] "title" "description" "L_units"
## [4] "L_type" "L_source" "dataType"
## [7] "observationGroup" "header" "dt"
## LMids 2015 2016 2017 2018 2019
## 1 11 0 0 0 0 0
## 2 13 0 0 0 0 0
## 3 15 0 0 0 0 0
## 4 17 0 0 0 0 0
## 5 19 0 0 0 0 0
## 6 21 0 0 0 0 0