This vignette of package
groupedHyperframe.random (Github,
RPubs)
documents the simulation of superimposed
ppp.object and the groupedHyperframe
object.
Examples in this vignette require that the search path
has
library(groupedHyperframe.random)
#> Loading required package: spatstat.random
#> Loading required package: spatstat.data
#> Loading required package: spatstat.univar
#> spatstat.univar 3.1-2
#> Loading required package: spatstat.geom
#> spatstat.geom 3.3-6.001
#> spatstat.random 3.3-3
#> Loading required package: groupedHyperframe| Term / Abbreviation | Description | Reference |
|---|---|---|
| Forward pipe operator | ?base::pipeOp introduced in R
4.1.0 |
|
CRAN, R |
The Comprehensive R Archive Network | https://cran.r-project.org |
coords |
\(x\)- and \(y\)-coordinates | spatstat.geom:::ppp |
diag |
Diagonal matrix | base::diag |
groupedHyperframe |
Grouped hyper data frame | groupedHyperframe::as.groupedHyperframe |
hypercolumns, hyperframe |
(Hyper columns of) hyper data frame | spatstat.geom::hyperframe |
marks, marked |
(Having) mark values | spatstat.geom::is.marked |
pmax |
Parallel maxima | base::pmax |
ppp, ppp.object |
Point pattern | spatstat.geom::ppp.object |
recycle |
Recycling | https://r4ds.had.co.nz/vectors.html#scalars-and-recycling-rules |
rlnorm |
Log normal random variable | stats::rlnorm |
rMatClust |
Matern’s cluster process | spatstat.random::rMatClust |
rmvnorm_ |
Multivariate normal random variable | groupedHyperframe.random::rmvnorm_;
MASS::mvrnorm |
rnbinom |
Negative binomial random variable | stats::rnbinom |
rpoispp |
Poisson point pattern | spatstat.random::rpoispp |
superimpose |
Superimpose | spatstat.geom::superimpose |
var, cor,
cov |
Variance, correlation, covariance | stats::var, stats::cor,
stats::cov |
This work is supported by NCI R01CA222847 (I. Chervoneva, T. Zhan, and H. Rui) and R01CA253977 (H. Rui and I. Chervoneva).
Function .rppp() simulates superimposed
ppp.objects with vectorized parameterization of
random point pattern and distribution of marks.
marked Point PatternExample below simulates a coords-only,
unmarked, two superimposed Matern’s cluster
processes \((\kappa, \mu, s) =
(10,8,.15)\) and \((5,4,.06)\).
marked Point PatternExample below simulates two superimposed
marked ppps,
Matern’s cluster process \((\kappa,\mu,s) = (10,8,.15)\), attached
with a log-normal mark \((\mu,\sigma)=(3,.4)\), and a
negative-binomial mark \((r,p)=(4,.3)\).
Matern’s cluster process \((\kappa,\mu,s) = (5,4,.06)\), attached with
a log-normal mark \((\mu,\sigma)=(5,.2)\), and a
negative-binomial mark \((r,p)=(4,.3)\).
set.seed(125); r1 = .rppp(
rMatClust(kappa = c(10, 5), mu = c(8, 4), scale = c(.15, .06)),
rlnorm(meanlog = c(3, 5), sdlog = c(.4, .2)),
rnbinom(size = 4, prob = .3) # shorter parameter recycled
)
#> Point-pattern simulated by `spatstat.random::rMatClust()`
#> Marks simulated by `stats::rlnorm()`
#> Marks simulated by `stats::rnbinom()`Example below simulates two superimposed
marked ppps,
Poisson point pattern \(\lambda=3\), attached with a log-normal
mark \((\mu,\sigma)=(3,.4)\), and a
negative-binomial mark \((r,p)=(4,.3)\).
Poisson point pattern \(\lambda=6\), attached with a log-normal
mark \((\mu,\sigma)=(5,.2)\), and a
negative-binomial mark \((r,p)=(6,.1)\).
set.seed(62); r2 = .rppp(
rpoispp(lambda = c(3, 6)),
rlnorm(meanlog = c(3, 5), sdlog = c(.4, .2)),
rnbinom(size = c(4, 6), prob = c(.3, .1))
)
#> Point-pattern simulated by `spatstat.random::rpoispp()`
#> Marks simulated by `stats::rlnorm()`
#> Marks simulated by `stats::rnbinom()`In the foreseeable future we will not support simulating more than
one type of point patterns in a single call to function
.rppp(). End user may manually superimpose
different (marked) point patterns after simulating each of
them separately.
groupedHyperframeNow consider two superimposed Matern’s cluster processes
attached with a log-normal mark. The population parameters
are
(p = data.frame(kappa = c(3,2), scale = c(.4,.2), mu = c(10,5),
meanlog = c(3,5), sdlog = c(.4,.2)))
#> kappa scale mu meanlog sdlog
#> 1 3 0.4 10 3 0.4
#> 2 2 0.2 5 5 0.2We simulate for 3 subjects (e.g., patients). The subject-specific
parameters deviate from the population parameters under a multivariate
normal distribution with variance-covariance matrix \(\Sigma\). The matrix \(\Sigma\) may be specified by a
numeric scalar, indicating all-equal diagonal
variances and zero
correlations/covariances. We also make sure
that all subject-specific parameters satisfy that \(\kappa>1\), \(\mu>1\), \(s>0\) for Matern’s cluster processes,
and \(\sigma>0\) for log-normal
distribution. Each matrix of the subject-specific
parameters has the subjects on the rows, and the parameters of the
ppps to be superimposed on the columns.
set.seed(39); (p. = rmvnorm_(n = 3L, mu = p, Sigma = list(
kappa = .2^2, scale = .05^2, mu = .5^2,
meanlog = .1^2, sdlog = .01^2)) |>
within.list(expr = {
kappa = pmax(kappa, 1 + .Machine$double.eps)
mu = pmax(mu, 1 + .Machine$double.eps)
scale = pmax(scale, .Machine$double.eps)
sdlog = pmax(sdlog, .Machine$double.eps)
}))
#> $kappa
#> [,1] [,2]
#> [1,] 3.119196 1.962887
#> [2,] 2.906535 1.754151
#> [3,] 2.915672 1.914559
#>
#> $scale
#> [,1] [,2]
#> [1,] 0.3519187 0.1489174
#> [2,] 0.3947885 0.1688761
#> [3,] 0.4029897 0.2418501
#>
#> $mu
#> [,1] [,2]
#> [1,] 10.227306 5.351866
#> [2,] 10.058303 4.622515
#> [3,] 9.726093 4.727232
#>
#> $meanlog
#> [,1] [,2]
#> [1,] 2.982251 5.007964
#> [2,] 2.878996 4.976754
#> [3,] 3.034019 4.852771
#>
#> $sdlog
#> [,1] [,2]
#> [1,] 0.4055664 0.1975062
#> [2,] 0.4172841 0.2115214
#> [3,] 0.4076479 0.1970090We simulate one to four ppps (e.g., medical images) per
subject.
Function grouped_rppp() simulates a
groupedHyperframe with a ppp-hypercolumn, and
one-or-more columns of the grouping structure.
set.seed(76); (r = p. |>
with.default(expr = {
grouped_rppp(
rMatClust(kappa = kappa, scale = scale, mu = mu),
rlnorm(meanlog = meanlog, sdlog = sdlog),
n = n
)
}))
#> Grouped Hyperframe: ~g1/g2
#>
#> 9 g2 nested in
#> 3 g1
#>
#> ppp g1 g2
#> 1 (ppp) 1 1
#> 2 (ppp) 1 2
#> 3 (ppp) 2 1
#> 4 (ppp) 2 2
#> 5 (ppp) 2 3
#> 6 (ppp) 3 1
#> 7 (ppp) 3 2
#> 8 (ppp) 3 3
#> 9 (ppp) 3 4