View source: R/randomizeClusters.R
randomizeClusters | R Documentation |
This function creates patches of the species of interest within the grid of locations created with createPop
based on a dataset provided. First, it randomly determines the new locations of network centers and (sampleGridPop
),, and then it randomly rotates the each network to further randomize the real data. Finally, it reassigns NetworkID (using assignNetworkMembership
as previously distinct networks may have been located close enough that they have now merged to create a single network.
If species information is assigned twice to a given unit (as can happen in the case of overlapping, neighboring networks), the unit will be preferentially assigned the information where the species is present (if only one of the duplicate records has the species as present). If there are more than one records indicating the species is present, one of the duplicate records is randomly drawn and then assigned to the unit.
The function returns a list, the first object being the list of units occupied by the species within the population, and the second object being a vector of the remaining, unused seed numbers.
This function uses a maximum of 2 + n.networks + number of units in the smallest network
random numbers: the first to set the seed to sample locations from a grid, the second to sample networks to assign to those locations (more specifically, the centers of the networks are assigned to those locations). Then n.networks
random numbers to determine the degrees to which to rotate each network of units before it is assigned coordinates. Finally, the last n.networks
random numbers are used, if necessary, to randomly determine which unit is used if units from multiple networks overlap.
MENTION BUFFER?
randomizeClusters(grid, n.networks, cluster.info, seed, yvar)
grid |
A dataframe of all x and y coordinates (as integer values) within a rectangular or square grid of coordinates for which the $y$-value *satisfies* the ACS criterion. (The grid can be first created with |
n.networks |
Number of networks to sample from the population of networks. |
cluster.info |
Data.frame of all network units. The data.frame should, at a minimum, include fields with information about the species used to initiate ACS, a PlotID field, a NetworkID field, and x and y coordinates. |
seed |
Vector of numbers to be given to |
yvar |
A string giving the name of the variable of interest, y, in the supplied dataframe popdata. This variable determines the condition under which adaptive cluster sampling takes place. In the dataframe $popdata$ this variable y must be numeric. |
saubyadaptiveACSampling
library(magrittr) library(dplyr) library(ggplot2) # realization info x_start = 1 x_end = 30 y_start = 1 y_end = 30 buffer = 5 grid <- createPop( x_start + buffer, x_end - buffer, y_start + buffer, y_end - buffer ) n.networks = 3 seed = 2000:2100 # WHY DID I MAKE THIS MANY SEEDS? data(Thompson1990Fig1Pop) cluster.info = Thompson1990Fig1Pop %>% dplyr::filter(m > 1) %>% createNetworks Thompson1990_realization = randomizeClusters(grid, n.networks, cluster.info, seed, yvar="y_value") # plot realization library(ggplot2) p <- ggplot(Thompson1990_realization, aes(x, y, colour=NetworkID, label=NetworkID)) p + annotate("rect", xmin=x_start, xmax=x_end, ymin=y_start, ymax=y_end, alpha=0, colour="grey") + geom_point(aes(size=factor(y_value))) + scale_colour_gradientn(colours = rainbow(7)) + geom_text(aes(label=NetworkID), hjust=0, vjust=0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.