library(spatstat.random)
library(RandomFieldsUtils)
library(RandomFields)

Cox spatial model vs Cox PH model

The spatial variable, as unobserved influence, effect the single RNA seq data. The cox spatial model (random effect model) could focus on estimating the statistical properties of the unoberved random influences. Especially, for the data point with positive denpendence.

Cox spatial model

Cox point process- Poisson process with a random intensity function

Driving intensity \(\Lambda(u)\) (unobserved underline the point, non-negative, right-hand side finite)

Example: Simple mixed poisson process

# generate a simple mixed poisson process with a random number lambda
#lambda with negative exponential distribution with mean 100
lambda = rexp(1, 1/100)
X = rpoispp(lambda)
plot(X)

lambda: driving intensity function rpoispp: random point pattern poisson process

Given the value \(\Lambda\), the expected number of the points of falling in a region B:

\[E[n(X \bigcap B) |\Lambda] = \Lambda|B|\]

Intensity of the mixed Poisson process

\[\lambda = E\Lambda\]

Variance of the number of the points falling in a region B:

\[varn(X \bigcap B) = (E\Lambda)|B| + (var\Lambda)|B|^2\]

However, the problem with the mixed Possion model is, it could not be ergodic. Even with the same \(\Lambda\), the realization will be different.

Spatial varing

For the spatial RNA sequence data, the spatial random as the random effect is varing. In order to generate the model, logarith of the intensity is favored. It also ensure the positive of the driving intensity.

\[ G(u) = log \Lambda(u) \]

Gaussian random field

The gaussian random fied should have the following property:

  1. \(G(u)\) has a normal distribution for each location u

  2. For each pair of location \(\mu\), \(v\), \((G(u), G(v))\) is bivariate Guassian distribution

  3. For any set of the of location, the corresponding G should have Gaussian joint distribution

LGCP: log-Gaussian Cox process

\[ \Lambda(u) = expG(u) \]

For the Guassian random field \(G(u)\)

Mean: \(\mu(u) =E G(u)\)

Covariance: \(C(u,v) = E[G(u)G(v)]-\mu(u)\mu(v)\)

Since the first and second moment in Gaussian random field is completely specified, for each Guassian random field with the same mean and covariance, the field will be identical.

Rescale the Guassian random field as random variable

\[G(u)=a(u)G_0(u)+b(u)\]

\[EG_0 = 0, C_0(u,v), a(u), b(u) as non-random function\]

\[\mu(u) =b(u)\]

\[C(u,v) = a(u)a(v)C_0(u,v)\]

We assume \(r=\mid\mid u-v\mid\mid\),

Then

\[C(u,v) = C_0(r) =\delta^2R(r/\alpha)\]

\(\alpha>0\): scale parameter

\(R(0)=1\)

\(\delta^2 >0\): variance parameter

For the default, \(R(r) = exp(-r)\), then \(C_0(r)=\delta^2exp(-r/\alpha)\)

Simulation Cox process

X = rLGCP(model = "exp", mu=4, var=0.2, scale=0.1, win=square(1))
plot(X)

PS: The randomfieldsutils package may have problem with the R studio version. Here i recommended use conda and condaforge to solve the problem. First, create a environment specific for R in anaconda. Then, in the terminal, type in conda config --add channels conda-forge conda config --set channel_priority strict. Third, in Conda environment, install the spatstat package and randomfieldutils package. Finally, load R in the anaconda and run the code.