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]  1.26473004 -0.08800188 -0.10217510  1.08396139 -2.70095266 -0.11782871
#>  [7] -0.57106378 -1.13102477 -0.03294818 -2.29589077  1.10147275  0.25052409
#> [13]  2.30163634  1.32050582 -1.29947603 -0.42783143  0.95707449 -0.05388136
#> [19] -1.44396247 -3.86578250 -1.49293065  0.21153028 -0.35608687  1.36644210
#> [25]  0.58239536 -0.05377436 -0.35717792 -0.22176421 -1.40507795  0.50159209
sprnorm(spcov_params_val, mean = 1:30, samples = 5, data = caribou, xcoord = x, ycoord = y)
#>             [,1]       [,2]      [,3]       [,4]      [,5]
#>  [1,] -2.0363727  2.9745357  2.015543  1.5698743  1.556115
#>  [2,]  0.1698875  0.4667801  1.948098  0.3800091  1.854540
#>  [3,]  3.2010668  2.9950526  4.328555  1.0568804  2.446079
#>  [4,]  4.4132496  3.4424347  5.534134  3.0903143  5.257416
#>  [5,]  3.6075334  5.1132421  5.556027  5.4022159  4.755699
#>  [6,]  6.4124912  4.8203979  6.404785  7.3421055  7.244071
#>  [7,]  5.5443592  7.4900737  5.154365  6.9316569  9.213593
#>  [8,]  9.3870780  5.6368196  4.244686  6.6196488  9.474234
#>  [9,] 10.2466086  8.6628491  9.932354  7.7334614  9.910769
#> [10,]  8.5294522  9.7918048 13.115985 10.2285386 11.600444
#> [11,] 12.8322104 10.8437649 10.775110 10.9705245 12.669231
#> [12,] 10.7045256 12.4593012 12.601743 11.4322129 11.951369
#> [13,] 14.8240284 12.7019872 12.883681 13.5571062 13.253777
#> [14,] 14.7468337 12.7119091 12.800901 14.4753149 15.306393
#> [15,] 14.6744087 13.0411175 14.576579 13.6504610 12.699546
#> [16,] 16.2937059 18.0011121 14.854845 16.8945606 16.852934
#> [17,] 14.4779436 17.2874912 19.967454 17.6259736 18.427422
#> [18,] 16.4492827 15.3025666 20.184688 20.1783726 19.979044
#> [19,] 20.5857468 19.9303664 18.557557 17.1133183 22.915288
#> [20,] 20.9208273 20.1941760 21.145562 19.2744982 21.093721
#> [21,] 20.4281936 23.6160132 21.599650 21.6326348 19.703092
#> [22,] 21.3906805 23.0085891 23.245905 22.6155262 22.814409
#> [23,] 22.8140945 22.6360048 21.722885 22.2080033 23.227607
#> [24,] 22.9728191 23.9674022 25.452969 23.3047686 28.132045
#> [25,] 25.9300677 24.2642939 25.220210 25.7851270 27.607540
#> [26,] 25.2751130 27.3600400 25.246540 23.8088324 25.425311
#> [27,] 27.0754319 28.2500633 28.804192 26.7483770 28.325790
#> [28,] 27.6079180 26.9881359 27.973944 29.0514302 28.940301
#> [29,] 29.8881122 28.8681440 29.152780 27.6163821 32.386033
#> [30,] 31.3101512 29.7750371 31.033035 27.2111172 32.357267