Calculate 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,
  dir = NULL,
  prediction_grid = NULL,
  boundaries = "Coastwide",
  cog = FALSE,
  bias_correct = TRUE
)

Arguments

data

The data used for fitting the model

fit

A fitted sdmTMB model object

dir

Directory path where results will be saved. If NULL, results will only be returned (not saved to a file)

prediction_grid

The prediction grid for the survey that sdmTMB will use to make model predictions to. Default is NULL where the data ranges from the fit object will be used to create a prediction grid using lookup_grid().

boundaries

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

cog

Logical. If TRUE, center of gravity estimates will also be calculated using sdmTMB::get_cog() for each area. Defaults to FALSE. Note that COG results are returned in long format with separate rows for the X (easting) and Y (northing) coordinate axes.

bias_correct

Logical. If TRUE sdmTMB::get_index() and sdmTMB::get_cog() will use bias correction to account for the non-linear transformation of random effects when calculating the index. Will be faster if set to FALSE, but is TRUE by default

Value

A list with the following components:

results

A named list with one element per area, each containing the sdmTMB prediction object, the raw index data frame, and (if cog = TRUE) the raw cog data frame.

indices

A data frame of biomass index estimates across all areas, with columns: area, year, est, lwr, upr, log_est, se, se_natural, type. Saved to est_by_area.csv if dir is provided.

cogs

(Only present if cog = TRUE) A data frame of center of gravity estimates across all areas, with columns: area, year, est, lwr, upr, se, coord, type. Unlike indices, COG results are in long format with one row per year per coordinate axis (coord = "X" for easting, coord = "Y" for northing). Saved to cog_by_area.csv if dir is provided.

plot_indices

A ggplot object of the biomass index across all areas.

Details

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.

See also

Author

Kelli F. Johnson, Chantel Wetzel, and Eric Ward

Examples

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"]]

# Also calculate center of gravity
results <- calc_index_areas(
  data, fit, grid,
  dir = getwd(), boundaries = c("Coastwide", "CA"),
  cog = TRUE
)
# Full COG table (long format: two rows per year per area, one per coord)
results[["cogs"]]
# Northing (latitude) only
dplyr::filter(results[["cogs"]], coord == "Y")
} # }