createRealizations: Create multiple realizations from data

View source: R/createRealizations.R

createRealizationsR Documentation

Create multiple realizations from data

Description

This function creates multiple realizations of patches of the variable of interest within the grid of locations created with createPopulation.

Usage

createRealizations(
  x_start,
  x_end,
  y_start,
  y_end,
  buffer,
  n.networks,
  n.realizations,
  SpeciesInfo,
  start.seed,
  variables,
  yvar
)

Arguments

x_start

The most western coordinate of the grid

x_end

The most eastern coordinate of the grid.

y_start

The most southern coordinate of the grid.

y_end

The most northern coordinate of the grid.

buffer

The distance from the edge of the grid from which initial samples should not be taken.

n.networks

The number of networks to be placed in the realization.

n.realizations

The number of realizations to create per n.networks.

SpeciesInfo

A dataframe containing, at a minimum, x and y coordinates and the variable of interest. Should only include plots that have the species of interest.

start.seed

The initial number used in set.seed. All subsequent numbers used in set.seed will be incremental after this number. seed = seq(start.seed, start.seed + 2*n.realizations + sum(n.networks)*n.realizations*2 + 1, by=1)

variables

Dataframe column names that are included in the final patch realizations. These columns are given a value of "0" if the species is not present or NA.

yvar

The variable of interest that determines how units will be assigned if during the randomization and rotation two units overlap. Must be a variable listed within the argument variables.

References

\insertRef

saubyadaptiveACSampling

Examples

library(magrittr)
library(dplyr)
library(ggplot2)
# EXAMPLE 1
# how large does the buffer need to be when generating realizations? (so 
#	that network units are not truncated by the dimensions of the realization 
#	grid)
data(PlotSurveys_season1)
PlotSurveys_season1 %>%
as.data.frame %>%
	summarise(
		max_x_buffer = max(abs(Rel_x)),
		max_y_buffer = max(abs(Rel_y))
	)

# realization info
x_start = 1
x_end = 30
y_start = 1
y_end = 30
n.networks = c(5, 15, 10, 20, 30, 40)
n.realizations = 1
SpeciesInfo = PlotSurveys_season1
variables = c("Stricta", "Pusilla", "Cactus")
start.seed=1
buffer=5

# create realizations
CactusRealizations = createRealizations(
x_start,
x_end,
y_start,
y_end,
buffer,
n.networks,
n.realizations,
SpeciesInfo,
start.seed,
variables,
yvar = "Cactus"
)

# plot realizations
p <- ggplot(CactusRealizations, 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(Cactus))) + 
	facet_wrap(~n.networks) + 
	scale_colour_gradientn(colours = rainbow(7)) +
	geom_text(aes(label=NetworkID), hjust=0, vjust=0)

p <- ggplot(CactusRealizations %>% filter(m>1), 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(Cactus))) + 
	facet_wrap(~n.networks) + 
	scale_colour_gradientn(colours = rainbow(7)) +
	geom_text(aes(label=NetworkID), hjust=0, vjust=0)

# EXAMPLE 2

# realization info	
x_start = 1
x_end = 20
y_start = 1
y_end = 20
n.networks = c(1,2,3)
n.realizations = 1
SpeciesInfo = Thompson1990Fig1Pop %>% 
	filter(m > 1) %>% 
	createNetworks
variables = "y_value"
buffer=5
start.seed=1

# create realizations
Thompson.realizations = createRealizations(x_start, x_end,
 	y_start, y_end, buffer, n.networks, n.realizations, SpeciesInfo, 
	start.seed, variables, yvar="y_value")	

# plot realizations
p <- ggplot(Thompson.realizations, 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))) + 
	facet_wrap(~n.networks) + 
	scale_colour_gradientn(colours = rainbow(7)) +
	geom_text(aes(label=NetworkID), hjust=0, vjust=0)

p <- ggplot(Thompson.realizations %>% filter(m > 1), 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))) + 
	facet_wrap(~n.networks) + 
	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.