Educational Tools for Introductory Bayesian Statistics using Mathematica

Post on 30-Dec-2015

40 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

Educational Tools for Introductory Bayesian Statistics using Mathematica. Shin-ichi Mayekawa Graduate School of Decision Science and Technology. Tokyo Institute of Technology. Purpose of this Research. Find a way to use Mathematica e fficiently in Bayesian Statistics. - PowerPoint PPT Presentation

Transcript

IMPS200

6

Educational Toolsfor

Introductory Bayesian Statistics using Mathematica

Shin-ichi Mayekawa

Graduate School of Decision Science and Technology.

Tokyo Institute of Technology

IMPS2006

Purpose of this Research

Find a way to use Mathematicaefficiently in Bayesian Statistics.

Mathematica can do Symbolic Math.Especially, definite integration.

IMPS200

6

Outline

• What Mathematica can and cannot do.• What mathStatica can and cannot do.• What my Bayespack can do.

Application of SuMOpack (2005)

IMPS2006

What Mathematica Can Do

Knows(memorizes) PDF, CDF,mean, variance, skewness, kurtosisof many distributions.Knows(memorizes) Characteristic Function ofunivariate distribution.Can symbolically calculate/derive the expectation of a function of the random variable.And More.

IMPS2006

In[67]:= dist BetaDistribution, PDFdist, XCDFdist, XMeandistVariancedistSkewnessdistKurtosisdistCharacteristicFunctiondist, t

Out[67]= BetaDistribution, Out[68]=1 X1 X1

, Out[69]= IX, Out[70]=

Out[71]= 2 1

Out[72]=2 1

2

Out[73]=3 12 2 6

2 3Out[74]= 1F1; ; tIn[75]:= ExpectedValueSqrtX, dist, X

Out[75]= 1

2

, 12

