library("spiDE")
data(toySpiDE)
spe <- buildNiches(toySpiDE, sigma = 30)
fit <- fitSpiDE(spe, index = "A", sigma = 30)
fitSpiDEFit (slopes engine), bandwidth 30
16 patients; condition: none
index A: 20 genes x 2 niches (B, C)
Fits, for every index cell type, one negative binomial GLM per gene of its expression on the local density of every other (niche) cell type, with an intercept per patient so that each niche effect is a within-patient slope. The slopes are then tested across patients by testSpiDE(), pooled or between conditions.
fitSpiDE(spe, condition = NULL, ...)
## S4 method for signature 'SpatialExperiment'
fitSpiDE(
spe,
condition = NULL,
engine = c("slopes", "sandwich"),
index = NULL,
niche = NULL,
sigma = NULL,
cell_type = "cell_type",
sample_id = "sample_id",
section = NULL,
covariates = character(),
depth = c("loglib", "nonlinear", "spatial_spline", "none"),
offset = NULL,
strata = NULL,
assay = "counts",
name = "Niche",
min.cells = 10L,
min.patients = 6L,
min.detect = 0.1,
genes = NULL,
tile = NULL,
min.tiles = 5L,
BPPARAM = BiocParallel::SerialParam(),
verbose = TRUE,
...
)
spe
|
a SpatialExperiment with raw counts and a niche reducedDim from buildNiches().
|
condition
|
NULL or a character, the colData column holding a two-level, patient-level condition. The slopes engine only records it (it can also be given to testSpiDE()); the sandwich engine fits the condition-specific model only when it is given.
|
…
|
unused. |
engine
|
“slopes” or “sandwich”.
|
index
|
NULL (every cell type with at least min.cells cells in at least min.patients patients) or a character vector of index cell types.
|
niche
|
NULL (test every niche column) or a character vector of niche columns to test; the others stay in the model as adjustments. An index type is never tested against its own niche (see mergeNiches()).
|
sigma
|
the niche bandwidth (needed only if spe carries several).
|
cell_type, sample_id
|
the colData columns of the cell type and of the patient (the unit that is replicated: one sample per patient). |
section
|
NULL (= sample_id) or the colData column of the tissue section, used to lay the spatial tiles of the variance estimate.
|
covariates
|
a character vector of cell-level colData columns to adjust for (centred; patient-level ones are absorbed by the patient intercepts). |
depth
|
how sequencing depth enters: “loglib” (default, the centred log library size as a covariate with a slope per gene), “nonlinear” (a natural cubic spline of it with 3 df, knots at the index type’s quantiles, so the depth response of each gene may bend), “spatial_spline” (a library-size spline within each patient: per section, log library size and its product with a smooth tensor spline of position, absorbed with the patient’s intercept, so each gene’s depth effect may vary over the section as in SpaNorm’s LS h_g(x, y) term, fitted jointly with the niche terms) or “none” (e.g. when offset carries depth).
|
offset
|
NULL or the name of an assay holding a log-scale offset per gene and cell (added to every linear predictor with its coefficient fixed at 1), e.g. the library-size component of a SpaNorm fit. Held dense per index type (genes x index cells).
|
strata
|
NULL or a patient-level colData column (e.g. slide or batch) whose niche slopes are adjusted for in the condition test. Needed when the condition is confounded with slide; used by the sandwich engine’s condition model here and by the slopes engine in testSpiDE(). The pooled test never uses it: its slope is the average over all patients.
|
assay
|
the counts assay (raw integer counts). |
name
|
the niche reducedDim prefix. |
min.cells
|
minimum cells of an index type a patient must contribute. |
min.patients
|
minimum patients an index type needs. |
min.detect
|
minimum fraction of an index type’s cells in which a gene is detected for it to be tested in that type. |
genes
|
NULL (every gene) or a character vector of the genes to test. Library size is always computed from every row of the assay, so a panel can be tested in part without changing each cell’s depth.
|
tile
|
side of the square tiles of the spatial variance estimate, in coordinate units (default 3 x the bandwidth). |
min.tiles
|
minimum tiles a patient needs for its own spatial variance. |
BPPARAM
|
a BiocParallelParam; genes are fitted in parallel. |
verbose
|
report progress. |
Two engines estimate the between-patient error the tests need:
“slopes” (default)
testSpiDE() combines them across patients with weighted limma. It is the more powerful engine when effects vary between patients, and its fit never sees the condition, so any condition can be tested later.
“sandwich”
The slopes engine passes every calibration null of five comparisons in four spatial cohorts, the sandwich engine all but one borderline tail; see the calibration vignette.
a SpiDEFit.
testSpiDE(), spiDE(), testNicheAbundance()