pool_across_neighbors {cellpypes}R Documentation

Sum up x across neighbors in a nearest neighbor graph.

Description

Neighbor pooling means that x is summed across the nearest neighbors.

Usage

pool_across_neighbors(x, neighbors)

Arguments

x

Numeric vector.

neighbors

Nearest neighbor graph provided as NxK index matrix (N observations, K neighbors) or NxN adjacency matrix. Index matrices can be obtained with find_knn (specifically the slot idx in the list it returns).

Value

Numeric vector of length x.

Examples

set.seed(42)
# simulate 30 cells without biological signal:
dummy_dat <- matrix(rpois(3000, .1), ncol=30) 
# find 15 approximate nearest neighbors 
neighbors <- find_knn(dummy_dat, k = 15) 
# pool gene1 counts across neighbors:
neighbor_sum_gene1 <- pool_across_neighbors(dummy_dat[1,], neighbors$idx)


[Package cellpypes version 0.3.0 Index]