Bhattacharya: Bhattacharya

View source: R/Bhattacharya.R

BhattacharyaR Documentation

Bhattacharya

Description

Analyzes the length frequeney distributions. The middle lengths obtained for each length group

Usage

Bhattacharya(x, length_class = seq(5, 20, by = 0.5), groups, mu = NULL, maxit = 5000)

Arguments

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

Details

If necessary, install mixtools package.

Examples

# 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)


PabloMBooster/fenix documentation built on Oct. 21, 2023, 8:22 p.m.