# BC - Base Case
# FG - Double Growth.
# t.ALK_FG: The proportion of individuals of age 'a' in each length class.
# edades_tallas: A 'bootstrap' array with 'n' samples of 100000 individuals per age class,
# distributed along length classess acording to 't.ALK_DG' multinomial matrix.
# A: A bootstrap array with 'n' samples of the distribution of individuals of length 'i' and age 'a' in DG
# acording to 'BC' age-length distribution.
#
# Read the ALK, Base Case ALK, ALK_BC, and Faster Growth ALK, ALK_FG.
# The asumption is that the correct growth model is Double Growth (DG).
ALK_BC <- read.table("ALK_BaseCase.txt", row.names = 1, header = TRUE)
ALK_FG <- read.table("ALK_FG.txt", row.names = 1, header = TRUE)
# 'Transpose' the 'real' ALK (ALK_FG), i.e., instead of give the age compositon by age
# transform it to obtain the length composition by age.
t.ALK_FG <- ALK_FG
for(i in 1:9)
t.ALK_FG[,i] <- ALK_FG[,i]/sum(ALK_FG[,i])
# Generate 'it' random samples of the length distribution by age of the 'real'
# population.
ages_lengths <- array(0,dim = c(9,96, it))
for(k in 1:it){
for(a in 1:9){
ages_lengths[a,,k] <- rmultinom(1, 100000, t.ALK_FG[,a])
}
}
# A:: An array to store 'it' random samples of the distribution of individuals
# of length 'i' and age 'a' in FG according to 'BC' age-length distribution.
# A[,i,a,k]:: Is the age distribution according to ALK_BC of the individuals of
# in i-th length class and 'real' age 'a' in the k-th sample.
# apply(A[,,a,k],1, sum):: give us the total number of individulas of each 'real'
# age that goes into age 'a' using ALK_BC.
# So,
# erCAA[i,j,k] is the number of individuals of real age 'i' that are aged 'j' in
# the k-th iteration.
A <- array(0, dim = c(9, 96, 9,it))
erCAA <- array(0,dim = c(9,9,it) , dimnames = list(paste("Age", 0:8, sep = "_"), paste("Age", 0:8, sep = "_"), NULL))
for(k in 1:it){
for(a in 1:9){
for(i in 1:96){
A[,i,a,k] <- rmultinom(1,ages_lengths[a,i,k],ALK_BC[i,])
}
erCAA[a,,k] <- apply(A[,,a,k],1, sum)
}
}
# Divide by n = 100000 to obtain the proportions.
erCAA <- erCAA/100000
for(i in 1:it){
erCAA[,,i] <- t(erCAA[,,i])
}
# erCAA :: The square matrix used to parameterize the multinomial distribution
erCAA <- array(erCAA, dim = c(9,9,it))
CAA_BC <- array(dim = c(9,9,it))
# CAA_FG:: A catch-at-age matrix with the faster gowth assumption
for(i in 1:it){
CAA_BC[,,i] <- CAA_FG*erCAA[,,i]
}
# CAA_BC is an array with 'it' possible CAA matrices obtained using the Base Case growth assumption
# if the hypothesis of Faster Growth were true.