knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This package implements the buffered random sampling algorithm described in a paper by Kingsley, M., Kanneworff, P., & Carlsson, D. (2004).
The main function of the package, buffered_random_sampling
, requires two data sets: one with strata and one with elements (points) within the strata.
The package includes two example data sets, element
and stratum
, showing how they should look. (See the exact details by running ?element
and ?stratum
in the console.)
library(buffersam) set.seed(92) stratum head(element)
To create an allocation run the function on two data sets:
allocation <- buffered_random_sampling(element, stratum) allocation
It's possible to get feedback while the algorithm is running, to know how far it has come or better understand how the algorithm works. This feedback can be provided in text or visuals.
It's possible to visualise the allocation by using visualise=TRUE
.
allocation <- buffered_random_sampling(element, stratum, visualise=TRUE)
Use verbose=TRUE
to print the status in the terminal as the algorithm is running.
allocation <- buffered_random_sampling(element, stratum, verbose=TRUE)
It's possible to pause the execution of the algorithm while it's running to allow time for inspecting the progress. This only really makes sense if used together with one of the other feedback parameters.
allocation <- buffered_random_sampling(element, stratum, pause=TRUE)
detail
controls how often the algorithm should give feedback, visual, text, or
pause. Level 1 for least detail, level 4 for most.
allocation <- buffered_random_sampling(element, stratum, verbose=TRUE, detail=2)
allocation <- buffered_random_sampling(element, stratum, verbose=TRUE, detail=3)
It's possible that some elements need to be selected without regard to buffered random sampling. These elements should be pre-selected, as if the algorithm had already selected them. These could be elements from previous years that need to be repeated.
preselect_element <- head(element, 2) preselect_element
allocation <- buffered_random_sampling(element, stratum, preselect_element = preselect_element)
This section contains a brief description of the buffered random algorithm in words. Please refer to the paper for exact details.
The survey area is divided into a number of strata which contains a number of elements. Each element is a fixed point with a surrounding area. In the West Greenland shrimp survey, each element is the center point of a ~2 nautical miles square.
The algorithm doesn't impose any requirements on how the elements are laid out or how many of them are available. However, an element list is needed; the algorithm cannot select arbitrary points within each stratum.
Elements can be placed, so its surrounding area is inside two or more strata. This can be represented in the elements
data frame by having multiple rows with the same elementId
but different values for stratum
.
Before the algorithm runs, these elements are assigned to one stratum at random by removing all but one of the duplicated elementId
's from the data set. If the elements
data frame contains the column preselect_probability
, the sampling will be done proportionally to the values in this column. A possible value for this variable is the area the element occupies in the given stratum.
This is done to avoid increasing the likelihood of these elements being selected. Pre-selected elements are always kept.
This peculiarity is not described in the original paper.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.