findSpatialNeighbors,SpatialFeatureExperimentmethod  R Documentation 
This function wraps all spatial neighborhood graphs implemented in the
package spdep
for the SpatialFeatureExperiment
(SFE) class, to
find spatial neighborhood graphs for the entities represented by columns or
rows of the gene count matrix in the SFE object or spatial entities in the
annotGeometries
field of the SFE object. Results are stored as
listw
objects in the spatialGraphs
field of the SFE object, as
listw
is used in many methods that facilitate the spatial neighborhood
graph in the spdep
, spatialreg
, and adespatial
. The edge
weights of the graph in the listw
object are by default style W (see
nb2listw
) and the unweighted neighbor list is in the
neighbours
field of the listw
object.
## S4 method for signature 'SpatialFeatureExperiment'
findSpatialNeighbors(
x,
sample_id = "all",
type = "spatialCoords",
MARGIN = 2,
method = c("tri2nb", "knearneigh", "dnearneigh", "gabrielneigh", "relativeneigh",
"soi.graph", "poly2nb"),
dist_type = c("none", "idw", "exp", "dpd"),
glist = NULL,
style = c("raw", "W", "B", "C", "U", "minmax", "S"),
nn_method = c("bioc", "spdep"),
alpha = 1,
dmax = NULL,
BPPARAM = SerialParam(),
BNPARAM = KmknnParam(),
zero.policy = TRUE,
...
)
x 
A 
sample_id 
Which sample(s) in the SFE object to use for the graph. Can also be "all", which means this function will compute the graph for all samples independently. 
type 
Name of the geometry associated with the MARGIN of interest for which to compute the graph. 
MARGIN 
Just like in 
method 
Name of function in the package 
dist_type 
Type of distancebased weight. "none" means not using
distancebased weights; the edge weights of the spatial neighborhood graph
will be entirely determined by the 
glist 
list of general weights corresponding to neighbours 
style 

nn_method 
Method to find k nearest neighbors and distance based
neighbors. Can be either "bioc" or "spdep". For "bioc", methods from

alpha 
Only relevant when 
dmax 
Only relevant when 
BPPARAM 
A 
BNPARAM 
A 
zero.policy 
default NULL, use global option value; if FALSE stop with error for any empty neighbour sets, if TRUE permit the weights list to be formed with zerolength weights vectors 
... 
Extra arguments passed to the 
For one sample, then a listw
object representing the graph,
with an attribute "method" recording the function used to build the graph,
its arguments, and information about the geometry for which the graph was
built. The attribute is used to reconstruct the graphs when the SFE object
is subsetted since some nodes in the graph will no longer be present. If
sample_id = "all" or has length > 1, then a named list of listw
objects, whose names are the sample_ids. To add the list for multiple
samples to a SFE object, specify the name
argument in the
spatialGraphs
replacement method, so graph of the same name
will be added to the SFE object for each sample.
style = "raw"
is only applicable when dist_type
is not
"none". If dist_type = "none"
and style = "raw"
, then style
will default to "W". Using distance based weights does not supplant finding
a spatial neighborhood graph. The spatial neighborhood graph is first found
and then its edges weighted based on distance in this function.
library(SFEData)
sfe < McKellarMuscleData(dataset = "small")
# sample_id is optional when only one sample is present
g < findSpatialNeighbors(sfe, sample_id = "Vis5A")
attr(g, "method")
# Returns named list for multiple samples
sfe2 < McKellarMuscleData(dataset = "small2")
sfe_combined < cbind(sfe, sfe2)
gs < findSpatialNeighbors(sfe, sample_id = "all")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.