The sampler uses independent Normal-inverse-Gamma priors for the slope and variance parameters, as well as a four-parameter
beta prior for the spatial autoregressive parameter \(\rho\).
This is a wrapper function calling sdemw with no spatially lagged exogenous variables.
semw(
Y,
tt,
Z,
niter = 100,
nretain = 50,
W_prior = W_priors(n = nrow(Y)/tt),
rho_prior = rho_priors(),
beta_prior = beta_priors(k = ncol(Z)),
sigma_prior = sigma_priors()
)List with posterior samples for the slope parameters, \(\rho\), \(\sigma^2\), \(W\), and average direct, indirect, and total effects.
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=T). Note that the observations
have organized such that \(Y = [Y_1',...,Y_T']'\).
single number greater or equal to 1. Denotes the number of time observations. \(tt = T\).
numeric \(N \times k_3\) design matrix of independent variables. The default value is a \(N \times 1\) vector of ones (i.e. an intercept for the model).
single number greater or equal to 1, indicating the total number of draws. Will be automatically coerced to integer. The default value is 100.
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.
list containing prior settings for estimating the spatial weight matrix \(W\).
Generated by the smart constructor W_priors.
list of prior settings for estimating \(\rho\),
generated by the smart constructor rho_priors
list containing priors for the slope coefficients \(\beta\),
generated by the smart constructor beta_priors.
list containing priors for the error variance \(\sigma^2\),
generated by the smart constructor sigma_priors
The considered panel spatial error model (SEM) with unknown (\(n\) by \(n\)) spatial weight matrix \(W\) takes the form:
$$ Y_t = Z \beta + \varepsilon_t, $$
with \(\varepsilon_t \sim N(0,(I_n - \rho W) \sigma^2)\) and \(W = f(\Omega)\). The \(n\) by \(n\) matrix \(\Omega\) is an unknown binary adjacency matrix with zeros on the main diagonal and \(f(\cdot)\) is the (optional) row-standardization function. \(\rho\) is a scalar spatial autoregressive parameter.
\(Y_t\) (\(n \times 1\)) collects the \(n\) cross-sectional (spatial) observations for time \(t=1,...,T\). \(Z_t\) (\(n \times k_3\)) is a matrix of explanatory variables. \(\beta\) (\(k_3 \times 1\)) is an unknown slope parameter vector.
After vertically staking the \(T\) cross-sections \(Y=[Y_1',...,Y_T']'\) (\(N \times 1\)), and \(Z=[Z_1', ..., Z_T']'\) (\(N \times k_3\)), with \(N=nT\). The final model can be expressed as:
$$ Y = Z \beta + \varepsilon, $$
where \(\tilde{W}=I_T \otimes W\) and \(\varepsilon \sim N(0,\sigma^2 (I_n \otimes (I_n - \rho W) )\). 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.
n = 20; tt = 10
dgp_dat = sim_dgp(n =n, tt = tt, rho = .5, beta3 = c(.5,1),
sigma2 = .05,n_neighbor = 3,intercept = TRUE,spatial_error = TRUE)
res = semw(Y = dgp_dat$Y,tt = tt,Z = dgp_dat$Z,niter = 20,nretain = 10)
Run the code above in your browser using DataLab