test_spide

test_spide(fit, condition=None, procedure=None, fdr=0.05, strata=None, n_jobs=1)

Test niche-dependent differential expression (R testSpiDE).

Always runs the pooled test: for every (gene, index cell type, niche cell type), whether the gene’s expression in the index type changes with the density of the niche type, within patients, consistently across patients. If a condition is given (here, or recorded by fit_spide), it also runs the condition-specific test: whether that slope differs between the two conditions, a between-patient contrast of within-patient slopes.

The condition test is carried out within a family of triplets chosen without looking at the condition, so the choice is exact under any relabelling of patients:

The heterogeneity filters need each patient’s slopes, so they are the slopes engine’s only.

Parameters

Name Type Description Default
fit SpiDEFit A fit from fit_spide. required
condition str Default: the condition recorded by the fit, if any. Otherwise a two-level, patient-level column of fit.patients. With the sandwich engine it must be the condition the model was fitted with. The contrast is second level minus first. None
procedure ('pooled_or_heterogeneity', 'heterogeneity', 'filtered', 'all') The condition test’s family; default by engine. "pooled_or_heterogeneity"
fdr float The FDR level of the filter. 0.05
strata str Default: the fit’s. A patient-level column adjusted for in the slopes engine’s condition test (e.g. slide, where the condition is confounded with it). None
n_jobs int The slopes engine’s condition test is run over genes in blocks on this many workers. 1

Returns

Name Type Description
SpiDEResults Read it with SpiDEResults.results.

See Also

fit_spide : Produces the fit that is tested here. spide : Build, fit and test in one call. results : Extract the results table.

Examples

from spidepy import build_niches, fit_spide, test_spide
from spidepy.datasets import toy_spide
adata = build_niches(toy_spide(), sigma=30)
fit = fit_spide(adata, condition="condition", verbose=False)
res = test_spide(fit)
res.contrast
'Responder - Non-responder'
res.procedure
'pooled_or_heterogeneity'
sorted(res.results(test="both")["test"].unique())
['condition', 'pooled']