Simulate a spatial gamma random variable with a specific mean and covariance structure.
Usage
sprgamma(
spcov_params,
dispersion = 1,
mean = 0,
samples = 1,
data,
randcov_params,
partition_factor,
...
)
Arguments
- spcov_params
An
spcov_params()
object.- dispersion
The dispersion value.
- mean
A numeric vector representing the mean.
mean
must have length 1 (in which case it is recycled) or length equal to the number of rows indata
. The default is0
.- samples
The number of independent samples to generate. The default is
1
.- data
A data frame or
sf
object containing spatial information.- randcov_params
A
randcov_params()
object.- partition_factor
A formula indicating the partition factor.
- ...
Additional arguments passed to
sprnorm()
.
Value
If samples
is 1, a vector of random variables for each row of data
is returned. If samples
is greater than one, a matrix of random variables
is returned, where the rows correspond to each row of data
and the columns
correspond to independent samples.
Details
The values of spcov_params
, mean
, and randcov_params
are assumed to be on the link scale. They are used to simulate a latent normal (Gaussian)
response variable using sprnorm()
. This latent variable is the
conditional mean used with dispersion
to simulate a gamma random variable.
Examples
spcov_params_val <- spcov_params("exponential", de = 0.2, ie = 0.1, range = 1)
sprgamma(spcov_params_val, data = caribou, xcoord = x, ycoord = y)
#> [1] 0.98270639 1.07797180 1.00114180 3.52250648 0.05488301 0.64124828
#> [7] 0.53919654 0.37435704 0.91751619 1.72870091 0.50983871 0.14994100
#> [13] 1.60474635 0.53674575 1.09566900 0.72692363 0.47854694 1.70170898
#> [19] 3.74593754 2.16956750 1.82205510 2.79962799 2.58488299 2.55382392
#> [25] 2.02894600 0.23520396 3.95034670 0.03308002 0.46230388 0.83211574
sprgamma(spcov_params_val, samples = 5, data = caribou, xcoord = x, ycoord = y)
#> 1 2 3 4 5
#> [1,] 0.29294778 0.246858202 0.934569052 1.04609504 1.2375493
#> [2,] 0.01592139 0.056530645 1.092646742 0.25767230 0.8191045
#> [3,] 0.12336823 0.294679512 0.682998044 0.69441865 0.4010496
#> [4,] 3.73616980 0.162591332 2.113933291 1.02415613 0.1488814
#> [5,] 0.53638417 0.071098416 1.402876587 0.28645135 0.1946186
#> [6,] 0.82942230 0.471862663 0.062689865 1.67281553 1.5536123
#> [7,] 0.11466762 2.797688497 0.884553527 1.64178697 0.2973793
#> [8,] 0.15173226 0.755664774 0.434129238 0.14027033 0.5114958
#> [9,] 0.05821510 1.206234568 1.211000414 1.25912960 2.2621710
#> [10,] 0.28157817 0.366420194 6.989335635 0.34295653 0.0613713
#> [11,] 0.28956682 0.255797696 2.537159921 0.12564588 1.5853181
#> [12,] 1.24092929 0.019886829 4.093114943 0.62296431 0.9489577
#> [13,] 0.71492202 0.311115004 0.004775145 4.16471751 2.2281085
#> [14,] 0.05475184 1.896114335 0.259166671 0.10251268 0.4224656
#> [15,] 0.75003384 0.426439612 0.217030426 0.35792017 0.2034753
#> [16,] 0.54182134 1.686953994 1.259323084 0.96228744 0.5639436
#> [17,] 0.31363135 1.263526496 0.123850084 1.55907903 0.2305360
#> [18,] 0.50067005 0.001541268 1.566068217 0.23538031 0.2102147
#> [19,] 0.04011362 0.033748237 0.735497473 0.15867990 0.9748251
#> [20,] 0.42080766 1.848467254 0.806786291 0.03270243 0.7926192
#> [21,] 0.02091180 0.411449651 0.830050106 1.05483640 1.2648370
#> [22,] 0.04585424 0.011454047 4.923010363 0.04687671 0.1553963
#> [23,] 0.45749354 0.076491680 2.842836783 0.34015594 0.5570676
#> [24,] 0.34911094 0.431970023 1.002115728 0.03295408 2.6895628
#> [25,] 0.32205601 0.193319563 0.274338704 0.20141377 0.1301718
#> [26,] 0.18119603 0.976407138 2.608057953 0.75767964 2.1965644
#> [27,] 2.90653608 0.155100764 0.806582318 1.30061520 15.5373696
#> [28,] 3.35231337 0.419025208 1.503553063 3.07332082 10.5479658
#> [29,] 0.05826492 0.277838460 0.231359553 1.44842343 5.6712965
#> [30,] 0.04453266 1.069806245 0.570394807 0.41338437 0.6849160