# Delete all objets of workspace
rm(list=ls(all=TRUE))
options(digits = 2, scipen=999)

# Working directory
setwd("C:/Users/christian.valero/Documents/SEGUIMIENTO_PELAGICOS/2018/CRUCERO/COMPOSICION/PRUEBA/PROCESOS_JUREL/PROCEDURES_DO")

# Libraries
library( DiagrammeR)
library(egg)
library(gdata)
library(dplyr)
library(tidyr)
library(ggplot2)
library(FSA) 

Introduction

Growth is generally the first process analysed in studies of fish stock and results in the most immediate application of age data, as the majority of analytical stock assessments use age-based models (Panfili et al. 2002).

Age data derived from reading solid structures is generally limited due to the cost and complexity involved. In contrast, the collection of length information is relatively simpler and less costly, thus catch-at-length data are more frequently available. Considering age and length are correlated, it is possible to determine catch-at-age from catch-at-length data.

Figure 1: Diagram of catch at age estimation.

Biological data

In the second stage a sub-sample per size class is taken. In this sub-sample the length, weigth and the collectiother measures of each specimen was recordered. The otoliths of each specimen are also collected.

LenWeight <- read.csv2("lenWeight.csv", sep = ";") 
LenWeight <- filter(LenWeight, !is.na(Month), !is.na(ForkLength), !is.na(Weight))
LenWeight$ForkLength <- as.numeric(as.character(LenWeight$ForkLength))
LenWeight$Weight <- as.numeric(as.character(LenWeight$Weight))
LenWeight$Zone <- 1 # Asignation a categorical variable indicating geographical area 
LenWeight$Trimester <- as.numeric(cut(LenWeight$Month,c(0,3,6,9,12),c(1,2,3,4))) # Asignation a time categorical variable 
headtail(LenWeight,10)
##     Month Year ForkLength Weight Otolith Zone Trimester
## 1       3 2018         11   14.7       2    1         1
## 2       3 2018         11   13.0       2    1         1
## 3       3 2018         15   33.7       2    1         1
## 4       3 2018         10   14.8       2    1         1
## 5       3 2018         12    9.7       2    1         1
## 6       3 2018         11   15.0       2    1         1
## 7       3 2018         10   11.0       2    1         1
## 8       3 2018         10    8.2       2    1         1
## 9       3 2018         12   14.8       2    1         1
## 10      3 2018         11   11.6       2    1         1
## 405     4 2018         13   25.0       2    1         2
## 406     4 2018         13   25.0       2    1         2
## 407     4 2018         12   20.0       2    1         2
## 408     4 2018         16   45.0       2    1         2
## 409     4 2018         21  120.0       2    1         2
## 410     4 2018         20  110.0       2    1         2
## 411     4 2018         22  140.0       2    1         2
## 412     4 2018         22  130.0       2    1         2
## 413     4 2018         23  130.0       2    1         2
## 414     4 2018         22  125.0       2    1         2

Cath at length

Corresponds to the total catch frecuency differentiated by each size range.

LenCatch <- read.csv2("LenCatch.csv", sep =";")
LenCatch <- gather(LenCatch, Zone, CatchL,"a","b","c","d","e","f","g")# tyding data
LenCatch <- aggregate(CatchL~ForkLength, data = LenCatch, FUN = sum)

headtail(LenCatch,10)
##    ForkLength     CatchL
## 1           5          0
## 2           6          0
## 3           7          0
## 4           8          0
## 5           9   29045221
## 6          10  270234305
## 7          11  785677931
## 8          12 1327220275
## 9          13 1927006478
## 10         14 2287199771
## 57         61          0
## 58         62          0
## 59         63          0
## 60         64          0
## 61         65          0
## 62         66          0
## 63         67          0
## 64         68          0
## 65         69          0
## 66         70          0

Age estimation

Otolith interpretation

This data contains each individual age estimation.

Age <- read.csv2("AgeAtLength.csv", sep =";")# individual age group estimation 
Age <- filter(Age,!is.na(TotalRadio), !is.na(NumRings),!is.na(ForkLength))

Marginal Increment

As a rule, if the marginal increment is translucent it is not counted because it is not fully formed. in the for cycle above, we calculate the proportion of the traslucent increment i in relation of the inncrement i-1.

Age$Im <- NA 

