Over the last few days, I study econometric with a book “Gary Koop Bayesian Econometrics”. This book is NOT over theoretical/mathematical orientated. It is important for me, there are many book which are related with “Bayesian Econometrics”, but all of them are over mathematical. This book is an exceptional, Professor Gary provided all source code on his web-site. He have provided some question sheets which take reader through some basic programming skills relating to course materials. Anyone else would know more about Bayesian Econometrics, you should take a look on his web-site. You would find/learn more than you expected.
I wrote a F# versions for his source code. The purpose of this article was to show the algorithms, and to borrow an implementation in F# and the examples may be interesting for those who like bayesian computing in functional language.
Professor Gary Koop conducted a course for various central-bank all over the world.
====================================================================================
Bayesian Methods for Empirical Macroeconomics
A Course Prepared the Global Initiative Program, Bank of Korea Academy
http://personal.strath.ac.uk/gary.koop/BoK_course.html
(* ---------------------- *)
(* Question 1 Ex1 *)
(* -------------------------- *)
#r "System.Windows.Forms.DataVisualization.dll"
#r @"../packages/MathNet.Numerics.3.2.1/lib/Net40/MathNet.Numerics.dll"
open System
open System.Net
open System.Windows.Forms
open System.Windows.Forms.DataVisualization.Charting
open Microsoft.FSharp.Control.WebExtensions
open MathNet.Numerics.Distributions
open MathNet.Numerics.Statistics
let num_draws = 10000
(* ---------------------- *)
(* Do results for uniform random number generator *)
(* -------------------------- *)
let uniformRandom =
printf "RESULTS - MEAN, STD "
printf "-----------------------------------------------------------------"
printf " "
printf "UNIFORM"
let normd = new Normal(0.0, 1.0)
let tempp = normd.Samples() |> Seq.take num_draws |> Seq.toList
let unifans = [tempp.Mean(), tempp.StandardDeviation()]
let trueans = [0.5, (1.0/sqrt(12.0))]
printf "%f %f\n",unifans, trueans
(* ---------------------- *)
(* Do results for Normal random number generator *)
(* ---------------------- *)
let standardNormalRandom =
printf "STANDARD NORMAL"
let normd = new Normal(0.0, 1.0)
let tempp = normd.Samples() |> Seq.take num_draws |> Seq.toList
let normans = [tempp.Mean(), tempp.StandardDeviation()]
let trueans = [0.0, 1.0]
printf "%f %f\n",normans, trueans
(* ---------------------- *)
(* Do results for Student-t random number generator *)
(* ---------------------- *)
let studentTRandom =
printf "STUDENT-T(3)"
let stdT = new StudentT(3.0,(float num_draws),1.0)
let tempp = stdT.Samples() |> Seq.take num_draws |> Seq.toList
let tans = [tempp.Mean(), tempp.StandardDeviation()]
let trueans = [0.0, sqrt(3.0)]
printf "%f %f\n",tans, trueans
(* ---------------------- *)
(* Do results for Beta random number generator *)
(* ---------------------- *)
let BETARandom =
printf "BETA(3,2)"
let beta = new Beta(3.0,2.0)
let tempp = beta.Samples() |> Seq.take num_draws |> Seq.toList
let betaans = [tempp.Mean(), tempp.StandardDeviation()]
let trueans = [(3/(3+2)),( 1 / 5 )]
printf "%f %f\n",betaans, trueans
(* ---------------------- *)
(* Do results for Exponential random number generator *)
(* ---------------------- *)
let exponentialRandom =
printf "Exponential (5)"
let exp = new Exponential(5.0)
let tempp = exp.Samples() |> Seq.take num_draws |> Seq.toList
let expans = [tempp.Mean(), tempp.StandardDeviation()]
let trueans = [5.0, 5.0]
printf "%f %f\n",expans, trueans
(* ---------------------- *)
(* Do results for Chi-Square random number generator *)
(* ---------------------- *)
let chiSquareRandom =
printf "ChiSquared(3)"
let chi2 = new ChiSquared(3.0)
let tempp = chi2.Samples() |> Seq.take num_draws |> Seq.toList
let chi2ans = [tempp.Mean(), tempp.StandardDeviation()]
let trueans = [3.0, sqrt(6.0)]
printf "%f %f\n",chi2ans, trueans
(* ---------------------- *)
(* Do results for Gamma random number generator *)
(* ---------------------- *)
let gammaRandom =
printf "Gamma(4,2)"
let gamma = new Gamma(4.0,2.0)
let tempp = gamma.Samples() |> Seq.take num_draws |> Seq.toList
let gamans = [tempp.Mean(), tempp.StandardDeviation()]
let trueans = [8.0, 4.0]
printf "%f %f\n",gamans, trueans
uniformRandom;;
standardNormalRandom;;
studentTRandom;;
BETARandom;;
exponentialRandom;;
chiSquareRandom;;
gammaRandom;;