<<Statistics`

IMPS2006

In[100]:= dist MultinormalDistribution1, 2,s1,1, s1,2,s1,2, s2,2PDFdist,x1, x2CDFdist,x1, x2MeandistVariancedistSkewnessdistKurtosisdistCharacteristicFunctiondist, t

Out[100]= MultinormalDistribution1, 2,s1,1 s1,2

s1,2 s2,2

Out[101]=

E

12

x22x22s1,1s1,1s2,2s1,2

2 x11s1,2s1,1 s2,2s1,2

2

x11x11s2,2s1,1 s2,2s1,2

2 x22s1,2s1,1s2,2s1,2

2

2s1,1 s2,2 s1,2

2

Out[102]= CDFMultinormalDistribution

1, 2,s1,1 s1,2

s1,2 s2,2

,x1, x2Out[103]=1, 2Out[104]=s1,1, s2,2Out[105]=0, 0Out[106]=3, 3Out[107]= CharacteristicFunction

MultinormalDistribution1, 2,s1,1 s1,2

s1,2 s2,2

, tIn[45]:= ExpectedValue1, dist,x1, x2

ExpectedValuex1, dist,x1, x2Out[45]= 1

Out[46]=If1 0,

2 1s1,1 , IntegrateEx112

2s1,1 x1,x1, , , Assumptions 1 02s1,1

IMPS2006

What Mathematica Cannot Do

Given an expression (full or kernel) and the name of the random variable, it cannot identify the distribution.Cannot directly calculate marginal/conditional distributions.Cannot handle fully symbolic multivariate distributions.No Bayesian distributions.

IMPS2006

Calculating the conditionaldistributions by NativeMathematica Conditional x given , and marginal f 12 2 Exp 1

2x ̂22

h0 1

2

Exp 222

x2

2222

2

222 Joint x and

g f h0

x2

22 222

22 Marginal x

f0 Integrateg,, , , Assumptions x, , , 0, 0 x2

222222 2

IMPS2006

Conditional given x h1 gf0h1 Simplify%, 0, 0, x ,

x2222x222 2

2222 2

22

2x2222

22 2222 22 Does it integrate to unity?

Integrateh1,, , , Assumptions x, , , 0, 01 Conditional Mean and Variance of given x meanMu Integrate h1,, , , Assumptions x, , , 0, 0varMu Integrate meanMu2 h1,, , , Assumptions x, , , 0, 02 x 2

2 2

2 2

2 2

IMPS2006

In[108]:= dist MultinormalDistribution, PDFdist, XCDFdist, XMeandistVariancedistSkewnessdistKurtosisdistCharacteristicFunctiondist, t

Out[108]= MultinormalDistribution, Out[109]= PDFMultinormalDistribution, , XOut[110]= CDFMultinormalDistribution, , XOut[111]=

Out[112]=

Out[113]= SkewnessMultinormalDistribution, Out[114]= KurtosisMultinormalDistribution, Out[115]= CharacteristicFunctionMultinormalDistribution, , tIn[116]:= ExpectedValue1, dist, X

Out[116]= ExpectedValue1, MultinormalDistribution, , X

IMPS2006

What is mathStatica ?mathStatica is a package created by: Colin Rose and Murray Smith(2002)

Mathematical Statistics with MathematicaSpringer Texts in Statistics 2002

with which we can study and practice mathematical statistics using Mathemtatica.

http://www.mathstatica.com/reviews/

IMPS2006

What mathStatica Can Do

Given PDF, mathStatica can do manysymbolic derivations using the followingfunctions:

Expect, Var, Corr, Cov, Prob, Transform, Jacob, Sufficient,Conditional, Marginal, and more.

IMPS2006

Calculating the conditional distributions by mathStatica

In[2]:= mathStatica.m

In[3]:= Conditional x given , and marginal f 12 2 Exp 1

2x ̂22

domainfx, , && Reals, 0Out[3]=

x22 222

Out[4]=x, , && Reals , 0In[5]:= h0

1

2

Exp 222

domainh0, , && Reals, 0Out[5]=

22 22

Out[6]=, , && Reals , 0In[7]:=

In[8]:= Joint x and g f h0domaingx, , ,, , && Reals, 0, 0

Out[8]=x22 2

22 2

22

Out[9]=x, , ,, , && Reals , 0, 0

IMPS2006

In[10]:= Conditional given x h1 Conditional, gh1 Simplify%, Reals, 0, 0, x , domainh1, , && Reals, 0Here is the conditional pdf gx:

Out[10]= 2x 2222

2 2 22222 22 2

Out[11]= 2x 2222

2 2 2222 22

Out[12]=, , && Reals , 0

IMPS2006

In[13]:= Conditional Mean and Variance of given x Expect, h1Simplify%, Reals, 0, 0Var, h1Simplify%, Reals, 0, 0This further assumes that: 1

2

1

2 0, 2

2 x 2

2 0Imx 2

2 0,

x 2

2 0

Out[13]=

2 x 21 2

22 232Out[14]=

2 x 2

2 2

This further assumes that: 12

1

2 0,

x 2

2 0Imx

2 0,

x 2

2 0

Out[15]= 2 x 222 22

2 4 22 x 22 x2 241

2 1

22 232

Out[16]=2 2

2 2

IMPS2006

What mathStatica Cannot Do

Given an expression (full or kernel) and the name of the random variable, it cannot identify the distribution.

Cannot handle fully symbolic multivariate distributions.

No Bayesian distributions.

No Bayesian statistics.

IMPS2006

Bayespack: objectives

Provide several Bayesian distributuionssuch as Inverted xxxx distribution.

Given an expression (full or kernel) and the name of the random variable(RV), identify the distribution of RV.

Find the kernel of the distributionby pattern matching,and find the normalizing constant.

IMPS2006

Bayespack: objectives

Should be able to handle fully symbolicmultivariate random variables.

1

2x.1.xUse SuMOpack.

IMPS200

6

SuMOpack for Mathematica (2005)1) Fully Symbolic Matrix Operations

1. Simplification of Matrix Expressions 2. Simplification of Partitioned Matrix Expressions 3. Conversion of Matrix Expressions to Summation Expressions 4. Derivative of a Scalar Function of Matrices w.r.t. a Matrix

2) Fully Symbolic Summation Operations

1. Simplification of Summation Expressions 2. Conversion of Summation Expressions to Matrix Expressions 3. Derivative of a Summation Expression w.r.t. a Subscripted Variable

IMPS2006

Bayespack: objectives

Should be able to do the standard Bayesian Analysis.

Identify the product of the Likelihood and the prior using the parametersas RV.

IMPS2006

Bayesian Distributions

Chi and Chi-Squared distribution(with scale parametes)Inverted Chi, Chi-Squared distributionInverted Gamma distributiont distribution (with mean and scale parametes)

Multivariate t distributionmatric t distribution (with mean and scale parametes)

Inverted Wishart distribution

IMPS2006

In[79]:= list "ChiSquared", , spdfx, list, 1, 1;pdfx, list, 2, 1;

Out[79]=ChiSquared, , sThe density of ChiSquared distribution with

the Parameters , s22 s x

2 s2 x1 2

Gamma2

The kernel of ChiSquared distribution with

the Parameters , s s x

2 x12

IMPS2006

In[82]:= list "InvertedChiSquared", , spdfx, list, 1, 1;pdfx, list, 2, 1;

Out[82]=InvertedChiSquared, , sThe density of InvertedChiSquared distribution with

the Parameters , s22 s

2 x s2 x1 2

Gamma2

The kernel of InvertedChiSquared distribution with

the Parameters , s s2 x x1

2

IMPS2006

In[94]:= list "Multivariatet", , M, Spdfx, list, 1pdfx, list, 2

Out[94]=Multivariatet, , M , SOut[95]=

nrx

2 2x M.S1.x M12nrx1

2 nrxS

2

Out[96]=x M.S1.x M 2

nrx2

IMPS2006

In[109]:= list "MatrixT", M, S, V, f pdfX, listpdfX, list, 2

Out[109]=MatrixT, M , S , V , Out[110]=

1

2 ncXnrXS nrX2 V12ncXX M.S1.X MV112ncXnrX1

i1

nrX1

2 i 1

i1

nrX1

2 i ncX 1

Out[111]=X M.S1.X M V112ncXnrX1In[106]:= list "MatrixT", M, S, V, , 2

f pdfX, listpdfX, list, 2

Out[106]=MatrixT, M , S , V , , 2Out[107]=

1

2 ncXnrXS12nrXVncX2 S X M.V .X M12ncXnrX1

i1

ncX1

2 i 1

i1

ncX1

2 i nrX 1

Out[108]=S X M.V .X M12ncXnrX1

IMPS2006

In[115]:= list "InvertedWishart", , pdfX, list, 1pdfX, list, 2

Out[115]=InvertedWishart, , Out[116]=

2 1

2nrX1nrX 1

2 Tr1.X1 1

4nrX1nrXX212nrX1i1nrX

12 i nrX

Out[117]= 1

2 Tr1.X1X2

IMPS2006

Identifying the DistributionOut[276]=

E2x2222

22 22222 22 2

In[277]:= IdentifyDist%, f f1, where the argument of Exp and Power in f1is Expanded and Collected .

Input : f E 2x 2222

2 2 22222 22 2

Simplified Input : f1 12 E 2

2 222 122

2

22222 2

222 x22

22

x 2222 x2 2

2 222 x 22

2 2

2 2222 2

Pattern matched KNormal : E2 a_. b_.c_. d_.

The distribution of is the Normal Distribution with

mu 2 x 2

2 2, sigma2

2 2

2 2,

const

2 22

The result of the integration of f with respect to

1

Out[277]=1,Normal,2 x 2

2 2,

2 2

2 2

IMPS2006

In[165]:= IdentifyDist2 12 nr 141nrnrDet2i1

nrGamma1

21 i

DetX12nr1ExpTrInverse.X, X;Normal , MVt or Wishart ??

Input : f 2

12 nrETr1.X 14nr1nrX12nr12

i1

nr1

2i 1

Pattern matched KWishart : Ed_.c_. TrC_:Identity.XB_.DetXa_.b_ e_.The distribution of X is the Wishart Distribution withSigma 2 , df ,

const 2

12 nrETr0 1

4nr1nr2i1

nr1

2i 1

The result of the integration of f with respect to X 22 2

IMPS2006

Bayesian Posterior Distributions

Method 1 Using the tools such as completeSquare,transform the joint distribution to the standard form and identify.

IMPS2006

Completion of SquareIn[278]:= completeSquarecx a2 dx b2, x

Out[278]=c da b2c d

c dx a c b d

c d2

In[279]:= matCompleteSquaretx a.C.x a tx b.D.x b, xThe following matrices are assumed to be symmetric .C, DTwo quadratic forms of x found .

Out[279]=a b.C1 D11.a bxC D1.C.a D.b.C D.x C D1.C.a D.bIn[280]:= matCompleteSquaretx a.C.x a tx b.D.x b, x, 1, 0

The following matrices are assumed to be symmetric .C, DTwo quadratic forms of x found .

Out[280]=x C D1.C.a D.b.C D.x C D1.C.a D.ba b.C.C D1.D.a b

IMPS2006

Completion of SquareIn[308]:= exp ssqy X., W

matCompleteSquareRssexp, %.XT .W .X1.XT .W .y

Out[308]=y X ..W .y X .Out[309]=y X .X.W .X1.X.W .y.W .y X .X.W .X1.X.W .y X.W .X1.X.W .y.X.W .X .X.W .X1.X.W .yOut[310]=y X .

.W .y X .

.X.W .X .

In[311]:= matCompleteSquaressqy1 X1. ssqy2 X2., The following matrices are assumed to be symmetric .Identity , X1.X1, X2.X2Two quadratic forms of found .

Out[311]= X1.X1 X2.X21.X1.y1 X2.y2.X1.X1 X2.X2. X1.X1 X2.X21.X1.y1 X2.y2X1.X11.X1.y1X2.X21.X2.y2.X1.X11X2.X211.X1.X11.X1.y1 X2.X21.X2.y2y1 X1.X1.X11.X1.y1.X1.X1.y1 X1.X1.X11.X1.y1y2 X2.X2.X21.X2.y2.X2.X2.y2 X2.X2.X21.X2.y2

IMPS2006

Completion of SquareIn[313]:= matCompleteSquaressqy1 X1., W1 ssqy2 X2., W2,

The following matrices are assumed to be symmetric .W1, W2, X1.W1.X1, X2.W2.X2Two quadratic forms of found .

Out[313]= X1.W1.X1 X2.W2.X21.X1.W1.y1 X2.W2.y2.X1.W1.X1 X2.W2.X2. X1.W1.X1 X2.W2.X21.X1.W1.y1 X2.W2.y2X1.W1.X11.X1.W1.y1 X2.W2.X21.X2.W2.y2.X1.W1.X11 X2.W2.X211.X1.W1.X11.X1.W1.y1 X2.W2.X21.X2.W2.y2y1 X1.X1.W1.X11.X1.W1.y1.X1.W1.X1.y1 X1.X1.W1.X11.X1.W1.y1y2 X2.X2.W2.X21.X2.W2.y2.X2.W2.X2.y2 X2.X2.W2.X21.X2.W2.y2

IMPS2006

Normal (natural conjugate)

Bayesian Normal Model

Data xi N, 2, i=1,2,...,n Natural Conjugate Prior for and . | N(, 2n0) Inverted Sqrt-Gamma(alpha0,beta0) = Inverted Chi (,s)

IMPS2006

Normal (natural conjugate)In[365]:= The Likelihood

L Product1

2

Expx 2

2 2.x xi,i, 1, n The Natural Conjugate Prior

h1 1

2 2n0 Exp 2

2 2n0h2 Exp s

21

The Joint Density of and g L h1 h2

Out[365]=i1

nExi2

222

Out[366]=E2 n0

2222

n0

Out[367]= E s2 1

Out[368]=

En02

22 s2 1

i1

nExi2

222 22

n0

IMPS2006

Normal (natural conjugate)In[388]:= Simplify the joint distribution of and .

g0 gprodPowerToPowerSumg0 g0sumSimplify

Out[388]=2 n2

12 E

n02

22 i1

nxi2

22 s2 n21

n1

2

n0

Out[389]=2

12n1

En022si1

nxi222 n21

n1

2

n0

In[390]:= %.Expa_ ExpcompleteSqsumFullSimplifya, Out[390]=

212n1

Enn0i1

n xin2

22nn0 n22

n022 n0i1

n xinn0

2 i1n xi22nsni1

n xi2

2n2n21

n1

2

n0

IMPS2006

Normal (natural conjugate)In[391]:= g2 IdentifyDistM%, 1;

Input : f 212n1E nn0i1

n xin2

2 2nn0 n2 2

n02 2 n0i1n xi

nn02 i1n xi22 nsni1n xi

2

2 n 2 n21n 12

n0

Pattern matched KNormal : Eb_.a_.m_:02 d_.The distribution of is the Normal Distribution with

mu n0 i1n xi

n n0, sigma2

2

n n0,

const 212n1Ei1n xi2n2 si1n xi

2n0n 22i1n xi2 si1n xi2

2 2nn0 n21n 12

n0

The result of the integration of f with respect to

2n2 Ei1n xi2n2 si1n xi2n0n 22i1n xi2 si1n xi

22 2nn0

12 n2 nn0

n n0

IMPS2006

Normal (natural conjugate)In[394]:= IdentifyDistg2, ;

f f1, where the argument of Exp and Power in f1is Expanded and Collected .

Input : f 2n2 Ei1n xi2n2 si1n xi

2n0n 22i1n xi2 si1n xi2

2 2nn0 12 n2 nn0

n n0

Simplified Input : f1 2n2 E

nn0 22nn0 n0i1n xi

nn0i1n xi22nn0

ni1n xi2

2nn0 n0i1n xi2

2nn0 nsnn0

sn0nn0

2 12 n2 nn0

n n0

Pattern matched KInvertedSqrtGamma : Eb_.2

d_.a_ c_.

The distribution of is the Inverted Chi Distribution with

df n 1, s i1n xi2 n2 s i1n xi2 n0n 2 2i1n xi 2 s i1n xi2

n n0,

const 2n2 1

2 n2n0n n0s2is 2df. Alias Inverted Sqrt Gammadf2, 2s

The result of the integration of f with respect to

1

2 32

12 n2 1

2n 1n0n n012n2

n n0 2 2 n0i1n xi i1n xi2 2 n s 2 s n0 n n0

i1

n

xi212n1

IMPS2006

Normal Regression (natural conjugate)

Bayesian Multiple Regression Normal Model

Data y NX ., 2Identity, i=1,2,...,n Natural Conjugate Prior for and . N(, n0

2 )

1s,

IMPS2006

Normal Regression (natural conjugate)

In[404]:= The Likelihood wo constant Clear, , , , x, m;L

1n

Exp 12ty X..y X.2 The Natural Conjugate Prior

h1 1

DetExp n022

t .Inverse. h2 Exp s

2 21 The Joint Density of x and

g L h1 h2

Out[405]= EyX ..yX .

22 n

Out[406]=E.1.n0

22Out[407]= E

s22 1

Out[408]=E s

22 yX ..yX .

22 .1.n0

22 n1

IMPS2006

Normal Regression (natural conjugate)

In[409]:= matCompSq%, The following matrices are assumed to be symmetric .Identity , X.X, 1Two quadratic forms of found .

Out[409]=1E

sX.X1n01.X. y1.n0.X.X1n0.X.X1 n01.X. y1.n0X.X1.X. y.n0 X.X11.X.X1.X. yyX .X.X1.X. y.X.X .yX .X.X22

n1

IMPS2006

Normal Regression (natural conjugate)In[410]:= IdentifyDistM%, 1

Input : f 1

E sX.X1 n0

1.X.y1. n0.X.X1 n0.X.X1 n01.X.y1. n0X.X1.X.y.n0 X.X11.X.X1.X.yy 2 2

n1

Pattern matched KMVN : Ea_.Transposem_:0.Sinv_:Identity.m_:0b_.d_. e_.The distribution of is the Multivariate Normal Distribution with

Mu 2X.X 1 n01.X.y 1. n0, Sigma 2X.X 1 n01,const

EsX.X1.X.y.n0 X.X11.X.X1.X.yyX.X.X1.X.y.X.X.yX.X.X1.X.y

2 2 n1The result of the integration of f with respect to

1E sX.X

1.X.y.n0 X.X11.X.X1.X.yyX.X.X1.X.y.X.X.yX.X.X1.X.y2 2

2 nr2 nnrX.X1 n01X.X 1 n01

Out[410]=EsX.X1.X. y.n0 X.X11.X.X1.X. yyX .X.X1.X. y.X.X .yX .X.X1.X. y

22 2nr2 nnrX.X1n01X.X 1 n01

IMPS2006

Normal Regression (natural conjugate)

In[411]:= IdentifyDistM%, ;Input : f

1E sX.X

1.X.y.n0 X.X11.X.X1.X.yyX.X.X1.X.y.X.X.yX.X.X1.X.y2 2

2 nr2 nnrX.X1 n01X.X 1 n01

Pattern matched KInvertedSqrtGamma : Eb_.2

d_.a_ c_.

The distribution of is the Inverted Chi Distribution with

df n nrX.X 1 n0, s

s X.X1.X.y.n0

X.X11. X.X1.X.yy X.X.X1.X.y.X.X.y X.X.X1.X.y,const 2 nr2 X.X 1 n01s2is 2df. Alias Inverted Sqrt Gammadf2, 2s

The result of the integration of f with respect to

12 12nnrnrX.X1 n02 nr

2X.X 1 n01s X.X1.X.y.

n0X.X11. X.X1.X.y

y X.X.X1.X.y.X.X.y X.X.X1.X.y12nnrX.X1 n012n nrX.X 1 n0

IMPS2006

Bayesian Posterior Distributions

Method 2 Try to identify the distribution automatically if possible without transforming to the standard form.

IMPS2006

Normal Regression (natural conjugate)

Bayesian Multiple Regression Normal Model

Data y NX ., 2Identity, i=1,2,...,n Natural Conjugate Prior for and . N(, n0

2 )

1s,

IMPS2006

Normal Regression (natural conjugate)In[427]:= The Likelihood wo constant

Clear, , , , x, m;L

1n

Exp 12ty X..y X.2; The Natural Conjugate Prior

h1 1

DetExp n022

t .Inverse. ;h2 Exp s

2 21; The Joint Density of x and

g L h1 h2;printL, h1, h2, g;L E

yX..yX.

2 2 n

h1 E.1.n0

2 2h2 E

s2 2 1

g E s2 2

yX..yX.

2 2.1.n0

2 2 n1

IMPS2006

Normal Regression (natural conjugate)In[435]:= Identify the dist of and integrate g0 wrt to get the marginal of .

g2 IdentifyDistg, 1;Normal , MVt or Wishart ??

The following matrices are assumed to be symmetric .X.X2

, 1,1 n02

,X.X2

1 n02

f f1, where the argument of Exp and Power in f1is Expanded and Collected .

Input : f E s2 2

yX..yX.

2 2.1.n0

2 2 n1Simplified Input : f1

E s2 2

y.X.1 n0.

2y.y2 2

.X.X1 n0.

2 2.1. n0

2 2 n1Pattern matched KMVN : EB_. a_.Transpose.C_:Identity. c_.d_. e_.The distribution of is the Multivariate Normal Distribution with

Mu X.X 1 n01.X.y 1. n0, Sigma 2X.X 1 n01,const

1E sy.yy.X.X.X1 n01.X.y.1. n0.1.X.X1 n01.X.y n0n0y.X.X.X1 n01.1..1.X.X1 n0

2 2

n1

The result of the integration of f with respect to

1E sy.yy.X.X.X1 n01.X.y.1. n0.1.X.X1 n01.X.y n0n0y.X.X.X1 n01.1..1.X.X1 n0

2 2

2 nr2 nnrX.X1 n01X.X 1 n01

IMPS2006

Normal Regression (natural conjugate)In[436]:= Identify the marginal of .

IdentifyDistg2, , 0;f f1, where the argument of Exp and Power in f1is Expanded and Collected .

Input : f 1E sy

.yy.X.X.X1 n01.X.y.1. n0.1.X.X1 n01.X.y n0n0y.X.X.X1 n01.1..1.X.X1 n02 2

2 nr2 nnrX.X1 n01X.X 1 n01Simplified Input : f1

1X.X 1 n0E 1

2 .1.X.X1 n01.1. n02 12 .1. n0 1

2 y.X.X.X1 n01.1. n0 12 .1.X.X1 n01.X.y n0 s2 y.y2 1

2 y2

2 nr2 nnrX.X1 n01

Pattern matched KInvertedSqrtGamma : Eb_.2

d_.a_ c_.

The distribution of is the Inverted Chi Distribution with

df n nrX.X 1 n0, s .1.X.X 1 n01.1. n02 .1. n0

y.X.X.X 1 n01.1. n0 .1.X.X 1 n01.X.y n0 s y.y y.X.X.X 1 n01.X.y,const

2 nr2X.X 1 n0s2is 2df. Alias Inverted Sqrt Gammadf2, 2sThe result of the integration of f with respect to

1X.X 1 n02 12nnrnrX.X1 n02 nr

2 12n nrX.X 1 n0s y.y y.X.X.X 1 n01.X.y n0.1. y.X.X.X 1 n01.1.

.1.X.X 1 n01.X.y .1.X.X 1 n01.1. n012nnrX.X1 n0

IMPS2006

Normal Regression (natural conjugate)

In[437]:= Identify the dist of and integrate g0 wrt to get the marginal of . g1 IdentifyDistg, , 01;f f1, where the argument of Exp and Power in f1is Expanded and Collected .

Input : f E s2 2

yX..yX.

2 2.1.n0

2 2 n1Simplified Input : f1

E s2 12y.X.yX. 12.1.n0

2 n1Pattern matched KInvertedSqrtGamma : E

b_.2

d_.a_ c_.

The distribution of is the Inverted Chi Distribution with

df n , s s y .X.y X. .1. n0,const

1s2is 2df. Alias Inverted Sqrt Gammadf2, 2sThe result of the integration of f with respect to

212n2n

2s y .X.y X. .1. n012n

IMPS2006

Normal Regression (natural conjugate)In[438]:= Identify the marginal of .

IdentifyDistg1, ;Normal , MVt or Wishart ??

The following matrices are assumed to be symmetric .X.X, 1, 1 n0, X.X 1 n0f f1, where the argument of Exp and Power in f1is Expanded and Collected .

Input : f 212n2n

2s y .X.y X. .1. n012n

Simplified Input : f1

212n2n

2s 2y.X .1 n0. y.y .X.X 1 n0. .1. n012n

Pattern matched KMVt :B_. a_. Transpose.C_ : Identity. c_. d_.b_ e_.The distribution of is the Multivariate t Distribution with

Mu X.X 1 n01.X.y 1. n0, Sigma X.X 1 n01s y.y y.X .1 n0.X.X 1 n01.X.y 1. n0 .1. n0n nr

, df n nr,const

212n2n

2sy.yy.X.1 n0.X.X1 n01.X.y1. n0.1. n0nnr 12n

The result of the integration of f with respect to

12 12n2 nr

2X.X 1 n0112n nrn nr12nrnrX.X1 n0s y.y y.X .1 n0.X.X 1 n01.X.y 1. n0 .1. n012nnrX.X1 n0

IMPS2006

Conclusions

Bayespack can be used as an Educational Tool.

It may be more suited

for those whowish to write a textbook on Bayseian Statistics.

Thank you.

IMPS200

6

Where to Download

http://www.ms.hum.titech.ac.jp/sumopack/sumopack.zip

http://www.ms.hum.titech.ac.jp/sumopack/Bayespack.zip

(by the end of June)

mayekawa@hum.titech.ac.jp

top related