similaritySD: Determine (spatial) similarity between sampling designs

Description Usage Arguments Details Value Author(s) Examples

View source: R/postprocessing.R

Description

Takes sampling designs and a reference sampling design and computes similarity between them by various algorithms: number of coinciding sensors, sensors within a k-neighbourhood (based on get.knnx), Earth Mover's Distance (based on emd2d).

Usage

1
similaritySD(simulations, SD, referenceSD, type = "equal", k = 9, ...)

Arguments

simulations

Simulations object, needed to define spatial properties; not needed if type = "equal"

SD

vector, matrix (sampling designs in rows) or list of sampling designs; indices of the locations of simulations

referenceSD

sampling design (indices of the locations of simulations); all SD are compared to this sampling design

type

character, indicating comparison method, one of "equal", "Kneighbours", "EarthMoversDistance"

k

neighbourhood size, to be used for type = "Kneighbours", forwarded to get.knnx

...

parameters to be used for type = "EarthMoversDistance", forwarded to emd2d

Details

Originally Earth Mover's Distance compares matrices of two distributions. We can use it for cases where all locations lie on a regular grid. Then a sampling design is represented by a matrix of all grid cells: each sensor is represented by 1, all other cells are 0 (for locations on a SpatialPolygrid, a sensor may belong to several cells, then the weight 1 is distributed evenly to all these cells).

Value

A vector of length referring to the number of sampling designs in SD with the similarity between these sampling designs and referenceSD respectively.

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
## ---------------- prepare data --------------------------
# simulations with SpatialPolygridDataFrame
data(radioactivePlumes)

# simulations with SpatialPixelsDataFrame
data(meuse.grid)
coordinates(meuse.grid) = ~ x + y
gridded(meuse.grid) = TRUE
meuseGSim = subset(radioactivePlumes, 
                  locations = 1:length(meuse.grid), plumes = 1:10)
meuseGSim@locations = meuse.grid

# simulations with rectangular SpatialPixelsDataFrame
data(SPixelsDF)
rectSim = subset(radioactivePlumes, 
                 locations = 1:length(SPixelsDF), plumes = 1:10)
rectSim@locations = SPixelsDF # not nice, no checking if sizes fit

# simulations with SpatialPointsDataFrame 
data(meuse)
coordinates(meuse) = ~ x + y
meuseSim = subset(radioactivePlumes, 
                  locations = length(meuse), plumes = 1:10)
meuseSim@locations = meuse # not nice, no checking if sizes fit

# for meuseSim
sds0 = c(10,  25,  42,  84,  90,  92,  94,  97, 120, 153)#sample.int(155, 10)
sds1 = matrix(c(97,   79,   40,   68,  131,
                57,   18,   38,  118,   14,
                23,   71,   22,   94,   27,
                125,  108,    4,   80,  129,
                130,   96,  101,  137,   19,
                77,  138,   32,   95,   88,
                140,   73,   43,  153,   12,
                8,  141,   92,   35,  102), 
              byrow = TRUE, nrow = 8)#matrix(sample.int(155, 40), nrow = 8)
sds2 = list(
  c(28, 59, 64, 78, 81),
  c(5,  13,  21,  31,  45,  91,  92, 122, 130, 141),
  c(1,   2,  19,  36,  50,  51,  58,  59,  90, 103, 105, 107, 112, 123, 132),
  c(34,  48,  49,  50,  71,  76,  77,  86,  92,  97, 100, 103, 104, 106, 108, 
  110, 113, 127, 134, 142)
)

# ------------- "equal" -----------------------------
  sim_1_1 = similaritySD(# no simulations needed
    SD = sds1, referenceSD = sds0, type = "equal")  

#------------- "Kneighbours" -------------------
  sim_2_1_1 = similaritySD(simulations = meuseGSim,
                              SD = sds2, referenceSD = sds0, 
                              type = "Kneighbours", k = 4)  
  sim_2_1_2 = similaritySD(simulations = meuseGSim,
                         SD = sds2, referenceSD = sds0, 
                         type = "Kneighbours", k = 9) 

# plot points for visual comparison
plot(coordinates(meuseSim@locations), pch = ".")
   points(coordinates(meuseSim@locations)[sds0,], cex = 0.5)
   for (i in seq(along = sds2)){
     points(coordinates(meuseSim@locations)[sds2[[i]],], 
            col = i + 1)
   }
#---------- "EarthMoversDistance"----------
  # SpatialPixelsDataFrame
  sim_3_1_3 = similaritySD(simulations = rectSim,
                                SD = c(2,9), referenceSD = c(3,8), 
                                type = "EarthMoversDistance")

  sim_3_1_4 = similaritySD(simulations = rectSim,
                                SD = c(3,8), referenceSD = c(4,5), 
                                type = "EarthMoversDistance")
  sim_3_1_5 = similaritySD(simulations = rectSim,
                                SD = c(3,8), referenceSD = c(4,5), 
                                type = "EarthMoversDistance", dist = "manhattan")  

  ## SpatialPolygridDataFrame
  sim_3_1_5 = similaritySD(simulations = radioactivePlumes,
                                SD = c(220, 503), referenceSD = c(224, 544), 
                                type = "EarthMoversDistance")  

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