for(i in 1:dim(Age)[1]){
  auxI1 <- numeric(); auxI1 <- Age$TotalRadio[i]
  auxI2 <- numeric(); auxI2 <- Age[i,c(10:33)] # columns containg the ratio of each annulus
  
  if(all(is.na(as.numeric(auxI2)))){
    Age$Im[i] <- 0.249
    
    }else{
      auxI3 <- numeric(); auxI3 <- auxI2[which(is.na(as.numeric(auxI2)))[1]-2]
      auxI4 <- numeric(); auxI4 <- auxI2[which(is.na(as.numeric(auxI2)))[1]-1]
     
      if(length(auxI3) > 0 & length(auxI4) > 0){
        
        if(as.numeric(auxI3) > 0 & as.numeric(auxI4) > 0){
          Age$Im[i] <- (auxI1 - as.numeric(auxI4))/(as.numeric(auxI4) - as.numeric(auxI3))
          
          }else{
            Age$Im[i] <- 0.249
            
            }
        
        }else{
          Age$Im[i] <- 0.249 
          
          }
      Age$Im[which(Age$Im > 1)] <- 0.249
      Age$Im[which(Age$Im < 0)] <- 0.249
      
    }
  }

Age group

The age group is the number of calendar years after the date of capture, for this purpose each fish will be assigned depends on the year in wich it was spawned and on the date of capture, simplifying the identification of annual class per fish.

This estimate is calculated with the number of rings observed in the otolith, the type of edge of the otolith and an arbitrary date of birth. In Chile, the first date of birth is taken as a convention on January 1.

## Biological age (Cosidering the edge and the number of traslucient rings)
Age$Age <- NA 

for(i in 1:length(Age$NumRings)){
  
  Age$Age[i] <- as.factor( Age$NumRings[i])
  
  if(Age$Border[i] > 2) {
    Age$Age[i] <- as.numeric(sum(Age$NumRings[i],1 ))
  
    } else {
    Age$Age[i] <- Age$NumRings[i] 
  
  }
  Age$Age[i] <- as.numeric(Age$Age[i])
  
}
# Age group(considering the bioligical age, the nature of border, year of birth and the date of capture)
Age$AgeGroup <- NA

for(i in 1:length(Age$Month)){
  
  if (Age$Month[i] <= 5 & Age$Border[i] <= 2) {
    Age$AgeGroup[i] <- sum(Age$Age[i],1)
    
  } else if (Age$Month[i] == 6 & Age$Border[i] == 1 & Age$Im[i] <= 0.249) {
    Age$AgeGroup[i] <- Age$Age[i] 
    
  } else if (Age$Month[i] == 6 & Age$Border[i] == 1 & Age$Im[i] > 0.249) {
    Age$AgeGroup[i] <- sum(Age$Age[i],1)
    
  } else if (Age$Month[i] == 6 & Age$Border[i] == 2) {
    Age$AgeGroup[i] <- sum(Age$Age[i],1)
    
  } else if (Age$Month[i] == 7 & Age$Border[i] == 1 & Age$Im[i] <= 0.349) {
    Age$AgeGroup[i] <- Age$Age[i]
    
  } else if (Age$Month[i] == 7 & Age$Border[i] == 1 & Age$Im[i] > 0.349) {
    Age$AgeGroup[i] <- sum(Age$Age[i],1)
    
  } else if (Age$Month[i] == 7 & Age$Border[i] == 2) {
    Age$AgeGroup[i] <- sum(Age$Age[i],1) 
    
  } else if (Age$Month[i] == 8 & Age$Border[i] %in% c(1,2)  & Age$Im[i] <= 0.499) {
    Age$AgeGroup[i] <- Age$Age[i] 
    
  } else if (Age$Month[i] == 8 & Age$Border[i] %in% c(1,2) & Age$Im[i] > 0.499) { 
    Age$AgeGroup[i] <- sum(Age$Age[i],1) 
    
  } else if (Age$Month[i] == 9 & Age$Border[i]  == 1) {
    Age$AgeGroup[i] <- Age$Age[i] 
    
  } else if (Age$Month[i] == 9 & Age$Border[i]  == 2 & Age$Im[i] <= 0.699) {
    Age$AgeGroup[i] <- Age$Age[i] 
    
  } else if (Age$Month[i] == 9 & Age$Border[i]  == 2 & Age$Im[i] > 0.699) {
    Age$AgeGroup[i] <- sum(Age$Age[i],1) 
    
  } else if (Age$Month[i] >= 10 & Age$Border[i] <= 2) {
    Age$AgeGroup[i] <- Age$Age[i]
    
  } else {
    Age$AgeGroup[i] <- Age$Age[i]
  }
  
}

