Patient-level test of the between-sample composition association
Source:R/AllGenerics.R, R/composition.R
compositionTest.RdFor each index cell type \(k\) and niche cell type \(n\), regresses the
per-sample pseudobulk log2-CPM of every gene in the type-\(k\) cells on
the per-sample mean log1p niche density of type \(n\) around those cells,
across samples, with a limma moderated \(t\)-test. With a
condition the design is ~ niche * condition + covariates and
two terms are reported: "niche", the association pooled across
conditions, and "condition:niche", its difference between conditions
– the patient-level counterpart of the CellType:condition:niche
term that fitSpiDE() tests within samples. Without a condition only
"niche" is reported.
Usage
compositionTest(spe, ...)
# S4 method for class 'ANY'
compositionTest(
spe,
condition = NULL,
sigma,
index = NULL,
niche = NULL,
covariates = character(),
assay = "counts",
cell_type = "cell_type",
sample_id = "sample_id",
name = "Niche",
min.cells = 10L,
prior.count = 1,
verbose = TRUE
)Arguments
- spe
a SpatialExperiment with niche reducedDims (see
buildNiches()).- ...
further arguments passed to the method.
- condition
a character, the colData column of the condition (constant within sample), or
NULL.- sigma
a numeric, the bandwidth (one value).
- index, niche
character vectors restricting the index / niche cell types (NULL = all). An index type is never tested against its own niche.
- covariates
a character vector of sample-level colData columns to adjust for (constant within sample; the first non-missing value per sample is used).
- assay
a character, the counts assay.
- cell_type, sample_id
the colData columns of cell type and sample.
- name
the niche reducedDim prefix.
- min.cells
minimum cells of the index type a sample must contribute.
- prior.count
the pseudocount in the log2-CPM.
- verbose
report progress.
Value
a data.frame with one row per (gene, index type, niche type, term):
gene, ct_index, ct_niche, term, coef
(log2-CPM per unit log1p density), t, p, fdr (BH
within each (index, niche, term) over genes), fdr.global (BH over
every row), and n_samples.
Details
This is the association that fitSpiDE()'s nested (sample x cell type)
intercept (re.celltype = TRUE) deliberately absorbs. It is a
between-patient effect with \(S\) experimental units; it is not
neighbourhood-dependent differential expression, and the two must not be
conflated (see the model vignette). Samples contributing fewer than
min.cells cells of the index type are dropped for that index type,
and an index type with fewer than three remaining samples is skipped.
Examples
data(toySpiDE)
spe <- buildNiches(toySpiDE, sigma = 20)
ct <- compositionTest(spe, condition = "condition", sigma = 20)
#> compositionTest: A x B (6 samples)
#> compositionTest: A x C (6 samples)
#> compositionTest: B x A (6 samples)
#> compositionTest: B x C (6 samples)
#> compositionTest: C x A (6 samples)
#> compositionTest: C x B (6 samples)
head(ct[order(ct$p), ])
#> gene ct_index ct_niche term coef t p
#> 84 G4 B A niche -133.40784 -3.273716 0.002604489
#> 205 G5 C B niche 101.13068 2.985133 0.004817548
#> 91 G11 B A niche -130.08615 -3.053832 0.004876956
#> 67 G7 A C condition:niche 43.63017 4.685958 0.006620484
#> 111 G11 B A condition:niche 127.12975 2.896307 0.007200383
#> 165 G5 C A niche -16.41544 -2.775646 0.008338056
#> n_samples fdr fdr.global
#> 84 6 0.04876956 0.288528
#> 205 6 0.09635095 0.288528
#> 91 6 0.04876956 0.288528
#> 67 6 0.08415400 0.288528
#> 111 6 0.14400766 0.288528
#> 165 6 0.16676113 0.288528