R/calc_index_areas.R
calc_index_areas.RdCalculate annual estimates of biomass (mt) for each area specified in
boundaries. The boundaries can be any configuration as long as all
boundaries lie within the overall grid; they can even be overlapping.
The more boundaries there are the longer the function will take to run.
calc_index_areas(data, fit, prediction_grid, dir, boundaries = "Coastwide")The data used for fitting the model
A fitted sdmTMB model object
The prediction grid for the survey that sdmTMB will use to make model predictions to
Directory path where results will be saved. If NULL, results
will only be returned (not saved to a file)
A character vector specifying which areas to calculate
indices for. These should be names from boundaries_data. The default is
"Coastwide", which calculates only the Coastwide index
A very large list is returned with predictions, model fits, and indices for
each area specified in boundaries. Potentially, two figures are also saved
to the disk displaying the index by year. The index for each area is also
saved to a csv file in dir titled est_by_area.csv.
The outer areas will be truncated based on the presence of positive tows such that the most northern and southern extents of adjoining areas will not extrapolate into areas where positive tows are not observed at least once. This is helpful for species that are sparsely sampled because model convergence is poor when there are a lot of zeros.
boundaries_data, a data object
available_areas(), helper function to list available areas
sdmTMB::get_index(), used to generate the area-specific indices
sdmTMB::sdmTMB(), used to create the fit object
if (FALSE) { # \dontrun{
# Read back in the saved object
load("sdmTMB_save.RData")
# pick which boundary you want to use, e.g., 4 for California,
boundaries_data[4]
# or you can make your own named list, e.g.,
list("test" = c(39, 38))
# run the function
index <- calc_index_areas(
data, fit, grid,
dir = getwd(), boundaries = list("test" = c(39, 38))
)
# look at the index, which will be in "test" because that is what we
# named the boundary
index[["test"]][["index"]]
} # }