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.510411907 0.216687188 0.339423878 0.685460362 3.203941701 0.312372277
#> [7] 2.008159055 1.153974566 1.526568718 0.103496511 0.891348655 0.218556010
#> [13] 1.746941178 0.007939202 1.685905518 0.703021272 0.723945600 4.516500190
#> [19] 1.560117256 0.054229802 1.128638418 0.233101963 0.060428670 0.765190662
#> [25] 0.230996700 0.273053588 0.463020978 0.172830310 0.022783997 0.115735038
sprgamma(spcov_params_val, samples = 5, data = caribou, xcoord = x, ycoord = y)
#> 1 2 3 4 5
#> [1,] 4.290836646 1.930259580 0.25760416 1.167262345 0.658087251
#> [2,] 3.022096792 3.599486978 0.17773316 0.796177516 0.174301060
#> [3,] 0.592641615 2.793868902 0.43057248 1.033769485 0.362928272
#> [4,] 0.328659419 0.569682539 2.24516406 9.682701289 1.404646459
#> [5,] 0.613510460 0.019924987 4.14572923 3.018015816 0.211315977
#> [6,] 3.692436722 0.427353284 0.17363166 2.324727617 0.242961094
#> [7,] 0.624537244 0.709482765 2.82839984 0.091491210 0.708267046
#> [8,] 1.729559308 2.062554648 0.05025101 0.343050320 0.006669871
#> [9,] 1.143686230 4.543377100 0.11063094 0.337678457 1.433344909
#> [10,] 1.160760768 0.063935208 0.54919369 1.334105968 0.879376004
#> [11,] 1.002984348 0.607073019 0.51457351 3.337348326 0.980267723
#> [12,] 4.697944815 0.013843398 1.23563854 0.458568465 0.435192944
#> [13,] 3.943889808 0.399753364 0.12623833 2.979121496 1.602677157
#> [14,] 0.042708871 0.344885858 0.55804519 0.145946830 0.443454486
#> [15,] 0.355278856 0.934586399 0.67323174 0.211348150 0.142296001
#> [16,] 0.857343107 0.102786267 0.17232609 0.007123398 0.046683426
#> [17,] 0.654695454 0.003775895 0.47772747 0.363136835 0.878589791
#> [18,] 0.125345322 0.599973471 0.07276595 1.602211959 0.195474776
#> [19,] 0.806800854 0.072447206 0.26951760 0.661767323 0.722356604
#> [20,] 0.381951497 0.617485670 0.47153559 2.764380200 1.236297355
#> [21,] 0.439667649 2.474088161 0.26782295 0.469454567 2.113097465
#> [22,] 1.427577145 0.537842619 0.21217180 0.245629247 6.822413566
#> [23,] 0.701701002 2.320098273 0.30456004 0.657589697 0.310362496
#> [24,] 2.416282394 0.615452464 0.29132408 1.698303971 0.170319250
#> [25,] 0.190278358 1.872124539 0.56892635 0.238591740 0.285307363
#> [26,] 0.006422544 0.682588475 0.36993680 0.300925095 4.290694265
#> [27,] 0.715846131 0.744826310 0.32184970 0.140872426 1.000780526
#> [28,] 1.855566343 0.826402782 0.32920254 0.025438626 0.323992742
#> [29,] 2.675205644 0.621306690 1.18167854 0.407740907 0.421469754
#> [30,] 0.898803125 2.709340319 2.03877604 1.659798306 0.166220946