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 class 'exponential'
sprnorm(
  spcov_params,
  mean = 0,
  samples = 1,
  data,
  randcov_params,
  partition_factor,
  xcoord,
  ycoord,
  ...
)

# S3 method for class 'none'
sprnorm(
  spcov_params,
  mean = 0,
  samples = 1,
  data,
  randcov_params,
  partition_factor,
  ...
)

# S3 method for class 'ie'
sprnorm(
  spcov_params,
  mean = 0,
  samples = 1,
  data,
  randcov_params,
  partition_factor,
  ...
)

# S3 method for class '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. It is nearly the sample computational cost to call sprnorm() for any value of samples.

Only methods for the exponential 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 ie, 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.8139174  0.9094314 -1.7959732 -1.1581424 -0.7005365  0.6686048
#>  [7]  0.7050056 -0.4637456  0.9577332 -3.2036226  0.6357254  0.6500256
#> [13]  1.5285053  0.4743305 -2.3021599 -2.7895186 -0.7618093 -1.1851421
#> [19] -2.2085949 -2.2747279  0.5146615 -0.4055081  0.6200553 -1.2327053
#> [25]  0.8418224  0.3255716  1.0886699 -0.2252117 -1.5002841 -1.9571047
sprnorm(spcov_params_val, mean = 1:30, samples = 5, data = caribou, xcoord = x, ycoord = y)
#>             [,1]       [,2]      [,3]      [,4]        [,5]
#>  [1,] -0.2748755  0.1155318  2.347206  1.523679  0.09983275
#>  [2,]  0.8339078  1.1602295  4.195714  1.126313  3.61504371
#>  [3,]  3.5516497  2.0490162  2.419144  1.840225  3.36146585
#>  [4,]  4.4652743  2.4588213  4.747257  1.781319  3.54264261
#>  [5,]  5.2670731  3.6012551  6.960675  3.774978  4.31109660
#>  [6,]  8.3918665  4.9054873  4.935751  6.553229  8.34548881
#>  [7,]  7.7516281  5.8793538  6.509240  8.297281  6.93509254
#>  [8,]  8.2579335  7.0857589 12.017417  8.156199  7.97917804
#>  [9,]  8.4140449  8.3653240  9.955293  8.000257  8.16759616
#> [10,]  8.9199222 10.8568737  9.543874 10.671944  9.04492476
#> [11,]  9.7878845  8.7260293 12.795844 13.558241 11.66088375
#> [12,] 13.5503803 11.2075416 10.440449 12.939143 13.68747947
#> [13,] 10.9929982 11.7472477 13.506709 13.056158 13.15485404
#> [14,] 12.7417254 14.8911874 15.050980 14.904826 14.61448637
#> [15,] 14.4580950 14.7040191 12.409566 14.315579 14.81673809
#> [16,] 13.6817421 17.2158771 18.168880 16.965996 15.68117644
#> [17,] 16.5934293 16.8951988 18.578171 17.286128 15.85103380
#> [18,] 18.0421202 19.2696604 16.584094 15.923414 19.80385913
#> [19,] 18.0583333 21.7512918 20.009333 17.689520 20.88655095
#> [20,] 19.9703920 21.3173426 21.080595 19.709029 19.81634252
#> [21,] 19.4810692 21.2066772 19.534027 21.995145 21.34389890
#> [22,] 21.6401066 21.4965973 25.600925 20.915390 21.56624424
#> [23,] 24.1746662 23.2880136 24.831344 21.114132 24.13225753
#> [24,] 25.4777620 24.3944133 26.733684 25.568400 26.05442398
#> [25,] 26.5884388 23.8327401 24.708696 23.438435 26.92647113
#> [26,] 25.0321208 26.2344102 26.142207 25.954725 27.34575182
#> [27,] 25.6402016 28.7084961 30.175747 26.445106 27.67336513
#> [28,] 28.5907631 29.7967426 30.434292 27.239459 28.40566741
#> [29,] 31.1786845 30.5039825 32.851905 29.249651 30.15184131
#> [30,] 33.8788844 28.4681690 32.588354 28.592910 28.81678983