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.33981695 2.37173620 4.03226225 1.69995669 0.36124087 1.27329275
#> [7] 0.07712826 0.45577459 3.35596721 1.37833838 0.32529319 1.02826305
#> [13] 2.40537108 0.57451777 5.70839408 3.77163655 0.42718333 0.96604666
#> [19] 1.32251107 1.83645059 2.48608936 2.24490832 1.00580609 0.77037649
#> [25] 1.33240476 7.12251522 1.39576611 1.82790556 0.26688084 0.17034332
sprinvgauss(spcov_params_val, samples = 5, data = caribou, xcoord = x, ycoord = y)
#> 1 2 3 4 5
#> [1,] 0.64081845 0.63622539 0.3770099 0.05783596 1.1724016
#> [2,] 0.20428337 0.14446792 0.4815875 1.80568339 0.7478716
#> [3,] 0.52303099 0.42886369 2.2230104 0.39342022 6.1912100
#> [4,] 0.70163523 0.39202138 0.3262380 0.44955581 1.8943433
#> [5,] 1.30241001 0.80002821 6.1426952 1.45056443 0.1050080
#> [6,] 0.41483106 1.74783585 1.2036769 1.38195926 1.7943408
#> [7,] 0.16910352 0.59192143 0.2799052 4.65331629 0.9928443
#> [8,] 0.70377242 0.60511817 1.7411992 0.66992997 2.1234973
#> [9,] 0.85548522 1.35382692 2.7630847 2.28911150 1.1980443
#> [10,] 1.13149516 0.93499788 0.1495665 0.29073807 0.1384345
#> [11,] 1.05394678 0.21546480 0.7151537 1.57627520 1.0224662
#> [12,] 1.41957910 0.42856851 0.1555528 7.92066973 0.8567975
#> [13,] 1.15515878 2.82969188 2.2594092 3.23925713 1.1538443
#> [14,] 2.10312008 2.12431867 0.1497573 0.46634134 0.7128764
#> [15,] 0.44124602 2.46739760 4.9943807 3.15296031 0.5158310
#> [16,] 0.18129605 1.72124223 0.9079781 5.70085400 0.2425942
#> [17,] 0.89939225 0.54932237 2.3239886 1.08059698 0.8512440
#> [18,] 0.15806389 3.35196047 1.1990384 0.57089640 1.5259846
#> [19,] 0.54972554 1.58450988 0.3125771 5.70337188 1.0188017
#> [20,] 0.87900550 0.42707021 0.9372119 0.51609450 0.1060621
#> [21,] 0.72481126 1.12034732 1.4016846 1.10830422 0.4057523
#> [22,] 1.70243729 0.27322791 0.7308345 0.24970596 0.4527398
#> [23,] 0.45459289 0.08909499 0.3784597 1.39716890 0.2830682
#> [24,] 0.50944306 1.14851893 0.4160466 0.44119398 0.1777623
#> [25,] 2.56349905 0.55700467 0.5981317 0.45131414 1.4032689
#> [26,] 0.73336612 0.24870992 0.4966467 0.65965170 0.6134144
#> [27,] 1.07902941 0.10035354 0.5146971 0.25800039 0.7738898
#> [28,] 0.09814205 0.93274980 0.6105824 5.48134050 0.6887984
#> [29,] 0.38468192 0.53736423 0.2016769 0.89378085 2.3384563
#> [30,] 2.96570189 0.80828413 0.3163915 4.79946757 0.6409281