# converting into a factor
Age$ForkLength <- factor(Age$ForkLength, levels = c(5:70), labels= c(5:70), ordered = F )
Age$AgeGroup <- factor(Age$AgeGroup, levels = c(0:24), labels= c(0:24),ordered = F )

headtail(Age,5)
##     Month Year Otolith Zone Trimester ForkLength NumRings Border
## 1       3 2018       2    1         1         11        0      2
## 2       3 2018       2    1         1         11        0      2
## 3       3 2018       2    1         1         15        0      3
## 4       3 2018       2    1         1         10        0      2
## 5       3 2018       2    1         1         12        0      2
## 194     3 2018       2    1         1         15        1      2
## 195     3 2018       2    1         1         16        1      1
## 196     3 2018       2    1         1         15        0      3
## 197     3 2018       2    1         1         15        0      3
## 198     3 2018       2    1         1         17        1      1
##     TotalRadio R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17
## 1           15 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA
## 2           14 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA
## 3           21 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA
## 4           14 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA
## 5           14 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA
## 194         22 20 NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA
## 195         22 20 NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA
## 196         21 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA
## 197         21 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA
## 198         23 21 NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA
##     R18 R19 R20 R21 R22 R23 R24   Im Age AgeGroup
## 1    NA  NA  NA  NA  NA  NA  NA 0.25   0        1
## 2    NA  NA  NA  NA  NA  NA  NA 0.25   0        1
## 3    NA  NA  NA  NA  NA  NA  NA 0.25   1        1
## 4    NA  NA  NA  NA  NA  NA  NA 0.25   0        1
## 5    NA  NA  NA  NA  NA  NA  NA 0.25   0        1
## 194  NA  NA  NA  NA  NA  NA  NA 0.25   1        2
## 195  NA  NA  NA  NA  NA  NA  NA 0.25   1        2
## 196  NA  NA  NA  NA  NA  NA  NA 0.25   1        1
## 197  NA  NA  NA  NA  NA  NA  NA 0.25   1        1
## 198  NA  NA  NA  NA  NA  NA  NA 0.25   1        2

Age length key

The age-length key (ALK) is determined by ageing a sub-sample of the population, and is used to ascertain age data from larger length frecuency samples. ALKs describe distributions of size for each age, and relative number of individuals at each age. The ALK is presented as a table with ages in columns and lengths in rows, exhibiting probabilities of a fish belonging to a group of age “i” given it is of fork length “j”, with row totals summing to 1.

the probability of each size interval (j) to belong to a certain age group (i) is defined as:

\[q_{ij} = n_{ij}/n_j\] where:

  • i: Age group
  • j: Fork length
  • qij : Probability of individuals of length j belonging to an age group i
  • nij : Number of individuals of age group i with length j
  • nj : Total number of individuals of length j.
# Finding length classes without age group estimation but with length frecuency data 
Dif <- NA

auxD1 <- data.frame(table(Age$ForkLength));colnames(auxD1) <- c("ForkLength", "AgeGroup")# Vector with the size class without age group estimation
auxD1 <- cbind(LenCatch,auxD1["AgeGroup"])
auxD1 <- filter(auxD1, CatchL != 0 & AgeGroup == 0) # Vector with identifyng size classes whithout age group assigned
auxD2 <- read.csv2("Hist.csv", sep =";") # Vector  containing historical reference data of age group estimation classes without ageing data
auxD2 <- filter(auxD2, ForkLength %in% unique(auxD1$ForkLength))

Dif <- cbind(auxD1["ForkLength"],auxD2["AgeGroup"])# Vector with data of age group estimation of the size classes without age group estimation but with length frecuency data

headtail(read.csv2("Hist.csv", sep =";"),5)
##    ForkLength AgeGroup
## 1           7        0
## 2           8        0
## 3           9        1
## 4          10        1
## 5          11        1
## 57         63       14
## 58         64       16
## 59         65       16
## 60         66       16
## 61         68       15
headtail(Dif,10)
##   ForkLength AgeGroup
## 1         19        2
## 2         34        7
## 3         38        8
## 4         41        9
## 5         45       10
#Age length key
Alk <- NA

