| Title: | A package to compare intensities of point patterns across samples with spatial parametric models |
|---|---|
| Description: | `multipointR` is a package to compare the distribution of cells in an image or cross images with point process models. On a single image level point process models (`ppm`) model the spatial distribution of a cell type point pattern as a function of spatial covariates while accounting for natural spacing of cells. The main model class considered in `multipointR` are inhomgoeneous Gibb's point process models. Across multiple images, users can either compare multiple univariate `ppm` models in a for loop or fit one joint model across all images with `mppm`. `multipointR` provides an interface between `SpatialExperiment` and `SpatialFeatureExperiment` objects and let's users flexibly define their own `ppm`/`mppm` models with R's formula interface. |
| Authors: | Martin Emons [aut, cre] (ORCID: <https://orcid.org/0009-0000-5219-5311>), Wolfgang Huber [aut] (ORCID: <https://orcid.org/0000-0002-0474-2218>), Mark D. Robinson [aut, fnd] (ORCID: <https://orcid.org/0000-0002-3048-5518>) |
| Maintainer: | Martin Emons <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.99.0 |
| Built: | 2026-06-18 14:17:28 UTC |
| Source: | https://github.com/BiocStaging/multipointR |
Convert SpatialExperiment object to ppp object
.dfToppp(df, marks = NULL, continuous = FALSE, window = NULL).dfToppp(df, marks = NULL, continuous = FALSE, window = NULL)
df |
|
marks |
|
continuous |
|
window |
|
ppp; object for use with spatstat functions
# retrieve example data from Keren et al. (2018) spe <- SpatialDatasets::spe_Keren_2018() speSub <- subset(spe, , imageID == "6") dfSub <- .speToDf(speSub) pp <- .dfToppp(dfSub, marks = "cellType")# retrieve example data from Keren et al. (2018) spe <- SpatialDatasets::spe_Keren_2018() speSub <- subset(spe, , imageID == "6") dfSub <- .speToDf(speSub) pp <- .dfToppp(dfSub, marks = "cellType")
fit $n$ univariate Models for all $n$ images
.fitSingelModelsPerImage( spe, model = "ppm", imageId, imageLs = NULL, marks, formula, family = spatstat.model::dppGauss(), threshold = NULL, interaction = "StraussHard", cellspacing = NA, lambda = NULL, ncores = 1, verbose = TRUE, ... ).fitSingelModelsPerImage( spe, model = "ppm", imageId, imageLs = NULL, marks, formula, family = spatstat.model::dppGauss(), threshold = NULL, interaction = "StraussHard", cellspacing = NA, lambda = NULL, ncores = 1, verbose = TRUE, ... )
spe |
|
model |
|
imageId |
|
imageLs |
|
marks |
|
formula |
|
family |
|
threshold |
|
interaction |
|
cellspacing |
|
lambda |
|
ncores |
|
verbose |
|
... |
other parameters passed on to |
mppm object of the shared fit across all images
spe <- SpatialDatasets::spe_Keren_2018() out <- .fitSingelModelsPerImage(spe = spe, imageId = "imageID", imageLs = list("1", "2"), marks = "cellType", formula = as.formula("Keratin_Tumour ~ distfun(CD8_T_cell)"), threshold = 10)spe <- SpatialDatasets::spe_Keren_2018() out <- .fitSingelModelsPerImage(spe = spe, imageId = "imageID", imageLs = list("1", "2"), marks = "cellType", formula = as.formula("Keratin_Tumour ~ distfun(CD8_T_cell)"), threshold = 10)
Transform a SpatialExperiment into a dataframe
.speToDf(spe).speToDf(spe)
spe |
|
DataFrame; x and y coordinates from the corresponding
SpatialExperiment and the colData
# retrieve example data from Keren et al. (2018) spe <- SpatialDatasets::spe_Keren_2018() speSub <- subset(spe, , imageID == "6") dfSub <- .speToDf(speSub)# retrieve example data from Keren et al. (2018) spe <- SpatialDatasets::spe_Keren_2018() speSub <- subset(spe, , imageID == "6") dfSub <- .speToDf(speSub)
define the Interaction Model
defineInteractionModel(interaction, cellspacing, response, data)defineInteractionModel(interaction, cellspacing, response, data)
interaction |
|
cellspacing |
|
response |
|
data |
|
object of class interact
spe <- SpatialDatasets::spe_Keren_2018() speSub <- subset(spe, , imageID == "5") formula = as.formula("Keratin_Tumour ~ distfun(CD8_T_cell)") #define the response response <- as.character(formula.tools::lhs(formula)) #deparse the Formula and extract the data out <- deparseFormula(spe = speSub, response = response, formula = formula, marks = "cellType", lambda = NULL, threshold = 10) interactionModel <- defineInteractionModel(interaction = "Hardcore", cellspacing = NA, response = response, data = out[["data"]])spe <- SpatialDatasets::spe_Keren_2018() speSub <- subset(spe, , imageID == "5") formula = as.formula("Keratin_Tumour ~ distfun(CD8_T_cell)") #define the response response <- as.character(formula.tools::lhs(formula)) #deparse the Formula and extract the data out <- deparseFormula(spe = speSub, response = response, formula = formula, marks = "cellType", lambda = NULL, threshold = 10) interactionModel <- defineInteractionModel(interaction = "Hardcore", cellspacing = NA, response = response, data = out[["data"]])
deparse the Formula for spatstat and extract the relevant data
deparseFormula(spe, formula, response, marks, lambda, threshold)deparseFormula(spe, formula, response, marks, lambda, threshold)
spe |
|
formula |
|
response |
|
marks |
|
lambda |
|
threshold |
|
named list with both the updated formula and the data for fitting
spe <- SpatialDatasets::spe_Keren_2018() speSub <- subset(spe, , imageID == "5") formula = stats::as.formula("Keratin_Tumour ~ distfun(CD8_T_cell)") #define the response response <- as.character(formula.tools::lhs(formula)) #deparse the Formula and extract the data out <- deparseFormula(spe = speSub, response = response, formula = formula, marks = "cellType", lambda = NULL, threshold = 10)spe <- SpatialDatasets::spe_Keren_2018() speSub <- subset(spe, , imageID == "5") formula = stats::as.formula("Keratin_Tumour ~ distfun(CD8_T_cell)") #define the response response <- as.character(formula.tools::lhs(formula)) #deparse the Formula and extract the data out <- deparseFormula(spe = speSub, response = response, formula = formula, marks = "cellType", lambda = NULL, threshold = 10)
SpatialExperiment
objectFit point process models to one FOV of a SpatialExperiment
object
fitModel( spe, model = "ppm", marks, formula, family = spatstat.model::dppGauss(), threshold = NULL, interaction = "Fiksel", lambda = NULL, cellspacing = NA, ... )fitModel( spe, model = "ppm", marks, formula, family = spatstat.model::dppGauss(), threshold = NULL, interaction = "Fiksel", lambda = NULL, cellspacing = NA, ... )
spe |
|
model |
|
marks |
|
formula |
|
family |
|
threshold |
|
interaction |
|
lambda |
|
cellspacing |
|
... |
other parameters passed on to |
list; result from a dppm model in spatstat.model
spe <- SpatialDatasets::spe_Keren_2018() speSub <- subset(spe, , imageID == "5") mdl <- fitModel(spe = speSub, marks = "cellType", formula = as.formula("Keratin_Tumour ~ distfun(CD8_T_cell)") )spe <- SpatialDatasets::spe_Keren_2018() speSub <- subset(spe, , imageID == "5") mdl <- fitModel(spe = speSub, marks = "cellType", formula = as.formula("Keratin_Tumour ~ distfun(CD8_T_cell)") )
SpatialExperiment objectFit point process models across all images in the
SpatialExperiment object
fitModelAcrossImages( spe, model = "ppm", imageId, imageLs = NULL, marks, formula, family = spatstat.model::dppGauss(), threshold = NULL, interaction = "Fiksel", cellspacing = NA, lambda = NULL, sharedModel = TRUE, ncores = 1, verbose = TRUE, ... )fitModelAcrossImages( spe, model = "ppm", imageId, imageLs = NULL, marks, formula, family = spatstat.model::dppGauss(), threshold = NULL, interaction = "Fiksel", cellspacing = NA, lambda = NULL, sharedModel = TRUE, ncores = 1, verbose = TRUE, ... )
spe |
|
model |
|
imageId |
|
imageLs |
|
marks |
|
formula |
|
family |
|
threshold |
|
interaction |
|
cellspacing |
|
lambda |
|
sharedModel |
|
ncores |
|
verbose |
|
... |
other parameters passed on to |
list; result from a ppm model in spatstat.model or a mppm model
spe <- SpatialDatasets::spe_Keren_2018() mdl <- fitModelAcrossImages(spe = spe, imageId = "imageID", imageLs = list("1", "2"), marks = "cellType", formula = as.formula("Keratin_Tumour ~ distfun(CD8_T_cell)"), threshold = 10)spe <- SpatialDatasets::spe_Keren_2018() mdl <- fitModelAcrossImages(spe = spe, imageId = "imageID", imageLs = list("1", "2"), marks = "cellType", formula = as.formula("Keratin_Tumour ~ distfun(CD8_T_cell)"), threshold = 10)
Convert the list of spatial models to a dataframe
mdlToDf(mdlLs, imageCovariates = c("imageID"))mdlToDf(mdlLs, imageCovariates = c("imageID"))
mdlLs |
|
imageCovariates |
|
DataFrame of the model coefficients
spe <- SpatialDatasets::spe_Keren_2018() mdlLs <- fitModelAcrossImages(spe = spe, imageId = "imageID", imageLs = list("1", "2"), marks = "cellType", sharedModel = FALSE, formula = as.formula("Keratin_Tumour ~ distfun(CD8_T_cell)"), threshold = 10) mdlDf <- mdlToDf(mdlLs = mdlLs, imageCovariates = c("imageID", "tumour_type"))spe <- SpatialDatasets::spe_Keren_2018() mdlLs <- fitModelAcrossImages(spe = spe, imageId = "imageID", imageLs = list("1", "2"), marks = "cellType", sharedModel = FALSE, formula = as.formula("Keratin_Tumour ~ distfun(CD8_T_cell)"), threshold = 10) mdlDf <- mdlToDf(mdlLs = mdlLs, imageCovariates = c("imageID", "tumour_type"))
ppm objectsPlot mulitpointR ppm objects
## S3 method for class 'multipointRppm' plot(x, type = "trend", ...)## S3 method for class 'multipointRppm' plot(x, type = "trend", ...)
x |
|
type |
|
... |
further arguments passed to geom_raster |
a ggplot2 object of the model trend/intensity surfance
spe <- SpatialDatasets::spe_Keren_2018() speSub <- subset(spe, , imageID == "5") mdl <- fitModel(spe = speSub, marks = "cellType", formula = as.formula("Keratin_Tumour ~ distfun(CD8_T_cell)") ) plot(mdl)spe <- SpatialDatasets::spe_Keren_2018() speSub <- subset(spe, , imageID == "5") mdl <- fitModel(spe = speSub, marks = "cellType", formula = as.formula("Keratin_Tumour ~ distfun(CD8_T_cell)") ) plot(mdl)
convert a SpatialExperiment object into a point pattern
speToPPP(spe, marks)speToPPP(spe, marks)
spe |
|
marks |
|
A ppp object for use with any spatstat package
spe <- SpatialDatasets::spe_Keren_2018() speSub <- subset(spe, , imageID == "6") pp <- speToPPP(speSub, mark = "cellType")spe <- SpatialDatasets::spe_Keren_2018() speSub <- subset(spe, , imageID == "6") pp <- speToPPP(speSub, mark = "cellType")