| 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.6 |
| Built: | 2026-09-25 12:12:00 UTC |
| Source: | https://github.com/bioc/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
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
Transform a SpatialExperiment into a dataframe
.speToDf(spe).speToDf(spe)
spe |
|
DataFrame; x and y coordinates from the corresponding
SpatialExperiment and the colData
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 ~ spatstat.geom::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 ~ spatstat.geom::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 ~ spatstat.geom::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 ~ spatstat.geom::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, improve.type = NULL, relaxed = FALSE, ... )fitModel( spe, model = "ppm", marks, formula, family = spatstat.model::dppGauss(), threshold = NULL, interaction = "Fiksel", lambda = NULL, cellspacing = NA, improve.type = NULL, relaxed = FALSE, ... )
spe |
|
model |
|
marks |
|
formula |
|
family |
|
threshold |
|
interaction |
|
lambda |
|
cellspacing |
|
improve.type |
|
relaxed |
|
... |
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 ~ spatstat.geom::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 ~ spatstat.geom::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 = FALSE, 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 = FALSE, 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 ~ spatstat.geom::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 ~ spatstat.geom::distfun(CD8_T_cell)" ), threshold = 10 )
Title
get_fun_call(expr, var)get_fun_call(expr, var)
expr |
part of a formula object |
var |
variable to extract |
the extracted formula call of the bespoke variable
Function to obtain the innermost call of a formula expression
get_innermost_call(term)get_innermost_call(term)
term |
the term of the function to de-nest |
the innermost call of a nested funciton
Convert the list of spatial models to a dataframe
mdlToDf(mdlLs, imageCovariates = c("imageID"), fine = FALSE)mdlToDf(mdlLs, imageCovariates = c("imageID"), fine = FALSE)
mdlLs |
|
imageCovariates |
|
fine |
|
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 ~ spatstat.geom::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 ~ spatstat.geom::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 ~ spatstat.geom::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 ~ spatstat.geom::distfun(CD8_T_cell)" ) ) plot(mdl)
convert a SpatialExperiment object into a point pattern
speToPPP(spe, marks, continuous = FALSE, window = NULL)speToPPP(spe, marks, continuous = FALSE, window = NULL)
spe |
|
marks |
|
continuous |
|
window |
|
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")