Skip to contents

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 in data. The default is 0.

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 if data are an sf object.

ycoord

Name of the column in data representing the y-coordinate. Can be quoted or unquoted. Not required if data are an sf object.

W

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).

row_st

A logical indicating whether row standardization be performed on W. The default is TRUE.

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 when W is provided and row_st is FALSE. When M, 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.23349423  2.12575784  0.98817290 -1.78892120 -1.28678320 -0.63362264
#>  [7] -0.82059580  2.37982075  0.46615743  2.82006260  0.17180381 -0.87118299
#> [13] -1.69682481  1.27065415  1.88133665  1.68000680 -0.01153944 -1.73281688
#> [19] -1.10583271 -1.09570753  0.82339135  1.61871390 -0.19397140 -1.10240843
#> [25] -0.55185459  1.03933008  0.09506606 -1.03082715 -2.24406182 -2.59429104
sprnorm(spcov_params_val, mean = 1:30, samples = 5, data = caribou, xcoord = x, ycoord = y)
#>            [,1]       [,2]      [,3]      [,4]       [,5]
#>  [1,]  1.528083  0.7703245  1.722417  2.429180 -0.6652816
#>  [2,]  1.799518  1.0150236  3.968203  3.813322  1.3440317
#>  [3,]  2.678239  1.0913940  2.213606  3.428126  4.0833516
#>  [4,]  2.865541  2.0443124  5.112626  2.856614  3.1451557
#>  [5,]  2.517346  5.3680605  5.544207  5.702143  6.5841828
#>  [6,]  7.231810  5.6476596  6.090334  7.002619  3.8896299
#>  [7,]  7.238252  8.4750326  6.391873  7.376044  8.7161865
#>  [8,]  7.365753  6.7724488  5.653785  6.486235  5.7240857
#>  [9,]  7.854739  8.7908037  8.293750  9.046280  8.6750041
#> [10,] 11.420877  8.1292646  9.133496 12.753457 12.1230740
#> [11,] 10.074353 10.3532001  9.457402 10.523221  8.9749191
#> [12,] 10.753295 11.9407482  9.849835 12.563811 11.8429336
#> [13,] 11.184922 14.2850012 14.174044 11.772692 13.0241812
#> [14,] 11.744046 14.8355656 11.754424 14.101684 15.1884856
#> [15,] 14.477492 14.2241853 14.998525 16.305557 15.5878442
#> [16,] 15.542840 13.9935528 14.735531 17.970287 15.9918663
#> [17,] 14.485220 18.9555527 16.431921 16.798546 16.7995965
#> [18,] 18.028339 17.6749548 18.208921 18.473442 17.6009399
#> [19,] 21.534036 20.3600206 18.891205 20.838431 18.9532774
#> [20,] 20.972658 21.6627229 20.591763 21.882818 19.7179787
#> [21,] 19.442234 22.0256617 21.443533 20.615684 22.0036001
#> [22,] 22.150830 21.4046788 22.287592 19.364185 19.2283562
#> [23,] 23.637628 23.2833634 22.493463 20.829445 22.2427017
#> [24,] 25.140054 25.0016260 23.356456 24.835558 25.2346133
#> [25,] 25.012462 26.8574702 27.689026 24.826478 24.0999552
#> [26,] 27.994622 26.9697075 27.823406 23.080754 24.5108520
#> [27,] 28.250463 26.7327525 26.546732 24.964274 24.8147699
#> [28,] 27.666385 27.0834780 28.936417 31.506135 26.7133213
#> [29,] 28.469509 30.1375615 29.534090 30.659416 28.2522673
#> [30,] 30.760192 31.7687738 31.264848 30.938891 29.1911678