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] 0.24836060 -0.67946755 -2.54672984 -0.29698680 -0.25167380 1.48479435
#> [7] -0.67371545 -1.13172749 0.71488447 -0.35997943 0.09778758 -0.90708526
#> [13] -4.52677664 1.82669767 -0.85163591 1.65492173 1.77860062 -1.15679253
#> [19] 0.43599127 0.14449950 0.03472484 -2.08895286 -0.11185542 0.58235422
#> [25] -2.04138948 -0.32571389 -0.26898036 -1.09534288 -1.57882955 -0.21690907
sprnorm(spcov_params_val, mean = 1:30, samples = 5, data = caribou, xcoord = x, ycoord = y)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] -2.037976 -0.08689167 1.753807 1.811566 -1.6771136
#> [2,] 4.085087 -0.19640589 1.151105 1.634582 0.6481624
#> [3,] 4.635681 3.21287082 4.396806 1.143563 4.5670795
#> [4,] 4.953969 3.12480835 6.342408 4.352813 5.3541200
#> [5,] 5.432799 3.57559769 5.381281 6.681447 5.5604226
#> [6,] 7.179666 4.55762263 6.526624 6.878795 7.5732539
#> [7,] 8.213535 4.09741909 9.535317 5.272869 6.7066919
#> [8,] 7.696434 8.47318551 9.978071 6.860323 8.4958459
#> [9,] 9.997375 7.61099861 9.239341 8.855789 9.2701620
#> [10,] 9.065587 11.70715187 10.437296 10.858045 9.4066308
#> [11,] 11.648966 10.22644014 11.396240 10.715020 10.4685192
#> [12,] 12.062270 11.49272559 15.435126 8.241423 15.0341640
#> [13,] 12.196000 13.18814800 13.989268 12.544422 12.2306496
#> [14,] 10.504005 11.80164177 15.125990 12.691760 14.7905477
#> [15,] 11.886501 14.43027541 15.664010 15.344990 13.3371944
#> [16,] 17.842002 15.07705821 18.397104 14.145291 15.5074878
#> [17,] 18.703065 15.84783991 18.968082 15.966304 16.7605365
#> [18,] 20.426370 17.18540709 20.453927 17.164918 16.4303497
#> [19,] 19.997671 17.00909470 21.059382 18.919232 18.9073898
#> [20,] 19.389567 21.44267298 19.946676 20.634010 19.6779856
#> [21,] 23.577645 22.94123947 20.861966 19.557735 20.6004080
#> [22,] 21.618422 20.01193544 25.357496 21.666128 19.4046966
#> [23,] 23.611442 23.34995136 21.662746 24.432918 23.4388497
#> [24,] 25.982594 23.24405545 24.067474 24.711970 23.4259906
#> [25,] 25.999811 24.57149956 25.504207 25.759787 21.3481587
#> [26,] 25.105262 25.48257801 24.616494 25.058904 25.9125902
#> [27,] 25.736640 29.62433422 26.770361 29.489366 26.1146796
#> [28,] 26.878747 29.54214298 27.753899 30.424720 26.9851088
#> [29,] 29.478631 28.42427446 30.282107 27.045511 28.8611322
#> [30,] 28.445630 30.14412972 29.786879 30.009059 30.7524009