Compute trophic levels for functional groups using diet composition
Source:R/utils.R
extractTrophicLevels.Rd
Calculates trophic levels for each functional group based on their diet composition using an iterative Gauss-Seidel algorithm.
Details
Calculate Trophic Levels from Diet Matrix
This function computes trophic levels by:
Starting with phytoplankton at trophic level 1.0
Initializing all other groups at trophic level 2.0
Iteratively updating trophic levels based on weighted diet composition
Continuing until convergence (difference < 0.01) or maximum iterations (100)
Processing 3D diet arrays with time series data
Trophic level calculation follows: TL = 1 + sum(diet_fraction_i * TL_prey_i)
The function calculates trophic levels for each time step separately and dynamically determines the number of groups from the diet matrix dimensions.
This provides a quantitative measure of each group's position in the food web and is useful for analyzing ecosystem structure and energy transfer efficiency.
Examples
if (FALSE) { # \dontrun{
# After running ZooMSS model with 3D time series
results <- zoomss_model(input_params, Groups)
trophic_levels <- extractTrophicLevels(results) # Returns matrix (time x groups)
# View trophic levels by group for final time step
final_tl <- trophic_levels[nrow(trophic_levels), ]
names(final_tl) <- results$param$Groups$Species
print(final_tl)
} # }