nn.cumsum: Cumulative sum over nearest neighbors

Description Usage Arguments Value Examples

View source: R/nn.cumsum.R

Description

nn.cumsum computes the cumulative sum of y for the sequences of indices in each element of the list contained in nn.

Usage

1
nn.cumsum(nn, y, simplify = TRUE)

Arguments

nn

A list of nearest neighbors in the format produced by nnpop.

y

A numeric vector of values to be summed over.

simplify

A logical value indicating whether the results should be simplified to a numeric vector. The default is TRUE.

Value

A vector or list, depending on the value of simplify.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# show nn.cumsum example for a circular scan setting
data(nydf)
coords = with(nydf, cbind(longitude, latitude))
cases = floor(nydf$cases)
d = sp::spDists(coords, longlat = TRUE)
# compute circular nearest neigbhors
nn = nnpop(d, pop = nydf$pop, ubpop = 0.1)
# compute cumulative sums over all nn
cnn = nn.cumsum(nn, cases)
# compute cumulative sums over just the first set of nn
cnn1 = cumsum(cases[nn[[1]]])
# check equality
all.equal(cnn1, cnn[seq_along(cnn1)])

smerc documentation built on Oct. 1, 2021, 5:07 p.m.