randomizeClusters: Randomly place networks within a grid population.

View source: R/randomizeClusters.R

randomizeClustersR Documentation

Randomly place networks within a grid population.

Description

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?

Usage

randomizeClusters(grid, n.networks, cluster.info, seed, yvar)

Arguments

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 createPop, and then rows can be removed that do not satisfy the ACS criterion). Should only include plots that have the species of interest.

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 set.seed(). Two numbers are used: the first to determine the sample of locations and the second to determine the sample of species information to be assigned to the sample locations.

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.

References

\insertRef

saubyadaptiveACSampling

Examples

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)

ksauby/ACS documentation built on Aug. 18, 2022, 3:33 a.m.