auxAlk1 <- Age[,c("ForkLength","AgeGroup")]
auxAlk1 <- rbind(auxAlk1,Dif)
auxAlk1 <- table(auxAlk1)

Alk <- prop.table(auxAlk1, margin=1 ) #Row proportions table.
Alk[is.nan(Alk)] <- 0

headtail(Alk,10)
##    0    1     2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
## 5  0 0.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 6  0 0.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 7  0 0.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 8  0 0.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 9  0 1.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 10 0 1.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 11 0 1.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 12 0 0.93 0.067 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 13 0 0.91 0.087 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 14 0 0.89 0.105 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 61 0 0.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 62 0 0.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 63 0 0.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 64 0 0.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 65 0 0.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 66 0 0.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 67 0 0.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 68 0 0.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 69 0 0.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## 70 0 0.00 0.000 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0

Length weigth relationship

The length-weight relationship is widely used in fisheries to estimate weight from the length of an individual and also to estimate condition indices. The most frequently used expression for this relationship corresponds to the allometric equation where the weight is expressed as a function of length, and its parameters are estimated by linear regression of log-transformed data. Since variability in weight usually increases with length, this transformation has the advantage that it tends to stabilize the weight variance, but introduces a bias factor in back-transformed predictions which requires correction.

The weight/length model is:

\[W_i = a*L_i^b\] We can derive a simple linear regression model applying a logarithmic transformation:

\[ln(W_i) = ln(a)+b*ln(L_i)\]

where Wi represents the weight and Li the length of the i-th fish; a and b correspond to the intercept and slope, respectively.

Slope and y-intercept

# Length weigth relationship paramethers
LenWeight$logL <- log(LenWeight$ForkLength)
LenWeight$logW <- log(LenWeight$Weight)

lm <- lm(logW ~ logL,data = LenWeight)
Vb <- data.frame(coef(lm))

a <- exp(Vb[1,1])# y-intercept
b <- Vb[2,1]# Slope
R <-cor(LenWeight$logW, LenWeight$logL)# R-squared
n <- dim(LenWeight)[1]# Number of individuals

Bias adjustment for mean weigth estimation

Systematic bias for each given average length occurs when the mean weight at a given age is estimated from the mean length. This bias increases with the variability in length within the sample (Ricker 1958). Pienaar & Ricker (1968) addressed this issue, presenting a method to correct this bias.

# Pending error adjustment table
SlopeAdj <- read.csv2("PendingError.csv", sep = ";")
SlopeAdj
##    Pend   a1   a2
## 1   1.0 0.00  0.0
## 2   1.1 0.08  0.0
## 3   1.2 0.15  0.0
## 4   1.3 0.23  0.0
## 5   1.4 0.32  0.0
## 6   1.5 0.42  0.0
## 7   1.6 0.52  0.0
## 8   1.7 0.63  0.0
## 9   1.8 0.74  0.0
## 10  1.9 0.87  0.0
## 11  2.0 1.00  0.0
## 12  2.1 1.14  0.0
## 13  2.2 1.31  0.0
## 14  2.3 1.48  0.0
## 15  2.4 1.66  0.0
## 16  2.5 1.86  0.0
## 17  2.6 2.07  0.0
## 18  2.7 2.29  0.0
## 19  2.8 2.52  0.0
## 20  2.9 2.75  0.0
## 21  3.0 3.00  0.0
## 22  3.1 3.25  0.2
## 23  3.2 3.51  0.4
## 24  3.3 3.77  0.6
## 25  3.4 4.04  0.9
## 26  3.5 4.32  1.2
## 27  3.6 4.62  1.5
## 28  3.7 4.95  1.8
## 29  3.8 5.29  2.2
## 30  3.9 5.64  2.6
## 31  4.0 6.00  3.0
## 32  4.1 6.36  3.5
## 33  4.2 6.73  4.1
## 34  4.3 7.11  4.9
## 35  4.4 7.50  5.9
## 36  4.5 7.90  7.1
## 37  4.6 8.31  8.4
## 38  4.7 8.72  9.7
## 39  4.8 9.14 11.3
## 40  4.9 9.57 13.0
# Ricker and piennar imput formula
auxbmax <- round(b,1)
auxbmin <- auxbmax - 0.1
auxP1 <- filter(SlopeAdj, Pend == auxbmax)["a1"]
auxP2 <- filter(SlopeAdj, Pend == auxbmin)["a1"]
auxP3 <- filter(SlopeAdj, Pend == auxbmax)["a2"]
auxP4 <- filter(SlopeAdj, Pend == auxbmin)["a2"]

