Simulate a spatial normal (Gaussian) random variable with a specific mean and covariance structure.
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 ie
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,
...
)
An spcov_params()
object.
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 in data
. The default is 0
.
The number of independent samples to generate. The default
is 1
.
A data frame or sf
object containing spatial information.
A randcov_params()
object.
A formula indicating the partition factor.
Other arguments. Not used (needed for generic consistency).
Name of the column in data
representing the x-coordinate.
Can be quoted or unquoted. Not required if data
are an sf
object.
Name of the column in data
representing the y-coordinate.
Can be quoted or unquoted. Not required if data
are an sf
object.
Weight matrix specifying the neighboring structure used for car and
sar models. Not required if data
are an sf
polygon object and W
should be calculated internally (using queen contiguity).
A logical indicating whether row standardization be performed on
W
. The default is TRUE
.
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
when W
is provided and row_st
is FALSE
. When M
,
is required, the default is the identity matrix.
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.
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.
spcov_params_val <- spcov_params("exponential", de = 1, ie = 1, range = 1)
sprnorm(spcov_params_val, data = caribou, xcoord = x, ycoord = y)
#> [1] 0.7295330 -0.1464557 -0.6440707 0.6846085 -1.0265109 1.0855714
#> [7] 0.4864720 -0.6086310 -0.6648226 1.2126239 1.1669871 1.3339350
#> [13] 0.5193776 1.3132474 -0.2588738 0.7270756 -0.2675173 2.4908294
#> [19] 1.1697255 -0.4819587 0.1402007 -0.6007224 2.6260628 2.3593206
#> [25] -1.2412009 -0.3532930 -2.0020151 0.3291695 -1.1167337 0.5067219
sprnorm(spcov_params_val, mean = 1:30, samples = 5, data = caribou, xcoord = x, ycoord = y)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 2.6826043 0.03645854 0.5418698 -0.9583461 -0.9407780
#> [2,] -0.3475714 1.07867458 2.8647890 1.2259798 0.2757822
#> [3,] 1.4192099 3.57972869 1.8585750 3.8140107 1.5220003
#> [4,] 5.7859837 6.46258424 2.0783939 3.6029321 2.3611136
#> [5,] 4.8314165 7.28339629 5.2239981 4.1732668 4.8750043
#> [6,] 3.9052040 5.02831125 4.9407409 5.2405835 7.1770119
#> [7,] 4.0811976 8.62503780 6.2341917 7.5103071 5.2324641
#> [8,] 7.6099946 7.38567557 8.1745419 8.0192062 7.1591082
#> [9,] 9.6443881 8.93477189 9.9143297 7.2800348 8.0556939
#> [10,] 11.1737062 10.54551342 9.5474115 9.4969713 10.4015801
#> [11,] 10.6457242 12.91474090 10.5644616 10.0171602 10.3333953
#> [12,] 10.9550519 11.30757591 12.4383081 11.2161272 12.2723014
#> [13,] 14.7887060 12.89027226 14.4906696 13.4813033 13.3166775
#> [14,] 12.2561885 12.81773362 15.4710743 12.5490735 14.0731488
#> [15,] 13.6222303 14.41096493 13.3685912 12.4559545 13.4177200
#> [16,] 15.5565348 15.28052745 16.7505130 15.7552921 16.7151686
#> [17,] 15.9511689 18.18521355 17.1905893 16.2667766 16.2584423
#> [18,] 18.5378461 17.70817096 18.7072022 20.3020913 18.3316137
#> [19,] 19.4339331 17.23963728 18.9809522 19.4549497 18.7934473
#> [20,] 19.0473645 20.16644781 20.6129162 20.5602634 19.9818491
#> [21,] 21.5359177 22.25259498 20.1363655 20.6932762 20.3953194
#> [22,] 21.3121090 22.64364461 21.9117288 21.5527441 20.9678691
#> [23,] 24.3641973 21.91184919 25.8638034 23.3035162 24.2698395
#> [24,] 23.4176948 22.74474825 26.0934353 24.5857354 24.6562789
#> [25,] 22.3106568 24.03093980 23.8808282 24.0220256 25.8209420
#> [26,] 24.6157656 27.58248741 23.7597144 26.4362438 26.5329806
#> [27,] 24.7461919 28.53420016 27.8781392 27.5560128 25.3986703
#> [28,] 29.2483577 26.81614702 29.8974594 29.0680694 28.8898464
#> [29,] 28.5834952 28.22743999 28.6159507 29.8020352 27.9987930
#> [30,] 30.8567576 30.57729558 27.5115180 31.2970567 30.3425222