This is a Bayesian econometrics MATLAB toolbox. It is convenient to use and has a lot of standard econometrics models:
- Linear Regression
- Ordinary Least Squares
- Bayesian Linear Regression
- Linear Regression(Heterogeneity)
- Bayesian IV Linear Regression
- Time Series
- Bayesian Unit-Root Test
- Principal Component Analysis
- Linear Regression(Autocorrelation,MCMC)
- Unrestricted BVAR Model
- Impulse-Response Analysis
- Markov Switching Model
- State Space Model
- Unobserved Component Model
- Dynamic Common Factor Model
- Time-varying Parameter
- ARMA-X(Kalman filter)
- Stochastic Volatility
- Variable Selection
- Absolutely Continuous Spikes prior
- Dirac Spike - g prior
- Mixture Normal
This package is appropriate to use when you need to see patterns in data easily and quickly (preliminary analysis).
Download the entire package files and add the path of the folder containing bayecon.m
in MATLAB.
Just type
results = bayecon(data)
in REPL(command line) or a script. That's all! When you type it, you will naturally realize how to use it.
Input data
is a matrix in which each column has observations of a variable (each variable is a column vector). The order of variables does not matter. Bayecon will reorder it as you want.
Output results
is a struct containing an analysis's results.
Suppose we have one dependent variable, y
, and one regressor, x
. Then, we can compose the input as
[T, ~] = size(y)
data = [y ones(T,1) x]
Then, execute the package with
results = bayecon(data)
in REPL(or script). Then, in the command window, the below things are displayed.
/////////////////////////////////////////////
////////Bayesian Econometrics ToolBox////////
/////////////////////////////////////////////
Email : econ.preference@gmail.com
====================Model====================
1. Linear Regression
2. Time Series
3. State Space Model
4. Variable Selection
5. Mixture Normal
=============================================
Which model would you like to choose?
Type 1
in REPL and press enter. Then,
/////////////////////////////////////////////
////////Bayesian Econometrics ToolBox////////
/////////////////////////////////////////////
Model: Linear Regression
====================Model====================
1. Ordinary Least Squares
2. Bayesian Linear Regression
3. Linear Regression(Heterogeneity)
4. Bayesian IV Linear Regression
=============================================
Which model would you like to choose?
is displayed. Type 2
in REPL and press enter. The displayed output is
=============================================
Model: Bayesian Linear Regression
=============================================
[Data generating Process]
Y | X,b,sig2 ~ Normal(X*b, sig2 * I(T,T))
b ~ Normal(b0, B0)
(b0: k by 1, B0: k by k)
sig2 ~ InverseGamma(a0 / 2, d0 / 2)
(a0: 1 by 1, d0: 1 by 1)
T: Number of observations, k: Number of Regressor
What column in the data matrix is the dependent variable?
It is a description of my Bayesian linear regression model. See the last line. Since our dependent variable is in the first column of data
, type 1
in REPL and press enter. The next question is
Enter the Hyper-parameter according to the following form.
b0: 2 by 1 =
As shown in the model description, b0
is a prior mean. In the display, b0: 2 by 1
means that b0
should be a two-by-one array. For example, I can type zeros(2, 1)
in REPL. The next thing is
B0: 2 by 2 =
In this case, B0
(prior variance) is a two-by-two array. Type it based on your prior belief. Similarly, the package will ask you to type a0
and b0
. Since a0
and b0
are scalars, type double-type numbers based on your belief. For example, I can type
a0: scalar = 4
Lastly, the package asks you about the MCMC simulation size. In my case, I set it as
[burn-in size, sampling size]= [5000, 20000]
Here, sampling size
is the number of posterior samples. Then, the package asks you whether you wanna make a forecast. Type Y
or N
. Also, it will ask about whether you want to calculate the marginal likelihood.
The last thing displayed is
Do you want to save your model into "BLR.mat" ?
type Y or N :
It is a function to save the setting that you typed. It can be saved for the replication. Or, you can modify the saved mat file to change your settings. After you type Y
or N
, you can see estimation results in your command and pop-up windows. The results will be saved in results
(the specified output name of function "bayecon") as a struct
type variable.
When there is a corresponding mat file(a specific file name for each model) in your current working folder, you can see the below output after selecting 2. Bayesian Linear Regression
model.
"BLR.mat" is founded"
Do you want to use the model in "BLR.mat" ?
type Y or N :
If you want to use the saved setting, press Y
. Then, the package estimates the model using the saved setting. If you do not want to use the previous setting, press N
and create a new setting as you did before.
Most models in the package are mex-files. I check that every mex-file model has both *.mexw64 and *.mexmaci64. Some models do not have *.mexw32. So, if you have a different operating system,
-
Compile a new mex file using the corresponding *.prj file. All mex file model has their prj file that is completed.
-
In the script where the compatibility error occurs, erase "_mex" from the function name in my script (for example, modify
output=function_name_mex(input)
tooutput=function_name(input)
)
If you want to cite my package, please cite
@software{Lee_Bayecon_Bayesian_Econometrics_2023,
author = {Sun Ho Lee},
month = apr,
title = {{Bayecon: Bayesian Econometrics package}},
url = {https://github.com/econPreference/bayecon.matlab},
version = {1.0.0},
year = {2023}
}
or
Lee, Sun Ho (2023), “Bayecon: Bayesian econometrics package.”