sar_abc: SAR estimation using Aproximate Bayesian Computation

Description Usage Arguments Value Examples

View source: R/sarabc.R

Description

SAR estimation using Aproximate Bayesian Computation

Usage

1
2
3
sar_abc(y, X, W, rho = runif(N, -1, 1), beta = matrix(runif(N * ncol(X), -2,
  2), nrow = N), sweights = c(1, 2, 2), N = 10000L, p = 5L,
  no_inv = FALSE, no_moran = FALSE, keep = 1000L, cl = NULL, ...)

Arguments

y

Numeric vector of length n. Dependent variable.

X

Numeric matrix of size n*k. Covariates.

W

Square matrix of class dgCMatrix of size n*n.

rho

Numeric vector of length N. Prior of rho.

beta

Numeric matrix of size N*k. Prior of beta.

sweights

Numeric vector of length 3. Weights for the distance.

N

Integer scalar. Number of simulations to run.

p

Integer scalar. See sar_sim.

no_inv

Logical scalar. When FALSE runs the model approximating the inverse of I_n - rho W. Otherwise naively predicts y as in OLS.

no_moran

Logical scalar. When TRUE does not includes Moran's I in the set of statistics to compute distances.

keep

Numeric scalar between (0,1]. Sets what proportion of the simulated data to keep after ranking according to distances.

cl

An object generated by makeCluster.

...

Ignored.

Value

An object of class sar_abc

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Simple example ------------------------------------------------------------
set.seed(133)

# Parameters
n <- 200
rho  <- .25
beta <- -.6

# Dataset
W    <- netdiffuseR::rgraph_ws(n, 6, .15)
W    <- W/(Matrix::rowSums(W) + 1e-15)
X <- matrix(rnorm(n*1), ncol=1)
y <- sim_sar(W, X, rho, beta)

# Estimating
res <- sar_abc(y, X, W, N=1e4)
res

# Comparing with OLS
lm(y~0+I(as.matrix(W %*% y)) +X , data.frame(y,X))

# Comparing with sphet
## Not run: 
library(sphet)
spreg(y~X, data.frame(y,X), listw = mat2listw(W), model = 'lag')

## End(Not run)

gvegayon/sarabc documentation built on May 17, 2019, 9:30 a.m.