Skip to contents

Simulate a spatial binomial random variable with a specific mean and covariance structure.

Usage

sprbinom(
  spcov_params,
  mean = 0,
  size = 1,
  samples = 1,
  data,
  randcov_params,
  partition_factor,
  ...
)

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.

size

A numeric vector representing the sample size for each binomial trial. The default is 1, which corresponds to a Bernoulli trial for each observation.

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.

...

Additional arguments passed to sprnorm().

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

The values of spcov_params, mean, and randcov_params are assumed to be on the link scale. They are used to simulate a latent normal (Gaussian) response variable using sprnorm(). This latent variable is the conditional mean used with dispersion to simulate a binomial random variable.

Examples

spcov_params_val <- spcov_params("exponential", de = 0.2, ie = 0.1, range = 1)
sprbinom(spcov_params_val, data = caribou, xcoord = x, ycoord = y)
#>  [1] 1 0 0 1 0 1 0 0 0 0 0 0 1 0 1 1 0 0 0 0 1 0 0 1 1 1 0 1 1 1
sprbinom(spcov_params_val, samples = 5, data = caribou, xcoord = x, ycoord = y)
#>       1 2 3 4 5
#>  [1,] 1 1 0 0 1
#>  [2,] 0 0 1 0 0
#>  [3,] 0 0 1 0 1
#>  [4,] 0 0 1 1 1
#>  [5,] 1 0 1 1 1
#>  [6,] 0 1 1 0 0
#>  [7,] 1 0 1 1 0
#>  [8,] 0 0 0 0 0
#>  [9,] 1 1 1 0 0
#> [10,] 0 1 0 0 1
#> [11,] 1 1 1 1 0
#> [12,] 1 1 1 1 1
#> [13,] 0 1 1 1 0
#> [14,] 1 0 1 1 0
#> [15,] 1 1 1 1 1
#> [16,] 0 1 0 0 0
#> [17,] 1 1 0 0 1
#> [18,] 1 0 0 0 0
#> [19,] 0 1 0 1 1
#> [20,] 0 1 0 1 0
#> [21,] 0 1 0 0 0
#> [22,] 1 0 1 1 0
#> [23,] 0 1 0 1 1
#> [24,] 0 1 0 1 1
#> [25,] 0 1 1 1 0
#> [26,] 0 1 0 0 0
#> [27,] 0 1 1 1 0
#> [28,] 0 1 1 0 0
#> [29,] 1 0 1 0 0
#> [30,] 1 0 0 1 0