The computation behind Statial::kontextualTest(); use that function, whose help page describes the method.
For each triple of parentDf it compares Statial's Kontextual statistic in each image with its exact
expectation and variance when the to cells are a random choice among the parent's cells, and combines the
images as spicy() does: each image's effect (observed minus expected, over Kontextual's normaliser) with the
image random effect within patients (Paule-Mandel), then the frailty GEE across patients with each condition's
CR2 variance and Satterthwaite df, and enough effective patients per condition. For a triple with from == to
the statistic is quadratic in the labels, and its variance is the exact variance of observed minus expected under
that random choice; an image where every choice gives the same value carries no information and is left out.
Usage
kontextualEngine(
cells,
parentDf,
condition,
subject = NULL,
covariates = NULL,
r = 50,
from = NULL,
to = NULL,
imageID = "imageID",
cellType = "cellType",
spatialCoords = c("x", "y"),
adjustAbundance = FALSE,
variance = c("cr2", "hartung_knapp"),
frailty = TRUE,
labelClustering = FALSE,
edgeCorrect = TRUE,
window = c("convex", "rectangle"),
ref = NULL,
cellWeights = NULL
)Arguments
- cells
A SingleCellExperiment, SpatialExperiment or data frame with a row per cell.
- parentDf
A data frame of triples with columns
from,to,parent(a list column of cell types containingto) and optionallyparent_name, as made byStatial::parentCombinations().- condition
The column with each image's condition, or a
Survcolumn of survival outcomes.- subject, covariates, r, from, to, imageID, cellType, spatialCoords, variance, frailty, ref
As for
spicy();ris one radius (several radii are not supported).- adjustAbundance
Adjust the test for the log share of the
totype among the parent's cells in each image (defaultFALSE), asspicy()'sadjustAbundance; its effect is reported asabundance_effect.- labelClustering
Whether to multiply each image's variance by a factor for clustering of the
tolabels. Off by default: the factor puts most of the weight on a few images, and without it the test stays at or below its nominal level when the conditions are shuffled between patients.- edgeCorrect
Correct the parent densities for the part of each disc outside the image's window.
- window
The window of each image for the edge correction:
"convex"or"rectangle".- cellWeights
Optional cell weights, a vector or a soft membership matrix as for
spicy(): with a matrix,fromandto(and thefrom,toofparentDf) name its columns, whileparentstill lists cell types. Afromcell enters with its weight, the score of a candidate counts with itstoweight, and the null shuffles thetoweights over the candidates. Pairs of a label with itself are not tested, andlabelClusteringis not available.
Value
A SpicyResults object with one row per triple (from, to, parent).