normalgamma | R Documentation |
The sampler uses independent Normal-inverse-Gamma priors to estimate a linear panel data model. The function is
used for an illustration on using the beta_sampler
and sigma_sampler
classes.
normalgamma( Y, tt, X = matrix(1, nrow(Y), 1), niter = 200, nretain = 100, beta_prior = beta_priors(k = ncol(X)), 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. |
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. |
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 model takes the form:
Y_t = X_t β + \varepsilon_t,
with \varepsilon_t \sim N(0,I_n σ^2).
Y_t (n \times 1) collects the n cross-sectional observations for time t=1,...,T. X_t (n \times k_1) is a matrix of explanatory variables. β (k_1 \times 1) is an unknown slope parameter matrix.
After vertically staking the T cross-sections Y=[Y_1',...,Y_T']' (N \times 1), X=[X_1',...,X_T']' (N \times k), with N=nT, the final model can be expressed as:
Y = X β + \varepsilon,
where \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.
n = 20; tt = 10; k = 3 X = matrix(stats::rnorm(n*tt*k),n*tt,k) Y = X %*% c(1,0,-1) + stats::rnorm(n*tt,0,.5) res = normalgamma(Y,tt,X)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.