Skip to contents

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,
  quiet = FALSE
)

Arguments

prepared_data

List. Prepared data generated by prepare_data().

strata_map

sf Data Frame. sf map of the strata in (MULTI)POLYGONs. Must have column "strata_name" matching strata output from prepare_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.

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) or convex_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 if buffer_type = "buffer" or the final distance if buffer_type = "convex_hull". Default 10000. See Details.

add_map

sf object. 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.

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 matrix

  • model_data - list of data formatted for use in Stan modelling

  • meta_data - meta data defining the analysis

  • meta_strata - data frame listing strata meta data

  • raw_data - data frame of summarized counts used to create model_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)
#> 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$map
#> NULL

# 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$map
#> NULL