spatialSpread: Cost function based on sensor locations only

Description Usage Arguments Details Value Author(s) Examples

View source: R/spatialSpread.R

Description

This is a wrapper function to compute cost of a set of sensors based on their coordinates only. It takes as parameter fun an actual function to compute such cost for each location of the provided simulations and can summarise it with a function fun_R

Usage

1
spatialSpread(simulations, locations, weightByArea = TRUE, fun, fun_R)

Arguments

simulations

Simulations object or SpatialDataFrame to compute local cost in each location (values are ignored)

locations

indices of locations of sensors

weightByArea

if cost in the locations has to be multiplied by the area associated to them before summary; for "SpatialPointsDataFrame" the factor is 0.

fun

function to compute location-wise cost, for examples see spatialSpreadFunctions; needs the parameters allLocations, locations; can be the result of replaceDefault with type = "fun.spatialSpread"; result must have length number of locations

fun_R

function to summarise the result of fun; must have parameter x, generate by replaceDefault with type = "funR.spatialSpread"

Details

The function itself is only a wrapper to turn simulations and locations into the correct form and apply the functions.

Value

List

cost

result of fun_R, missing if no fun_R given

costLocations

result of fun, length equals number of locations in simulations

Author(s)

Kristina B. Helle, kristina.helle@uni-muenster.de

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# prepare data and functions
data(radioactivePlumes)
data(medianVariogram)

krigingVarianceMedian = 
  replaceDefault(krigingVariance, newDefaults = list(model = medianVariogram))[["fun"]]

meanFun = function(x){mean(x, na.rm = TRUE)}

locationsSensors = sample.int(nLocations(radioactivePlumes), 50)

spatialSpread_minDist = spatialSpread(
    simulations = radioactivePlumes,
    locations = locationsSensors, 
    weightByArea = TRUE,
    fun = minimalDistance,
    fun_R = meanFun
)
spatialSpread_krigingVar = spatialSpread(
    simulations = radioactivePlumes,
    locations = locationsSensors, 
    weightByArea = TRUE,
    fun = krigingVarianceMedian,
    fun_R = meanFun
  )

# plot maps
## Not run: 
## takes some seconds
y = radioactivePlumes@locations
y@data$minDist = spatialSpread_minDist[["costLocations"]]
y@data$krigVar = spatialSpread_krigingVar[["costLocations"]]
yPoints = as(y, "SpatialPointsDataFrame")

# distance to next sensor
spplot(y, zcol = "minDist", 
       sp.layout = list("sp.points", yPoints[locationsSensors,], 
                          col = 3))
# kriging variance
spplot(y, zcol = "krigVar", 
       sp.layout = list("sp.points", yPoints[locationsSensors,], 
                          col = 3))

## End(Not run)

sensors4plumes documentation built on May 1, 2019, 10:27 p.m.