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.10623477 1.59149291 1.13731950 0.21307711 0.37828973 0.88846623
#> [7] 0.18793081 0.06641346 1.78962365 0.31916600 0.15179867 0.40107720
#> [13] 3.50882219 0.29687175 0.97274671 0.40491748 1.08652307 5.70486656
#> [19] 0.80905153 1.92537079 0.58144841 0.60368256 1.47948978 3.37855743
#> [25] 0.69734196 0.07777519 0.58411317 0.80341697 0.09204080 0.55262488
sprgamma(spcov_params_val, samples = 5, data = caribou, xcoord = x, ycoord = y)
#> 1 2 3 4 5
#> [1,] 0.95195555 0.07018360 2.163074056 0.644591385 1.37499396
#> [2,] 3.78332861 0.02155080 2.101960692 2.772266429 1.44407593
#> [3,] 2.39148094 0.61636330 0.954995585 0.328675280 0.06649921
#> [4,] 1.52926559 1.38751202 0.172694034 0.335708082 0.11614483
#> [5,] 0.12124543 1.87696074 0.011720212 0.506388337 0.21858311
#> [6,] 0.14012202 0.43823811 0.409564448 1.269655833 0.11726717
#> [7,] 0.37814398 2.06360004 0.353248386 3.615889903 0.52050686
#> [8,] 0.25366622 1.96007225 0.532409881 0.860701880 0.64979281
#> [9,] 0.15273710 1.27324250 0.562989803 0.281462747 0.02046185
#> [10,] 0.63263649 1.24179825 0.266419255 1.738383871 0.76451091
#> [11,] 1.16520455 0.27727138 0.376316005 0.412686997 1.31095545
#> [12,] 0.71806073 1.04175619 0.042039029 2.134790458 1.06603846
#> [13,] 0.35463318 0.07503641 0.250337496 0.618703893 0.26158179
#> [14,] 0.66414622 0.56887888 0.629149675 1.346480965 0.80167808
#> [15,] 1.45034105 1.09247029 0.282949189 0.492891245 0.93670429
#> [16,] 1.44507432 0.32250085 0.701018062 2.071944167 0.86971591
#> [17,] 0.37818678 0.03480591 0.525912016 0.659680358 0.66993846
#> [18,] 9.58191052 0.14354215 4.572642570 0.182559430 1.32351949
#> [19,] 4.52398648 0.84713058 0.195575805 0.627621088 0.12448380
#> [20,] 1.65663294 0.47554319 0.002101945 1.319858811 0.13017465
#> [21,] 3.59455854 1.46979219 2.154254694 0.016229356 0.52324387
#> [22,] 0.19319304 0.28719140 1.255723795 0.187158988 0.53911365
#> [23,] 1.24856273 1.08120762 2.045063400 9.489730450 1.29614275
#> [24,] 0.29998248 0.95177264 0.841893672 0.466713350 0.30579408
#> [25,] 0.03353258 0.18990337 0.487948170 0.005429396 2.99146611
#> [26,] 1.53657734 1.48399365 1.545178807 0.766653078 2.68703562
#> [27,] 0.08261160 0.20563147 0.907412329 1.636006336 0.26081937
#> [28,] 0.57310068 2.99801318 0.521783877 1.233547929 0.73389283
#> [29,] 1.01589249 0.06370281 0.625450565 2.964508902 0.19878401
#> [30,] 0.72957443 0.33684841 0.175437648 0.187002263 0.02111357