Simulate a spatial normal (Gaussian) random variable with a specific mean and covariance structure.
Usage
sprnorm(
spcov_params,
mean = 0,
samples = 1,
data,
randcov_params,
partition_factor,
...
)
# S3 method for exponential
sprnorm(
spcov_params,
mean = 0,
samples = 1,
data,
randcov_params,
partition_factor,
xcoord,
ycoord,
...
)
# S3 method for none
sprnorm(
spcov_params,
mean = 0,
samples = 1,
data,
randcov_params,
partition_factor,
...
)
# S3 method for car
sprnorm(
spcov_params,
mean = 0,
samples = 1,
data,
randcov_params,
partition_factor,
W,
row_st = TRUE,
M,
...
)
Arguments
- spcov_params
An
spcov_params()
object.- 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.
- ...
Other arguments. Not used (needed for generic consistency).
- xcoord
Name of the column in
data
representing the x-coordinate. Can be quoted or unquoted. Not required ifdata
are ansf
object.- ycoord
Name of the column in
data
representing the y-coordinate. Can be quoted or unquoted. Not required ifdata
are ansf
object.- W
Weight matrix specifying the neighboring structure used for car and sar models. Not required if
data
are ansf
polygon object andW
should be calculated internally (using queen contiguity).- row_st
A logical indicating whether row standardization be performed on
W
. The default isTRUE
.- M
M matrix satisfying the car symmetry condition. The car symmetry condition states that \((I - range * W)^{-1}M\) is symmetric, where \(I\) is an identity matrix, \(range\) is a constant that controls the spatial dependence,
W
is the weights matrix, and \(^{-1}\) represents the inverse operator.M
is required for car models whenW
is provided androw_st
isFALSE
. WhenM
, is required, the default is the identity matrix.
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
Random variables are simulated via the product of the covariance matrix's
square (Cholesky) root and independent standard normal random variables
with mean 0 and variance 1. Computing the square root is a significant
computational burden and likely unfeasible for sample sizes much past 10,000.
Because this square root only needs to be computed once, however, it is
nearly the sample computational cost to call sprnorm()
for any value
of samples
.
Only methods for the exponential
, none
, and car
covariance functions are documented here,
but methods exist for all other spatial covariance functions defined in
spcov_initial()
. Syntax for the exponential
method is the same
as syntax for spherical
, gaussian
, triangular
,
circular
, cubic
, pentaspherical
, cosine
, wave
,
jbessel
, gravity
, rquad
, magnetic
, matern
,
cauchy
, and pexponential
methods. Syntax for
the car
method is the same as syntax for the sar
method. The
extra
parameter for car and sar models is ignored when all observations have
neighbors.
Examples
spcov_params_val <- spcov_params("exponential", de = 1, ie = 1, range = 1)
sprnorm(spcov_params_val, data = caribou, xcoord = x, ycoord = y)
#> [1] -1.46335302 -1.67885804 -1.65346027 0.57419791 -1.71488231 -0.99952975
#> [7] -0.17636994 -0.56767256 1.21629099 0.82876680 -1.64805834 -0.97063157
#> [13] 1.51858670 -0.36598527 -1.10465784 0.47162421 -1.10349493 -1.33105042
#> [19] -0.57589162 -1.96273381 1.65453953 -1.64531826 -0.36546472 -1.94609042
#> [25] 0.63737887 0.63223158 1.83344455 -1.26007555 0.79220665 -0.04373597
sprnorm(spcov_params_val, mean = 1:30, samples = 5, data = caribou, xcoord = x, ycoord = y)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1.162601 0.6524519 1.15964269 2.260801 1.2493025
#> [2,] 4.231140 4.0444025 0.61172899 2.335092 0.3795448
#> [3,] 5.142157 2.2747252 0.06820083 2.100900 3.9941623
#> [4,] 3.331826 4.0683648 1.26224251 7.047277 5.5967905
#> [5,] 5.129745 4.1858451 7.00068119 4.261089 7.4343191
#> [6,] 5.535428 4.7524446 6.69430118 5.426775 9.4496373
#> [7,] 8.252122 5.0688144 8.20173667 6.541140 5.0989592
#> [8,] 9.624927 6.6915964 9.96317945 9.334000 7.4940617
#> [9,] 8.066904 6.6400277 7.85387662 13.479139 8.7897667
#> [10,] 11.831996 9.3389975 12.17666140 10.315021 11.6506274
#> [11,] 9.627038 11.7566068 11.73301650 9.189824 11.0234301
#> [12,] 12.216187 11.3535320 13.01272900 12.689285 14.4063274
#> [13,] 11.915653 12.7924222 13.22892414 12.465453 12.8885760
#> [14,] 16.113003 14.0057950 11.89293959 14.701471 12.2622039
#> [15,] 15.078023 15.7630446 15.09341871 16.443105 14.0116676
#> [16,] 15.388801 17.0895570 14.91557362 15.654539 17.0347396
#> [17,] 17.795969 17.7051606 17.02292795 18.049383 18.6027549
#> [18,] 18.879535 19.8872036 16.67693899 18.056383 21.8215325
#> [19,] 18.968464 19.8050288 18.31727331 19.084633 19.4351137
#> [20,] 21.708373 19.4010558 19.66322639 20.897677 20.2946701
#> [21,] 22.838082 22.4761944 21.27505547 21.738802 21.2887948
#> [22,] 21.220251 22.3814489 19.21876303 21.527416 22.7434834
#> [23,] 23.867438 24.9695166 24.13012213 24.747038 23.8877163
#> [24,] 24.107590 22.9326596 23.11405541 25.465577 24.1312394
#> [25,] 22.677036 28.0959129 22.54509916 26.343039 26.5194153
#> [26,] 26.242764 25.9375405 25.39963814 28.656080 24.0358104
#> [27,] 28.027058 27.5428299 25.74227458 26.724940 28.9734259
#> [28,] 28.670234 28.8566194 27.39628401 27.414541 29.0167917
#> [29,] 30.173791 31.2559216 27.61800253 29.247356 31.0248711
#> [30,] 26.912934 26.9040841 28.90906919 30.850065 31.7753734