sem | R Documentation |
The sampler uses independent Normal-inverse-Gamma priors for the slope and variance parameters,
as well as a four-parameter prior for the spatial autoregressive parameter \rho
. The function is
used as an illustration on using the beta_sampler
, sigma_sampler
,
and rho_sampler
classes.
sem(
Y,
tt,
W,
Z = matrix(1, nrow(Y), 1),
niter = 200,
nretain = 100,
rho_prior = rho_priors(),
beta_prior = beta_priors(k = ncol(Z)),
sigma_prior = sigma_priors()
)
Y |
numeric |
tt |
single number greater or equal to 1. Denotes the number of time observations. |
W |
numeric, non-negative and row-stochastic |
Z |
numeric |
niter |
single number greater or equal to 1, indicating the total number of draws. Will be automatically coerced to integer. The default value is 200. |
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 100. |
rho_prior |
list of prior settings for estimating |
beta_prior |
list containing priors for the slope coefficients |
sigma_prior |
list containing priors for the error variance |
The considered panel spatial error model (SDEM) takes the form:
Y_t = Z \beta + \varepsilon_t,
with \varepsilon_t \sim N(0,(I_n - \rho W) \sigma^2)
. The row-stochastic n
by n
spatial weight
matrix W
is non-negative and has zeros on the main diagonal. \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_2
) is a
matrix of explanatory variables, where the former will also be spatially lagged.
\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_2
),
with N=nT
, the final model can be expressed as:
Y = Z \beta_3 + \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.
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 = sem(Y = dgp_dat$Y, tt = tt, W = dgp_dat$W,
Z = dgp_dat$Z, niter = 100, nretain = 50)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.