Given the prepared data and a spatial data frame of polygons outlining strata, identify a neighbourhood matrix for use in modelling.
Usage
prepare_spatial(
prepared_data,
strata_map,
voronoi = FALSE,
nearest_fill = FALSE,
island_link_dist_factor = 1.2,
buffer_type = "buffer",
buffer_dist = 10000,
add_map = NULL,
label_size = 3,
queen = FALSE,
quiet = FALSE
)Arguments
- prepared_data
List. Prepared data generated by
prepare_data().- strata_map
sfData Frame.sfmap of the strata in (MULTI)POLYGONs. Must have column "strata_name" matching strata output fromprepare_data().- voronoi
Logical. Whether or not to use Voroni method. Default
FALSE.- nearest_fill
Logical. For strata with no neighbours, whether or not to fill in by centroids of the 2 nearest neighbours when not using the Voronoi method. Default
FALSE.- island_link_dist_factor
Numeric. Distances within a factor of this amount are considered nearest strata neighbours. Used when linking otherwise isolated islands of strata, when not using the Voronoi method. Default 1.2.
- buffer_type
Character. Which buffer type to use when using the Voronoi method. Must be one of
buffer(default) orconvex_hull. See Details for specifics.- buffer_dist
Numeric. Distance to buffer and link the strata if not connected when using the Voronoi method. Units are that of
sf::st_crs(strata_map). This is the starting distance ifbuffer_type = "buffer"or the final distance ifbuffer_type = "convex_hull". Default 10000. See Details.- add_map
sfobject. Spatial data to add to map output.- label_size
Numeric. Size of the labels on the map. For data with many different strata it can be useful to reduce the size of the labels. Default 3.
- queen
Logical. Default is FALSE. if TRUE, a single shared boundary point defines strata as neighbours, if FALSE, more than one shared point is required. With a regular rectangular grid, if TRUE each grid-cell will have 8 neighbours, (analogous to the queen's moves in chess). If FALSE, each grid-cell will have 4 neighbours (analogous to the rook's move). note that for irregular grids more than one shared boundary point does not necessarily mean a shared boundary line. Setting to TRUE can increase the realised spatial smoothing of parameters in the model because it increases the number of neighbours with which each strata is sharing information. Value is passed to
spdep::poly2nb()- quiet
Logical. Suppress progress messages? Default
FALSE.
Value
List of prepared (meta) data to be used for modelling and further steps.
spatial_data- list of samples, nodes, adjacent matrix and map visualizing the matrixmodel_data- list of data formatted for use in Stan modellingmeta_data- meta data defining the analysismeta_strata- data frame listing strata meta dataraw_data- data frame of summarized counts used to createmodel_data(just formatted more nicely)
Details
When using the Voronoi method, a buffer is used to fill around and link
strata together. If the buffer_type is buffer, buffer_dist is the
starting distance over which to buffer. If not all strata are linked, this
distance is increased by 10% and applied again, repeating until all strata
are linked. If buffer_type is convex_hull, then a convex hull is used to
link up the strata before applying a buffer at a distance of buffer_dist.
Note that all distances are in the units of sf::st_crs(strata_map).
See also
Other Data prep functions:
prepare_data(),
prepare_model(),
stratify()
Examples
map <- load_map("bbs_cws")
s <- stratify(by = "bbs_cws", sample_data = TRUE,
use_map = FALSE)
#> Using 'bbs_cws' (standard) stratification
#> Using sample BBS data...
#> Using species Pacific Wren (sample data)
#> Filtering to species Pacific Wren (7221)
#> Stratifying data...
#> Combining BCR 7 and NS and PEI...
#> Renaming routes...
p <- prepare_data(s, min_max_route_years = 2)
sp <- prepare_spatial(p, map)
#> Preparing spatial data...
#> Identifying neighbours (non-Voronoi method)...
#> Formating neighbourhood matrices...
#> Plotting neighbourhood matrices...
# Visually explore the spatial linkages
sp$spatial_data$map
# Overlay subset strata map on original mapping data
sp <- prepare_spatial(p, map, add_map = map)
#> Preparing spatial data...
#> Identifying neighbours (non-Voronoi method)...
#> Formating neighbourhood matrices...
#> Plotting neighbourhood matrices...
sp$spatial_data$map
