Perform kernel density estimation on SpatialExperiment for cell types of interest
Source:R/gridDensity.R
gridDensity.Rd
Perform kernel density estimation on SpatialExperiment for cell types of interest
Usage
gridDensity(
spe,
id = if (isVisium) "in_tissue" else "cell_type",
coi = NULL,
kernel = "gaussian",
bandwidth = NULL,
ngrid.x = NULL,
grid.length.x = NULL,
diggle = FALSE,
grid.type = c("hex", "square"),
isVisium = FALSE,
filterToVisiumSpot = isVisium
)
Arguments
- spe
A SpatialExperiment object.
- id
A character. The name of the column of colData(spe) containing the cell type identifiers. Set to cell_type by default.
- coi
A character vector of cell types of interest (COIs). Default to all cell types.
- kernel
The smoothing kernel. Options are "gaussian", "epanechnikov", "quartic" or "disc". For hexagonal grid, only Gaussian is implemented
- bandwidth
The smoothing bandwidth. By default performing automatic bandwidth selection using cross-validation using function spatstat.explore::bw.diggle.
- ngrid.x
Number of grids in the x-direction. Ignored when 'grid.length.x' is specified. Default to NULL.
- grid.length.x
Grid length in the x-direction. If both 'ngrid.x' and 'grid.length.x' are NULL, then 'grid.length.x' is set to 100 (micron) by default.
- diggle
Logical. If TRUE, use the Jones-Diggle improved edge correction. See spatstat.explore::density.ppp() for details.
- grid.type
Type of grid can be either hexagon or square.
- isVisium
Logical. If TRUE, fit hexagonal grids to Visium spots by replacing spatial coords with array rows & array cols.
- filterToVisiumSpot
Logical. If TRUE, filter grid polygons to only those with a Visium spot underneath.
Value
A SpatialExperiment object. Grid density estimates for all cell type of interest are stored in spe@metadata$grid_density. Grid information is stored in spe@metadata$grid_info
Examples
data("xenium_bc_spe")
spe <- gridDensity(spe)