# Piennar and ricker slope adjustments values (a1 and a2)
a1 <- as.numeric(auxP1 - ((auxbmax - b) * (auxP1 - auxP2)) / (auxbmax - auxbmin))
a2 <- as.numeric(auxP3 - ((auxbmax - b) * (auxP3 - auxP4)) / (auxbmax - auxbmin))

Table 1: Length weight relationship parameters

ab <- cbind("a" = a,"b" = b, "R2" = R,
            "n" = n, "a1" = a1, "a2" = a2)
ab
##           a   b   R2   n  a1  a2
## [1,] 0.0072 3.1 0.99 414 3.4 0.3

Abundance by age group

Once a key is available, samples of fish that were only measured for length can be distributed to age groups accordingly.

This is possible because it assumes that the sample of aged fish and the sample of fish measured for length are simple random samples from the same population, thus the probability that a fish is of a particular age, given its length is the same in both samples follows.

The individuals present in each length interval (Nj) are assigned to different ages according to a size-age key.

The number of individuals belonging to each age group according to size interval is estimated as:

\[N_{ij} = q_{ij}/N_j\] where:

The abundance by age group is obtained by:

\[N_i = \sum_{i=1}^{n} N_{ij} \]

where:

Catch at age(Number)

Comp <- NA

auxC1 <- LenCatch$CatchL * Alk

Comp <- as.data.frame(cbind("Zone" = 1,
                            "Year" = 2018, 
                            LenCatch$ForkLength,
                            LenCatch$CatchL, 
                            auxC1))#Catch at age by length

names(Comp) <- c("Zone","Year","ForkLength","Abun_n","GE0","GE1","GE2","GE3",
                         "GE4","GE5","GE6","GE7",
                        "GE8","GE9","GE10","GE11","GE12","GE13","GE14",
                        "GE15","GE16","GE17","GE18","GE19","G20","G21",
                        "G22","G23","G24")
headtail(Comp[,1:17],10)
##    Zone Year ForkLength     Abun_n GE0        GE1       GE2 GE3 GE4 GE5
## 5     1 2018          5          0   0          0         0   0   0   0
## 6     1 2018          6          0   0          0         0   0   0   0
## 7     1 2018          7          0   0          0         0   0   0   0
## 8     1 2018          8          0   0          0         0   0   0   0
## 9     1 2018          9   29045221   0   29045221         0   0   0   0
## 10    1 2018         10  270234305   0  270234305         0   0   0   0
## 11    1 2018         11  785677931   0  785677931         0   0   0   0
## 12    1 2018         12 1327220275   0 1238738923  88481352   0   0   0
## 13    1 2018         13 1927006478   0 1759440697 167565781   0   0   0
## 14    1 2018         14 2287199771   0 2046441901 240757871   0   0   0
## 61    1 2018         61          0   0          0         0   0   0   0
## 62    1 2018         62          0   0          0         0   0   0   0
## 63    1 2018         63          0   0          0         0   0   0   0
## 64    1 2018         64          0   0          0         0   0   0   0
## 65    1 2018         65          0   0          0         0   0   0   0
## 66    1 2018         66          0   0          0         0   0   0   0
## 67    1 2018         67          0   0          0         0   0   0   0
## 68    1 2018         68          0   0          0         0   0   0   0
## 69    1 2018         69          0   0          0         0   0   0   0
## 70    1 2018         70          0   0          0         0   0   0   0
##    GE6 GE7 GE8 GE9 GE10 GE11 GE12
## 5    0   0   0   0    0    0    0
## 6    0   0   0   0    0    0    0
## 7    0   0   0   0    0    0    0
## 8    0   0   0   0    0    0    0
## 9    0   0   0   0    0    0    0
## 10   0   0   0   0    0    0    0
## 11   0   0   0   0    0    0    0
## 12   0   0   0   0    0    0    0
## 13   0   0   0   0    0    0    0
## 14   0   0   0   0    0    0    0
## 61   0   0   0   0    0    0    0
## 62   0   0   0   0    0    0    0
## 63   0   0   0   0    0    0    0
## 64   0   0   0   0    0    0    0
## 65   0   0   0   0    0    0    0
## 66   0   0   0   0    0    0    0
## 67   0   0   0   0    0    0    0
## 68   0   0   0   0    0    0    0
## 69   0   0   0   0    0    0    0
## 70   0   0   0   0    0    0    0
Summary <- NA

