Bhattacharya | R Documentation |
Analyzes the length frequeney distributions. The middle lengths obtained for each length group
Bhattacharya(x, length_class = seq(5, 20, by = 0.5), groups, mu = NULL, maxit = 5000)
x |
length frequency |
length_class |
length class |
groups |
number of groups that you want to separate |
mu |
starting value of vector of groups means |
maxit |
the maximum number of iterations |
If necessary, install mixtools package.
# Sample (Peruvian anchovy)
sample_frequency <- c(0,0,0,0,0,0,0,0,0,2,7,14,22,15,13,12,17,22,35,28,7,4,1,0,0,0,0,0,0,0,0)
length <- seq(5,20, by = 0.5)
# identify groups
view_modas <- modas(matrix(sample_frequency, nrow = 1), Lmin = 5, Lmax = 20, dL = 0.5, umbral = 10)
# number of groups
num_modas = apply(view_modas, 1, unique_modas)
# weighted
catch_frequency = weighted_frequency(length = length, frequency = sample_frequency, a = 0.003925, b = 3.2178, catch = 50000)
plot(length, catch_frequency, type = "l", lwd = 2, ylab = "Catch (number of individuals)", xlab = "Length (cm)")
# bhattacharya
out_cohortes = Bhattacharya(x = catch_frequency, groups = num_modas)
# rebuild the cohorts
cohortes <- NULL
for(i in 1:length(out_cohortes$tableBhatt$Population)){
N = out_cohortes$tableBhatt$Population[i]
L = out_cohortes$tableBhatt$Mean[i]
S = out_cohortes$outL$sigma[i]
cohortei = cohort_to_length(cohort = c(N, L, S), lower = 5, upper = 20)
cohortes = rbind(cohortes, cohortei)
}
# plots
plot(length, catch_frequency, type = "l", lwd = 2, ylab = "Catch (number of individuals)", xlab = "Length (cm)")
lines(length, cohortes[1,], col = 2, lty = 2)
lines(length, cohortes[2,], col = 2, lty = 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.