| 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 |
tt |
single number greater or equal to 1. Denotes the number of time observations. |
X |
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. |
beta_prior |
list containing priors for the slope coefficients |
sigma_prior |
list containing priors for the error variance |
The considered model takes the form:
Y_t = X_t \beta + \varepsilon_t,
with \varepsilon_t \sim N(0,I_n \sigma^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.
\beta (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 \beta + \varepsilon,
where \varepsilon \sim N(0,I_N \sigma^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.