slxw | R Documentation |
The sampler uses independent Normal-inverse-Gamma priors for the slope and variance parameters.
It is a wrapper around W_sampler
.
slxw( Y, tt, X = matrix(0, nrow(Y), 0), Z = matrix(1, nrow(Y), 1), niter = 100, nretain = 50, W_prior = W_priors(n = nrow(Y)/tt), beta_prior = beta_priors(k = ncol(X) * 2 + ncol(Z)), sigma_prior = sigma_priors() )
Y |
numeric N \times 1 matrix containing the dependent variables, where N = nT is the number of
spatial (n) times the number of time observations (T, with |
tt |
single number greater or equal to 1. Denotes the number of time observations. tt = T. |
X |
numeric N \times k_1 design matrix of independent variables. These will be automatically spatially lagged. If no spatially lagged variable is included in the model a matrix with N rows and zero columns should be supplied (the default value). Note: either X or Z has to be a matrix with at least one column. |
Z |
numeric N \times k_3 design matrix of independent variables which are not spatially lagged. The default value is a N \times 1 vector of ones (i.e. an intercept for the model). Note: either X or Z has to be a matrix with at least one column. |
niter |
single number greater or equal to 1, indicating the total number of draws. Will be automatically coerced to integer. The default value is 100. |
nretain |
single number greater or equal to 0, indicating the number of draws kept after the burn-in. Will be automatically coerced to integer. The default value is 50. |
W_prior |
list containing prior settings for estimating the spatial weight matrix W.
Generated by the smart constructor |
beta_prior |
list containing priors for the slope coefficients β,
generated by the smart constructor |
sigma_prior |
list containing priors for the error variance σ^2,
generated by the smart constructor |
The considered spatial panel SLX model with unknown (n by n) spatial weight matrix W takes the form:
Y_t = X_t β_1 + W X_t β_2 + Z β_3 + \varepsilon_t,
with \varepsilon_t \sim N(0,I_n σ^2) and W = f(Ω). The n by n matrix Ω is an unknown binary adjacency matrix with zeros on the main diagonal and f(\cdot) is the (optional) row-standardization function.
Y_t (n \times 1) collects the n cross-sectional (spatial) observations for time t=1,...,T. X_t (n \times k_1) and Z_t (n \times k_2) are matrices of explanatory variables, where the former will also be spatially lagged. β_1 (k_1 \times 1), β_2 (k_1 \times 1) and β_3 (k_2 \times 1) are unknown slope parameter vectors.
After vertically staking the T cross-sections Y=[Y_1',...,Y_T']' (N \times 1), X=[X_1',...,X_T']' (N \times k_1) and Z=[Z_1', ..., Z_T']' (N \times k_2), with N=nT. The final model can be expressed as:
Y = X β_1 + \tilde{W} X β_2 + Z β_3 + \varepsilon,
where \tilde{W}=I_T \otimes W and \varepsilon \sim N(0,I_N σ^2). Note that the input data matrices have to be ordered first by the cross-sectional spatial units and then stacked by time.
Estimation usually even works well in cases of n >> T. However, note that for applications with n > 200 the
estimation process becomes computationally demanding and slow. Consider in this case reducing niter
and
nretain
and carefully check whether the posterior chains have converged.
List with posterior samples for the slope parameters, σ^2, W, and average direct, indirect, and total effects.
set.seed(123) n = 20; tt = 10 dgp_dat = sim_dgp(n = 20, tt = 10, rho = 0, beta1 = c(1,-1), beta2 = c(3,-2.5), beta3 = c(.2), sigma2 = .05, n_neighbor = 3,intercept = TRUE) res = slxw(Y = dgp_dat$Y, tt = tt, X = dgp_dat$X, Z = dgp_dat$Z, niter = 20, nretain = 10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.