Simulate a marked point pattern from the DenMark data-generating process
Source:R/simulate.R
denmark_simulate.RdCells of the analyzed type follow an inhomogeneous Poisson process with
log lambda1(s) = beta0 + a11 w1(s), and each cell's count for gene k is
Poisson with
log mu_k(s) = beta1 + sigma2 * (rho_k w1(s) + sqrt(1 - rho_k^2) w2k(s)).
Arguments
- rho
Named vector of true correlations, one gene per element.
- width, height
Size of the window
[0, width] x [0, height].- n_cells
Number of cells of the analyzed type: the thinned point pattern is subsampled to
n_cellscells when it has more.- ell1, ell2
Length-scales of the density and expression fields.
- a11
Standard deviation of the log cell intensity.
- sigma2
Standard deviation of the log expression.
- beta1
Intercept of the log expression.
- seed
Random seed, set with
set.seed(); this resets the global random number stream.- tissue
"rectangle"(cells fill the window) or"irregular"(cells lie in a lobed tissue section).- n_other
Number of cells of other types; together with the analyzed cells they define the tissue boundary.
- celltype
Label of the analyzed cell type (used when
n_other > 0; the other cells are labeled"Other").
Value
Data frame with the columns x, y, celltype (when
n_other > 0) and one count column per gene; the true values are stored
in attr(, "truth"), including the true tissue outline for
tissue = "irregular".
Details
The fields are smooth, zero-mean, unit-variance Gaussian fields with
approximately Matern-3/2 covariance, drawn by random Fourier features. The
fields are standardized, and each w2k is orthogonalized against w1, on
a regular lattice over the tissue (that is, over space rather than over the
cells), so that the spatial correlation of the two fields equals rho_k,
which is what rho measures in the model.
With tissue = "irregular", the cells lie in a lobed tissue section inside
the window, so that the analysis needs a tissue boundary (see
denmark_alpha_shape()). The cells of other types are drawn from the
candidate locations that the thinning rejected, so they are densest where
the analyzed cells are sparse; their gene counts are Poisson with mean 0.3.
Examples
sim <- denmark_simulate(rho = c(up = 0.5, down = -0.5), n_cells = 500)
head(sim)
#> x y up down
#> 1 5.7341203 1.897406 1 1
#> 2 4.9010699 2.176218 0 2
#> 3 4.8743040 2.718039 3 0
#> 4 0.2315825 1.722756 0 4
#> 5 5.5570991 3.673129 3 3
#> 6 5.7925512 0.500681 5 5
attr(sim, "truth")$rho
#> up down
#> 0.5 -0.5
sec <- denmark_simulate(n_cells = 1000, tissue = "irregular", n_other = 800,
celltype = "Tumor")
table(sec$celltype)
#>
#> Other Tumor
#> 800 1000