| Title: | Spatial Lag Regression for Spatial Transcriptomics |
|---|---|
| Description: | Ranks genes in spatial transcriptomics data by the association between a spot's expression and the expression of its neighbours. For every gene, a quasi-Poisson generalized linear model is fitted with a library-size offset, user-defined design terms from the colData, and the spatial lag of the gene's own normalised counts as an additional covariate. The lag is a row-normalised, inverse-distance weighted mean over spots within a given radius, computed separately for each sample. The coefficient and test statistic of the lag, and the rank of the statistic across genes, are stored in the rowData of the input SpatialExperiment. No p-values are reported, because the null distribution of the statistic is not calibrated; the statistic is intended for ranking genes. Weights are computed in C++ with RcppArmadillo, and genes are fitted in parallel with BiocParallel. Plotting functions and a Shiny explorer are included. |
| Authors: | Sahal Paladan [aut, cre] (ORCID: <https://orcid.org/0009-0005-0120-128X>) |
| Maintainer: | Sahal Paladan <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.99.6 |
| Built: | 2026-12-02 04:49:07 UTC |
| Source: | https://github.com/bioc/spatialLagGLM |
Simulates a 30 x 30 grid of spots and 50 negative binomial genes. Spots
within 7 units of the grid centre are labelled "TumorCore", the
rest "Margin", and Gene1 is up-regulated in the core.
makeMockSpatial()makeMockSpatial()
A SpatialExperiment object with
synthetic counts and coordinates.
se <- makeMockSpatial()se <- makeMockSpatial()
Plots the effect size against the absolute statistic for every gene and
labels the top genes with the largest absolute statistic. The
statistics are not calibrated (see spatialLagGLM), so no
significance categories or thresholds are drawn: use the plot to rank genes.
plotLagSummary(se, top = 10L)plotLagSummary(se, top = 10L)
se |
A |
top |
A single non-negative whole number: how many top-ranked genes to label. |
A ggplot2 object.
se <- makeMockSpatial() analyzed <- spatialLagGLM(se, design = ~condition, radius = 2.5) plotLagSummary(analyzed)se <- makeMockSpatial() analyzed <- spatialLagGLM(se, design = ~condition, radius = 2.5) plotLagSummary(analyzed)
Plots either the raw counts of a gene or its spatial lag (the weighted mean
of its neighbours' normalised counts, i.e. the covariate used by
spatialLagGLM). With several samples, each is drawn in its
own panel.
plotSpatialLag( se, gene_id, metric = c("expression", "spatial_lag"), assay.type = NULL )plotSpatialLag( se, gene_id, metric = c("expression", "spatial_lag"), assay.type = NULL )
se |
A |
gene_id |
A single gene name. |
metric |
|
assay.type |
A string naming the assay with raw counts. The default,
|
A ggplot2 object.
se <- makeMockSpatial() analyzed <- spatialLagGLM(se, design = ~condition, radius = 2.5) plotSpatialLag(analyzed, gene_id = "Gene1", metric = "expression") plotSpatialLag(analyzed, gene_id = "Gene1", metric = "spatial_lag")se <- makeMockSpatial() analyzed <- spatialLagGLM(se, design = ~condition, radius = 2.5) plotSpatialLag(analyzed, gene_id = "Gene1", metric = "expression") plotSpatialLag(analyzed, gene_id = "Gene1", metric = "spatial_lag")
Launch Interactive Spatial Lag Explorer
runSpatialLagExplorer(se)runSpatialLagExplorer(se)
se |
A |
Called for its side effect of starting a Shiny app; returns nothing useful.
if (interactive()) { se <- makeMockSpatial() analyzed <- spatialLagGLM(se, design = ~condition, radius = 2.5) runSpatialLagExplorer(analyzed) }if (interactive()) { se <- makeMockSpatial() analyzed <- spatialLagGLM(se, design = ~condition, radius = 2.5) runSpatialLagExplorer(analyzed) }
For every gene, fits a quasi-Poisson regression with a library-size offset,
the terms of design, and the spatial lag of the gene's own
size-factor-normalised counts as an extra covariate. The coefficient of the
spatial lag, its test statistic and the rank of that statistic across genes
are stored in rowData(se). No p-values are reported.
spatialLagGLM( se, design, radius = 2.5, assay.type = "counts", size.factors = NULL, BPPARAM = BiocParallel::bpparam() )spatialLagGLM( se, design, radius = 2.5, assay.type = "counts", size.factors = NULL, BPPARAM = BiocParallel::bpparam() )
se |
A |
design |
A formula using variables in |
radius |
A positive number: the distance within which spots are
neighbours, in the units of |
assay.type |
A string naming the assay with raw counts. |
size.factors |
|
BPPARAM |
A |
For spot and a given gene, the model is
where is the size factor (library size divided by its geometric
mean), the row of the design matrix, and
the spatial lag. The weights
are inverse distances between spots within radius,
row-normalised, and are computed separately for each sample_id.
The question asked is whether : given the offset and the
design terms, is a spot's expression associated with the weighted mean of
its neighbours' normalised expression?
Why no p-values. Because the lag is built from the same gene's
counts, each pair of neighbouring spots enters the regression twice, once
as the response and once inside a covariate. The usual quasi-Poisson
standard error ignores this. Under no spatial structure, the variance of
the statistic is larger than the model assumes by a factor of about
, which is close
to 2 for symmetric weights. Nominal p-values are therefore far too small
(about 18% of null genes fall below 0.05 in simulation). This factor
depends on the weights, not on the gene, so it does not change how genes
rank against each other. The statistic is therefore meant for
ranking genes, not for testing against a significance threshold. For
calibrated inference, compare the statistic with a permutation null (see
the vignette).
This is not a spatial autoregressive model.
Genes whose fit fails or does not converge get NA results, and a
warning reports how many.
The results are stored in rowData(se) as spatial_effect_size
(, in units of normalised counts, so it depends on the
expression level of the gene), spatial_statistic (
divided by its quasi-Poisson standard error) and spatial_rank (rank
of the absolute statistic, 1 = strongest). The radius, assay and size
factors used are stored in metadata(se)$spatialLagGLM.
se with spatial_effect_size, spatial_statistic
and spatial_rank added to rowData.
se <- makeMockSpatial() analyzed <- spatialLagGLM(se, design = ~condition, radius = 2.5) head(SummarizedExperiment::rowData(analyzed))se <- makeMockSpatial() analyzed <- spatialLagGLM(se, design = ~condition, radius = 2.5) head(SummarizedExperiment::rowData(analyzed))