% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/spatialInference.R
\name{spatialInference}
\alias{spatialInference}
\title{Statistical Inference on Spatial Statistics Functions}
\usage{
spatialInference(
  spe,
  selection,
  fun,
  marks = NULL,
  rSeq = NULL,
  correction,
  sample_id,
  image_id,
  condition,
  continuous = FALSE,
  assay = "exprs",
  transformation = NULL,
  intensityAdjustment = "default",
  weights = "total",
  eps = 0.001,
  delta = "minNnDist",
  family = stats::gaussian(link = "log"),
  verbose = TRUE,
  upperDeltaProb = NULL,
  weightTransform = TRUE,
  AR1 = FALSE,
  sandwich = "cluster",
  ncores = 1,
  algorithm = "bam",
  ...
)
}
\arguments{
\item{spe}{a \code{SpatialExperiment} object}

\item{selection}{the mark(s) you want to compare. NOTE: This is directional.
c(A,B) is not the same result as c(B,A).}

\item{fun}{the \code{spatstat} function to compute on the point pattern object}

\item{marks}{the marks to consider e.g. cell types}

\item{rSeq}{the range of r values to compute the function over}

\item{correction}{the edge correction to be applied}

\item{sample_id}{the spe \code{colData} variable to mark the sample, if not NULL
this will result in a mixed model estimation}

\item{image_id}{the spe \code{colData} variable to mark the image}

\item{condition}{the spe \code{colData} variable to mark the condition}

\item{continuous}{A boolean indicating whether the marks are continuous
defaults to FALSE}

\item{assay}{the assay which is used if \code{continuous = TRUE}}

\item{transformation}{the transformation to be applied as exponential e.g.
1/2 for sqrt or Fisher's variance-stabilising transformation if "Fisher"}

\item{intensityAdjustment}{a logical whether or not to normalise out cell
type intensity differences in the functional regression model.
For $L$ functions the intensity effects is already explicit in the metric
definition. The intensity adjustement is via the average intensity of the
query cell type B in a cross (A->B) setting parametrised as a constant
covariate over the domain $r$. The "default" normalises $G$ and $F$ functions
like this but not all other functions.}

\item{weights}{the weighting to be applied to the functional GAM. Either NULL
(equal weights), total (npoints of total pattern), min (npoints of the smaller
subpattern) or max (npoints of the larger subpattern) or a user defined value
of same length as the number of curves to be estimated}

\item{eps}{some distributional families fail if the response is zero,
therefore, zeros can be replaced with a very small value eps}

\item{delta}{the delta value to remove from the beginning of the spatial
statistics functions. Can be reasonable if e.g. cells are always spaced
by 10 µm. If set to "minNnDist" it will take the mean of the minimum nearest
neighbour distance across all images for this cell type pair.}

\item{family}{the distributional family for the functional GAM}

\item{verbose}{logical indicating whether to print all information or not}

\item{upperDeltaProb}{the quantile to filter out the constant 1 part for \code{Gest}
and \code{Gcross}. If \code{NULL} no upper filtering is applied.}

\item{weightTransform}{logical indicating whether the weights (number of points)
should be sqrt transformed}

\item{AR1}{logical indicating whether to calculate the autocorrelation of the
residuals along the domain and account for this in a second fitting step}

\item{sandwich}{string indicating how and if to adjust for heterscedasticity of the
residuals with a sandwich correction}

\item{ncores}{the number of cores to use for parallel processing, default = 1}

\item{algorithm}{algorithm to fit the refund::pffr method. defaults to \code{bam}}

\item{...}{Other parameters passed to \code{spatstat.explore} functions for
parameters concerning the spatial function calculation and to \code{refund::pffr}
for the functional additive mixed model inference}
}
\value{
a list with four objects: i) the dataframe with the spatial
statistics results transformed and filtered as used for fitting,
ii) the raw spatial statistics results, iii) the designmatrix of the
inference and iv) the fitted pffr object v) the residual standard error per
condition defined as the residual sum of squares divided by the number of
datapoints - sum of the estimated degrees of freedom for the model parameters
as well as other QC metrics
}
\description{
A function to perform spatial statistical inference on spatial omics data.
This function works so far only on functions of radius "r".
}
\examples{
spe <- .loadExample()
#make the condition a factor variable
colData(spe)[["patient_stage"]] <- factor(colData(spe)[["patient_stage"]])
#relevel to have non-diabetic as the reference category
colData(spe)[["patient_stage"]] <- relevel(colData(spe)[["patient_stage"]],
"Non-diabetic")
res <- spatialInference(spe, c("alpha", "Tc"),
    fun = "Gcross", marks = "cell_type",
    rSeq = seq(0, 50, length.out = 50), correction = "rs",
    sample_id = "patient_id",
    image_id = "image_number", condition = "patient_stage",
    ncores = 1,
    algorithm = "bam"
)
}
