| make_category_svc | R Documentation |
This function helps set up the data structure, formula, and mapping needed for fitting spatially varying coefficient models with categories (e.g., ages, length bins, species) that have both spatial and spatiotemporal random fields. It's particularly useful for age or length composition standardization models.
make_category_svc(
data,
category_column,
time_column,
share_spatial_sd = TRUE,
share_spatiotemporal_sd = TRUE
)
data |
Data frame containing the composition data. |
category_column |
Character. Name of the category column (e.g., "Age", "length_bin", "species"). |
time_column |
Character. Name of the time column (e.g., "Year"). |
share_spatial_sd |
Logical. If |
share_spatiotemporal_sd |
Logical. If |
This function creates spatially varying coefficient structures for composition models by setting up:
Spatial fields: One field per category (e.g., age-specific spatial fields) 2. Spatiotemporal fields: One field per category-time combination (e.g., age-year fields)
The sharing of variance parameters is controlled by share_spatial_sd and
share_spatiotemporal_sd. When TRUE, all fields of that type share the
same variance parameter, which is more parsimonious but assumes similar
variance magnitudes across categories.
The resulting model structure allows each category to have its own spatial pattern and temporal variation while controlling parameter sharing for identifiability and computational efficiency.
A list containing:
data_expanded: Data frame with added model matrix columns for use in sdmTMB().
svc_formula: Formula for the spatial_varying argument in sdmTMB().
svc_map: Map list for the map argument in sdmTMBcontrol().
info: List with summary information about the model structure.
set.seed(123)
data <- data.frame(
age = factor(rep(1:3, each = 20)),
year = rep(2020:2022, 20),
abundance = rnorm(60),
x = runif(60), y = runif(60)
)
# Set up model components
setup <- make_category_svc(
data = data,
category_column = "age",
time_column = "year",
share_spatial_sd = TRUE,
share_spatiotemporal_sd = TRUE
)
# Check the setup
setup$info
# See the age composition standardization vignette for more details
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.