Simulate a spatial inverse gaussian random variable with a specific mean and covariance structure.
Usage
sprinvgauss(
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 inverse gaussian random variable.
Examples
spcov_params_val <- spcov_params("exponential", de = 0.2, ie = 0.1, range = 1)
sprinvgauss(spcov_params_val, data = caribou, xcoord = x, ycoord = y)
#> [1] 0.93765746 3.98266643 2.02968859 0.59686000 2.67867151 0.87732468
#> [7] 1.84291355 1.08779306 0.86999820 0.91615753 0.52931862 2.48748700
#> [13] 0.83966447 0.37002801 0.14097100 3.84501369 0.83374874 0.77604715
#> [19] 1.51638899 0.25034590 0.88939898 0.20831784 0.28739573 0.32681188
#> [25] 1.44646172 1.76112545 1.44545472 0.07328899 2.73702022 0.25302424
sprinvgauss(spcov_params_val, samples = 5, data = caribou, xcoord = x, ycoord = y)
#> 1 2 3 4 5
#> [1,] 0.1314888 1.33433196 0.3257362 0.6457639 0.56093136
#> [2,] 0.4093405 4.06829187 0.3940007 0.1065674 1.04490540
#> [3,] 0.8613436 0.17350110 0.6592941 0.2866657 1.75412265
#> [4,] 0.3255167 0.49058531 0.2539201 0.9282905 0.34824172
#> [5,] 0.2645718 1.82211141 3.8051048 0.5300899 0.12044805
#> [6,] 0.9035842 0.61460740 0.3937090 0.4952954 2.42794553
#> [7,] 0.2525350 0.40022835 3.3091112 0.7896956 0.72172301
#> [8,] 0.8548532 0.35501021 0.1497729 0.5013747 0.37790383
#> [9,] 1.3626610 0.23429299 0.1877900 0.9154179 2.73765065
#> [10,] 1.3999854 2.44476120 0.5661267 1.8273325 0.44643809
#> [11,] 0.5688829 1.04793153 0.2595232 0.4093794 0.59399384
#> [12,] 3.4695388 1.52350840 0.4701457 0.2509119 1.03739491
#> [13,] 1.6591417 0.19160901 0.5507933 0.5215502 0.54172518
#> [14,] 0.1684614 0.51981920 0.7530004 2.7474924 0.07573577
#> [15,] 6.4907673 0.45589271 0.7628898 0.1124657 0.31139528
#> [16,] 1.9325893 0.11766855 1.3141893 0.7622294 0.75802188
#> [17,] 5.8039796 0.13051741 0.7522042 0.3349398 1.38073930
#> [18,] 0.4895292 0.77930088 0.7367621 0.2309022 0.77156389
#> [19,] 0.5243327 2.96422831 1.7338909 0.6432435 2.47814083
#> [20,] 1.9615885 1.28831324 0.1392915 0.2560085 1.20013761
#> [21,] 1.8971246 0.24380640 0.5810944 0.1209071 1.52290794
#> [22,] 0.3412804 0.04471571 0.5334054 4.3372778 2.86377395
#> [23,] 1.2378118 0.22844877 1.8871396 0.0847234 0.48181047
#> [24,] 0.9144702 0.70792200 0.3028902 0.6751944 1.42047378
#> [25,] 0.5339361 0.12771128 0.7177573 1.5305458 2.42820479
#> [26,] 0.3053116 0.89100489 1.5825647 2.0163288 0.57373494
#> [27,] 0.4991243 0.06426802 0.6582163 1.4278142 0.17119731
#> [28,] 2.4038829 0.29843824 1.6697316 0.8365624 0.84153739
#> [29,] 0.9588386 0.32909906 2.0196280 0.3036074 0.30972041
#> [30,] 3.5012008 0.51382171 3.3448462 0.3740686 3.87049560