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] 1.36169322 0.70176158 0.11085374 0.19902637 1.38575003 1.08003713
#> [7] 0.50588835 3.12294138 0.56903055 0.24403798 3.08404827 6.07676214
#> [13] 0.37097471 0.87651747 1.05804970 0.35871580 0.19295990 3.58802950
#> [19] 0.97432670 0.44108731 1.64333540 0.53914936 4.35831855 1.38866946
#> [25] 0.19242884 0.71853667 2.98070481 0.33956468 0.21261274 0.03733033
sprgamma(spcov_params_val, samples = 5, data = caribou, xcoord = x, ycoord = y)
#> 1 2 3 4 5
#> [1,] 1.65960149 0.06859476 0.63206876 0.91860882 2.17900892
#> [2,] 1.16544083 0.45232992 2.64953162 0.43181296 6.79229005
#> [3,] 0.69982103 0.34714763 0.88728603 10.79459398 0.10874263
#> [4,] 0.85177148 0.19833268 0.94058248 0.51213187 0.12047310
#> [5,] 1.19372988 1.89261324 0.66739880 0.22876843 0.62839535
#> [6,] 0.40213711 1.47340586 0.29800680 0.29114546 0.74378419
#> [7,] 0.08992688 0.47748523 0.58979506 1.51029704 0.47626262
#> [8,] 0.04212040 0.09114111 1.57222946 0.55941031 0.25240568
#> [9,] 0.93463310 1.42131746 2.92909930 1.44856954 1.01526684
#> [10,] 1.42562641 0.77996857 1.59364101 0.09833515 1.61272155
#> [11,] 0.11525274 0.75778400 0.20871735 1.34145626 0.74160239
#> [12,] 0.37142467 0.14619573 0.35712169 0.85521718 2.41508926
#> [13,] 0.13790102 2.02314068 3.22712591 0.18242588 0.25491548
#> [14,] 0.93454760 0.61458333 0.76842899 0.33845787 0.44094035
#> [15,] 0.91726401 11.65350493 0.10909168 0.23128564 0.18093767
#> [16,] 0.20886922 2.00042668 0.55837310 0.88162639 0.96286667
#> [17,] 0.05663288 0.80527901 0.02177123 0.25396722 0.07757135
#> [18,] 0.48880116 2.52963134 0.90013776 0.20161640 1.08933549
#> [19,] 0.45990148 2.40294352 0.68716639 0.32127837 1.66839052
#> [20,] 1.48489451 2.58231885 3.04624828 0.42115744 0.19894999
#> [21,] 0.75789719 0.07048620 0.55764007 0.40127587 3.09175631
#> [22,] 0.60491713 0.77157153 0.39810478 0.68907420 1.18563417
#> [23,] 0.80301554 0.59316645 0.54667718 0.25510524 0.92593693
#> [24,] 0.05086169 0.33792585 1.73055432 0.32773326 1.04465020
#> [25,] 0.62566255 0.23824178 0.39058477 1.87306660 2.11030832
#> [26,] 0.43430739 1.76127128 0.04652649 0.75268568 0.38475621
#> [27,] 0.30325790 3.87528687 0.12625823 0.71888510 0.74735895
#> [28,] 0.80836076 0.02207119 6.90324794 0.13444120 0.13624736
#> [29,] 0.73392238 0.40521513 0.87362080 0.74365464 0.48307691
#> [30,] 0.14406440 0.26472290 0.69967431 0.32042970 0.38251750