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 car
sprnorm(
spcov_params,
mean = 0,
samples = 1,
data,
randcov_params,
partition_factor,
W,
row_st = TRUE,
M,
...
)
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.
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.
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)
sprnorm(spcov_params_val, mean = 1:30, samples = 5, data = caribou, xcoord = x, ycoord = y)
Run the code above in your browser using DataLab