Sets the the number of agents to initiate. THIS IS NOT FULLY IMPLEMENTED.

A SELES-like function to maintain conceptual backwards compatibility with that simulation tool. This is intended to ease transitions from SELES.

You must know how to use SELES for these to be useful.

initiateAgents(map, numAgents, probInit, asSpatialPoints = TRUE, indices)

# S4 method for Raster,missing,missing,ANY,missing
initiateAgents(map, numAgents, probInit, asSpatialPoints)

# S4 method for Raster,missing,Raster,ANY,missing
initiateAgents(map, probInit, asSpatialPoints)

# S4 method for Raster,numeric,missing,ANY,missing
initiateAgents(map, numAgents, probInit, asSpatialPoints = TRUE, indices)

# S4 method for Raster,numeric,Raster,ANY,missing
initiateAgents(map, numAgents, probInit, asSpatialPoints)

# S4 method for Raster,missing,missing,ANY,numeric
initiateAgents(map, numAgents, probInit, asSpatialPoints = TRUE, indices)

Arguments

map

RasterLayer with extent and resolution of desired return object

numAgents

numeric resulting from a call to numAgents

probInit

a Raster resulting from a probInit call

asSpatialPoints

logical. Should returned object be RasterLayer or SpatialPointsDataFrame (default)

indices

numeric. Indices of where agents should start

Value

A SpatialPointsDataFrame, with each row representing an individual agent

Author

Eliot McIntire

Examples

if (require(RandomFields)) { library(magrittr) library(raster) library(quickPlot) map <- raster(xmn = 0, xmx = 10, ymn = 0, ymx = 10, val = 0, res = 1) map <- gaussMap(map, scale = 1, var = 4, speedup = 1) pr <- probInit(map, p = (map/maxValue(map))^2) agents <- initiateAgents(map, 100, pr) if (interactive()) { clearPlot() Plot(map) Plot(agents, addTo = "map") } # Test that they are indeed selecting according to probabilities in pr library(data.table) dt1 <- data.table(table(round(map[agents], 0))) setnames(dt1, old = "N", new = "count") dt2 <- data.table(table(round(map[], 0))) setnames(dt2, old = "N", new = "available") dt <-dt1[dt2, on = "V1"] # join the counts and available data.tables setnames(dt, old = "V1", new = "mapValue") dt[, selection := count/available] dt[is.na(selection), selection := 0] if (interactive()) with(dt, {plot(mapValue, selection)}) #' # Note, can also produce a Raster representing agents, # then the number of points produced can't be more than # the number of pixels: agentsRas <- initiateAgents(map, 30, pr, asSpatialPoints = FALSE) if (interactive()) Plot(agentsRas) #' if (require(dplyr) && getRversion() >= 3.4) { # Check that the agents are more often at the higher probability areas based on pr if (utils::packageVersion("raster") >= "2.8-11") { out <- data.frame(stats::na.omit(crosstab(agentsRas, map)), table(round(map[]))) %>% dplyr::mutate(selectionRatio = Freq / Freq.1) %>% dplyr::select(-layer.1, -Var1) %>% dplyr::rename(Present = Freq, Avail = Freq.1, Type = layer.2) } else { out <- data.frame(stats::na.omit(crosstab(agentsRas, map)), table(round(map[]))) %>% dplyr::mutate(selectionRatio = Freq/Freq.1) %>% dplyr::select(-Var1, -Var1.1) %>% dplyr::rename(Present = Freq, Avail = Freq.1, Type = Var2) } out } }
#> #> Attaching package: ‘magrittr’
#> The following object is masked from ‘package:raster’: #> #> extract
#> Loading required package: dplyr
#> #> Attaching package: ‘dplyr’
#> The following object is masked from ‘package:MASS’: #> #> select
#> The following objects are masked from ‘package:data.table’: #> #> between, first, last
#> The following objects are masked from ‘package:raster’: #> #> intersect, select, union
#> The following objects are masked from ‘package:stats’: #> #> filter, lag
#> The following objects are masked from ‘package:base’: #> #> intersect, setdiff, setequal, union
#> Type Present Avail selectionRatio #> 1 0 2 2 1.0000000 #> 2 0 0 3 0.0000000 #> 3 1 3 7 0.4285714 #> 4 1 0 24 0.0000000 #> 5 2 7 16 0.4375000 #> 6 2 0 20 0.0000000 #> 7 3 20 13 1.5384615 #> 8 3 4 5 0.8000000 #> 9 4 12 9 1.3333333 #> 10 4 4 1 4.0000000 #> 11 5 12 2 6.0000000 #> 12 5 8 3 2.6666667 #> 13 6 9 7 1.2857143 #> 14 6 4 24 0.1666667 #> 15 7 2 16 0.1250000 #> 16 7 3 20 0.1500000 #> 17 8 3 13 0.2307692 #> 18 8 6 5 1.2000000 #> 19 10 0 9 0.0000000 #> 20 10 1 1 1.0000000