Given a spatial weights matrix and degree of autocorrelation, returns autocorrelated data.

sim_sar(m = 1, mu = rep(0, nrow(w)), w, rho, sigma = 1, ...)

## Arguments

m

The number of samples required. Defaults to m=1 to return an n-length vector; if m>1, an m x n matrix is returned (i.e. each row will contain a sample of correlated values).

mu

An n-length vector of mean values. Defaults to a vector of zeros with length equal to nrow(w).

w

Row-standardized n x n spatial weights matrix.

rho

Spatial autocorrelation parameter in the range (-1, 1). Typically a scalar value; otherwise an n-length numeric vector.

sigma

Scale parameter (standard deviation). Defaults to sigma = 1. Typically a scalar value; otherwise an n-length numeric vector.

...

further arguments passed to MASS::mvrnorm.

## Value

If m = 1 a vector of the same length as mu, otherwise an m x length(mu) matrix with one sample in each row.

## Details

Calls MASS::mvrnorm internally to draw from the multivariate normal distribution. The covariance matrix is specified following the simultaneous autoregressive (SAR) model.

aple, mc, moran_plot, lisa, shape2mat

## Examples

data(georgia)
w <- shape2mat(georgia, "W")
x <- sim_sar(w = w, rho = 0.5)
aple(x, w)

x <- sim_sar(w = w, rho = 0.7, m = 10)
dim(x)
apply(x, 1, aple, w = w)