Skip to contents

Perform kernel density estimation on SpatialExperiment for cell types of interest

Usage

gridDensity(
  spe,
  coi = NULL,
  id = "cell_type",
  kernel = "gaussian",
  bandwidth = NULL,
  ngrid.x = 100,
  ngrid.y = NULL,
  grid.length.x = NULL,
  grid.length.y = NULL,
  diggle = FALSE
)

Arguments

spe

A SpatialExperiment object.

coi

A character vector of cell types of interest (COIs). Default to all cell types.

id

A character. The name of the column of colData(spe) containing the cell type identifiers. Set to cell_type by default.

kernel

The smoothing kernel. Options are "gaussian", "epanechnikov", "quartic" or "disc".

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. Default to 100.

ngrid.y

Number of grids in the y-direction.

grid.length.x

Grid length in the x-direction.

grid.length.y

Grid length in the y-direction.

diggle

Logical. If TRUE, use the Jones-Diggle improved edge correction. See spatstat.explore::density.ppp() for details.

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)