auxS1 <- data.frame("CatchAgeNum" = apply(Comp[,c(5:29)], 2, sum))#Catch at age by length
auxS2 <-data.frame("AgeGroup" = c(0:24))

Summary <- cbind(auxS2,auxS1)

Percent of catch at age(Number)

Summary$PercNum <- Summary$CatchAgeNum / sum(Summary$CatchAgeNum) * 100

Mean length

the average length for each age group is expressed as

\[ \bar{p_{i}} = \frac{\sum_{i=1}^{n} l_{j}n_{ij}}{ni} \]

Donde:

  • \(l_{j}\) : Fork length j
  • \(n_{ij}\) : Estimated number of individuals of length j that belong to age group i
  • \(n_{i}\) : Estimated number of individuals in age group i.
auxML1 <- LenCatch$ForkLength * Comp[,c(5:29)]
auxML1 <- data.frame("MeanLength" = apply(auxML1,2, sum))

Summary <- cbind(Summary,auxML1)
Summary$MeanLength <- Summary$MeanLength/Summary$CatchAgeNum
Summary$MeanLength[is.nan(Summary$MeanLength)] <- 0 #Replacing nan

Variance of mean length

The variance of the mean length is expressed as

\[ P_i = \sum_{j=1} p_jq_{ij} \]

\[\sigma_{p_j} = \sum_{j=1}^{L} (\frac{p_j^{2}q_{ij}(1-q_{ij})}{n_{j}-1}+ \frac{p_{j}(q_{ij}-P_{i})^{2}}{N}) \]

Donde:

  • \(n_{j}\) : Estimated number of individuals of length j
  • N : sample Size
  • \(p_{j}\) : Sample size for each length stratum j
  • \(q_{ij}\) : Probability of individuals of length j belonging to an age group i
Summary$Variance <- NA

auxV1 <- as.data.frame(LenCatch$CatchL * Alk)
auxV1$ForkLength <- as.numeric(as.character(auxV1$ForkLength))
auxV1$AgeGroup <- as.numeric(as.character(auxV1$AgeGroup))
auxV1$Tmed <- auxV1$ForkLength * auxV1$Freq
auxV1$Varl <- (auxV1$ForkLength^2) * auxV1$Freq
auxV2 <- aggregate(Varl ~ AgeGroup, data = auxV1, FUN = sum)
auxV3 <- aggregate(Tmed ~ AgeGroup, data = auxV1, FUN = sum)

Summary <- cbind(Summary, auxV2[2], auxV3[2])
Summary$Df <- abs(Summary$CatchAgeNum - 1)# degree of freedom

for(i in 1:length(Summary$Tmed)){
  
  if(Summary$Tmed[i] > 0){
    Summary$Variance[i] <- abs((Summary$Varl[i] - (Summary$MeanLength[i] *                 
    Summary$Tmed[i]))/Summary$Df[i])
  
    }else{
    Summary$Variance[i] <- 0
  }
}

Mean weight

Assuming that the length is a normal random variable the expected function value of \(W_L\), will be defined as:

\[E(W) = a(\bar{p_{i}}^b+a_{1}\bar{p_{i}}^{b-2}\sigma^2+a_{2}\bar{p_{i}}^{b-4}\sigma^4)\]

where:

  • \(\bar{p_{i}}\): Mean length at age group i
  • \(\sigma\): Mean length at age i
  • a : y-intercept
  • b : Slope
  • \(a_{1}\): Pienaar and ricker coefficient (1)
  • \(a_{2}\): Pienaar and ricker coefficient (2)
Summary$MeanWeight <- NA

for(i in 1:length(Summary$MeanLength)){
  
  if(Summary$MeanLength[i] > 0){
  Summary$MeanWeight[i] <- (a * ((Summary$MeanLength[i]^b) + 
                    a1 * (Summary$MeanLength[i]^(b-2)) * Summary$Variance[i] +
                    a2 * (Summary$MeanLength[i]^(b-4)) * Summary$Variance[i]^2))/1000  
  
  }else{
  Summary$MeanWeight[i] <- 0
  
  }
 }

