nn.cumsum: Cumulative sum over nearest neighbors

View source: R/nn.cumsum.R

nn.cumsumR Documentation

Cumulative sum over nearest neighbors

Description

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

Usage

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

# show nn.cumsum example for a circular scan setting
data(nydf)
coords <- with(nydf, cbind(longitude, latitude))
cases <- floor(nydf$cases)
d <- gedist(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. 10, 2023, 5:07 p.m.