My code with bayesian linear regression

5 views (last 30 days)
Yohan
Yohan on 25 Apr 2024
Commented: Yohan on 6 May 2024
Currently I am just playing around with matlab to get used to the program and this is my following code so far. The purpose of my code is to run a following bayesian linear regression: My dependent variable is CAPB1 (stand for cyclically adjusted primary balance) and my independent variables are Govsize, GDPperCapita and CPIlevel. The Matlab website said I have to use bayeslm code but I am not aware of how does this code can be added here.
For your information on prior, I am assuming a normal distribution of parameter.
clear
% Load and prepare data
Cyclicalitydata = readtable("Could be final data set.xlsx");
BelgiumData = Cyclicalitydata(strcmp(Cyclicalitydata.Country, 'Belgium'), :);
BelgiumData = rmmissing(BelgiumData);
varnames = {'Govsize', 'GDPperCapita', 'CPIlevel'};
X = BelgiumData{:, varnames};
Y = BelgiumData{:, 'CAPB1'};
Also I am not sure how to use the semiconjugateblm and conjugateblm code too. The Matlab website wans't that friendly to me since it does not really provide an example of how to use those codes instead they said I can use some codes they mentioned.

Answers (1)

Harsh
Harsh on 6 May 2024
Hi Yohan,
From what I can gather, you are working with a code which should perform bayesian linear regression in MATLAB and are unable to find any relevant documentation that demonstrats how "bayeslm", "semiconjugateblm" and "conjugateblm" should be used.
For relevant examples on "bayeslm", "semiconjugateblm" and "conjugateblm" copy the following code snippets in MATLAB:
% This example uses "bayeslm" function with "conjugateblm"
openExample('econ/CreateNormalInverseGammaConjugatePriorModelExample')
% This example uses "bayeslm" function with "semiconjugateblm"
openExample('econ/CreateNormalInverseGammaSemiconjugatePriorModelExample')
Refer the following documentations for more information on "bayeslm", "semiconjugateblm" and "conjugateblm":
  1. semiconjugateblm: https://www.mathworks.com/help/econ/semiconjugateblm.html
  2. conjugateblm: https://www.mathworks.com/help/econ/conjugateblm.html
I hope this helps, thanks!
  1 Comment
Yohan
Yohan on 6 May 2024
Thank you so much! do you also have something similar to bayesian time varying coefficient model? That basically involves state space modelling.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!