Catch at age(Weight)

Summary$CatchAgeWeight <- (Summary$CatchAgeNum * Summary$MeanWeight) / 1000

Percent of catch at age(weight)

Summary$PercWeight  <- (Summary$CatchAgeWeight / sum(Summary$CatchAgeWeight)) * 100

Summary

auxC1 <- Summary[,c("CatchAgeNum","PercNum","MeanLength",  
                    "Variance", "MeanWeight", 
                    "CatchAgeWeight", "PercWeight" )]
auxC2 <- t(auxC1)
colnames(auxC2) <- c("GE0","GE1","GE2","GE3","GE4",
                  "GE5","GE6","GE7","GE8","GE9",
                  "GE10","GE11","GE12","GE13","GE14",
                  "GE15","GE16","GE17","GE18","GE19",
                  "GE20","GE21","GE22","GE23","GE24")

auxC3 <- data.frame(rowSums(auxC2))

# Total catch in number of individuals
TotalCatchN <- auxC3[1,1]

# Percent of catch in number
PercentCatchN <- auxC3[2,1]

#Mean Length
auxC4 <- colSums(Summary)["Tmed"]
Mean_Length <-  auxC4/TotalCatchN

#Variance
Variance <- abs((sum(Summary$Varl) - (Mean_Length*auxC4))/(TotalCatchN - 1))

MeanWeight <- (a * ((Mean_Length^b) + 
         a1 * (Mean_Length^(b-2)) * Variance+
         a2 * (Mean_Length^(b-4)) * Variance^2))/1000 

# Total catch in weigth(tonnes)
TotalCatchW <- rowSums(auxC2)[6]

# Percent of catch in weigth
PercentCatchW <- rowSums(auxC2)[7]

Output for technical report

CatchAtAge <- data.frame()

auxC5 <- data.frame("Abun_n" = c(TotalCatchN,
                                  PercentCatchN,
                                  Mean_Length,
                                  Variance,
                                  MeanWeight,
                                  TotalCatchW,
                                  PercentCatchW))

auxC6 <- data.frame("ForkLength" = c("CatchAgeNum","PercNum",
                                     "MeanLength","Variance",
                                     "MeanWeight","CatchAgeWeight",
                                     "PercWeight"))

auxC7 <- data.frame(cbind(auxC6, auxC5, auxC2))
auxC7$ForkLength <- as.character(auxC7$ForkLength)
auxC8 <- data.frame(Comp[,c(3:29)])
auxC8$ForkLength <- as.character(auxC8$ForkLength)
colnames(auxC8) <- colnames(auxC7)
auxC9 <- matrix(c(rep.int(NA,length(auxC8))),nrow = 1,ncol = length(auxC8))  
colnames(auxC9) <- colnames(auxC8)

CatchAtAge <- rbind(auxC8, auxC9, auxC7)   
rownames(CatchAtAge) <- NULL

# deleting all auxiliar objects
rm(list=ls(pattern="aux"))

Table 2: Table required for JM technical report

headtail(CatchAtAge[,1:5],10)
##        ForkLength          Abun_n GE0            GE1            GE2
## 1               5           0.000   0          0.000          0.000
## 2               6           0.000   0          0.000          0.000
## 3               7           0.000   0          0.000          0.000
## 4               8           0.000   0          0.000          0.000
## 5               9    29045220.616   0   29045220.616          0.000
## 6              10   270234304.594   0  270234304.594          0.000
## 7              11   785677930.922   0  785677930.922          0.000
## 8              12  1327220274.591   0 1238738922.952   88481351.639
## 9              13  1927006478.169   0 1759440697.459  167565780.710
## 10             14  2287199771.304   0 2046441900.640  240757870.664
## 65             69           0.000   0          0.000          0.000
## 66             70           0.000   0          0.000          0.000
## 67           <NA>              NA  NA             NA             NA
## 68    CatchAgeNum 10053739366.706   0 7852187551.781 1564023045.326
## 69        PercNum         100.000   0         78.102         15.557
## 70     MeanLength          14.318   0         13.338         15.132
## 71       Variance          10.137   0          2.581          2.446
## 72     MeanWeight           0.037   0          0.026          0.039
## 73 CatchAgeWeight      380762.704   0     207559.915      60763.955
## 74     PercWeight         100.000   0         54.512         15.958

References