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.0285442108 0.8116683198 0.9147324371 0.5456257474 0.3375298421
#> [6] 0.4043044309 0.8924363730 1.4448388514 0.5749349446 0.0878026882
#> [11] 0.5865039588 0.8182113316 1.2193856825 0.0741654338 1.0288955134
#> [16] 0.0008694274 0.6961455813 1.9475897653 0.3869756937 0.5847413204
#> [21] 0.0618529222 0.0948261740 0.7899274408 0.3854774688 6.3847823343
#> [26] 0.1653487092 0.2088346121 0.0401002964 0.5500307267 1.0628465843
sprgamma(spcov_params_val, samples = 5, data = caribou, xcoord = x, ycoord = y)
#> 1 2 3 4 5
#> [1,] 0.84211464 0.83830369 0.02471669 0.591876748 0.05817636
#> [2,] 0.41952155 1.31863863 3.79498069 0.071977125 0.85133017
#> [3,] 0.26689203 0.35033386 0.42086110 0.097805015 8.73352180
#> [4,] 0.28456795 0.74409994 0.34847552 1.518367165 0.14632379
#> [5,] 0.43910877 0.33673182 0.36700629 1.186525102 2.75316000
#> [6,] 0.70010382 1.74375764 0.33254780 2.301870453 1.20299565
#> [7,] 0.35932453 0.09054825 0.12478477 0.910851426 0.20550786
#> [8,] 0.55235995 0.22341262 0.75497733 0.331073648 1.03573765
#> [9,] 0.70695847 0.96958469 0.70367856 0.295940137 2.44892054
#> [10,] 1.04144420 0.37570299 0.38882288 0.009845469 0.02457492
#> [11,] 0.12591267 1.15455444 1.29789705 1.650778591 0.22141108
#> [12,] 0.80755966 0.53534749 0.03471475 0.324377878 6.18371489
#> [13,] 0.55425540 0.35856644 1.39889735 0.023811200 0.02161091
#> [14,] 0.81478966 0.14825766 0.59374547 0.911763031 0.77150338
#> [15,] 0.01911476 0.23247653 0.68363623 1.003214185 0.89459654
#> [16,] 0.32113338 0.19877059 0.61010483 2.717176206 1.96874373
#> [17,] 0.10361653 0.59065455 0.35210511 0.572906355 1.45538102
#> [18,] 0.38582529 1.80163603 0.75298879 1.986402741 0.15722106
#> [19,] 1.12134795 0.36377508 0.89414282 0.772050022 0.17422473
#> [20,] 1.18353348 0.31812705 0.46114219 0.733493912 0.17647938
#> [21,] 0.66439767 1.75796859 1.00678694 6.125246134 1.85291246
#> [22,] 3.15799641 0.47598986 0.33524006 0.196230613 0.12063750
#> [23,] 1.17089715 0.11490296 1.91916130 0.322843802 2.11988452
#> [24,] 0.77163635 0.95054364 0.42248372 0.281801429 0.32713411
#> [25,] 0.53356549 1.23978411 0.09088973 1.244007707 0.35530465
#> [26,] 0.59078348 0.18116070 1.61536324 0.208012996 0.19218388
#> [27,] 0.29287266 0.05431986 0.18449712 0.603014210 2.11098854
#> [28,] 0.05873685 0.88746004 0.93157260 2.239052041 3.69894335
#> [29,] 0.08312037 1.62661240 0.48852289 0.454138182 0.96652199
#> [30,] 0.21841420 0.64632512 0.30211786 0.520776205 0.08302397