Professional Documents
Culture Documents
Bayesgauss PDF
Bayesgauss PDF
Kevin P. Murphy
murphyk@cs.ubc.ca
Last updated October 3, 2007
1 Introduction
The Gaussian or normal distribution is one of the most widely used in statistics. Estimating its parameters using
Bayesian inference and conjugate priors is also widely used. The use of conjugate priors allows all the results to be
derived in closed form. Unfortunately, different books use different conventions on how to parameterize the various
distributions (e.g., put the prior on the precision or the variance, use an inverse gamma or inverse chi-squared, etc),
which can be very confusing for the student. In this report, we summarize all of the most commonly used forms. We
provide detailed derivations for some of these results; the rest can be obtained by simple reparameterization. See the
appendix for the definition the distributions that are used.
2 Normal prior
Let us consider Bayesian estimation of the mean of a univariate Gaussian, whose variance is assumed to be known.
(We discuss the unknown variance case later.)
2.1 Likelihood
Let D = (x1 , . . . , xn ) be the data. The likelihood is
n n
( )
Y 1 X
p(D|, 2 ) = p(xi |, 2 ) = (2 2 )n/2 exp 2 (xi )2 (1)
i=1
2 i=1
1
Hence
2 1 1 1 2 2
p(D|, ) = exp 2 ns + n(x ) (8)
(2)n/2 n 2
n/2
ns2
1 n
2
exp (x ) exp (9)
2 2 2 2 2
(Do not confuse 02 , which is the variance of the prior, with 2 , which is the variance of the observation noise.) (A
natural conjugate prior is one that has the same form as the likelihood.)
2.3 Posterior
Hence the posterior is given by
Since the product of two Gaussians is a Gaussian, we will rewrite this in the form
P 2
2 1
P 2
n 0 i xi 0 x
p(|D) exp 2 + 2 + 2 + 2
2 + i 2i (16)
2 0 20 2
0
def 1 1
= exp 2 (2 2n + 2n ) = exp 2 ( n )2 (17)
2n 2n
2 2 1
n
= + 2 (18)
2n2 2 02
1 1 n
= + 2 (19)
n2 02
2 02 1
n2 = = n (20)
n02 + 2 2 + 1
02
2
5
N = 10
N =2
N =1
N =0
0
1 0 1
Figure 1: Sequentially updating a Gaussian mean starting with a prior centered on 0 = 0. The true parameters are = 0.8
(unknown), ( 2 ) = 0.1 (known). Notice how the data quickly overwhelms the prior, and how the posterior becomes narrower.
Source: Figure 2.12 [Bis06].
Hence
2 n02
0 nx
n = 0 + x = n2 + 2 (24)
n02 + 2 n02 + 2 2
0
This operation of matching first and second powers of is called completing the square.
Another way to understand these results is if we work with the precision of a Gaussian, which is 1/variance (high
precision means low variance, low precision means high variance). Let
= 1/ 2 (25)
0 = 1/02 (26)
n = 1/n2 (27)
3
prior sigma 10.000 prior sigma 1.000
0.45 0.7
prior
prior
0.4 lik
lik 0.6 post
post
0.35
0.5
0.3
0.25 0.4
0.2 0.3
0.15
0.2
0.1
0.1
0.05
0 0
5 0 5 5 0 5
(a) (b)
Figure 2: Bayesian estimation of the mean of a Gaussian from one sample. (a) Weak prior N (0, 10). (b) Strong prior N (0, 1). In
the latter case, we see the posterior mean is shrunk towards the prior mean, which is 0. Figure produced by gaussBayesDemo.
Pn n
where nx = i=1 xi and w = n . The precision of the posterior n is the precision of the prior 0 plus one
contribution of data precision for each observed data point. Also, we see the mean of the posterior is a convex
combination of the prior and the MLE, with weights proportional to the relative precisions.
To gain further insight into these equations, consider the effect of sequentially updating our estimate of (see
Figure 1). After observing one data point x (so n = 1), we have the following posterior mean
2 2
1 = 2 0 + 2 0 2 x (31)
2
+ 0 + 0
2
= 0 + (x 0 ) 2 0 2 (32)
+ 0
2
= x (x 0 ) 2 (33)
+ 02
The first equation is a convex combination of the prior and MLE. The second equation is the prior mean ajusted
towards the data x. The third equation is the data x adjusted towads the prior mean; this is called shrinkage. These
are all equivalent ways of expressing the tradeoff between likelihood and prior. See Figure 2 for an example.
2.4 Posterior predictive
The posterior predictive is given by
Z
p(x|D) = p(x|)p(|D)d (34)
Z
= N (x|, 2 )N (|n , n2 )d (35)
= N (x|n , n2 + 2 ) (36)
This follows from general properties of the Gaussian distribution (see Equation 2.115 of [Bis06]). An alternative proof
is to note that
x = (x ) + (37)
x N (0, 2 ) (38)
N (n , n2 ) (39)
Since E[X1 + X2 ] = E[X1 ] + E[X2 ] and Var [X1 + X2 ] = Var [X1 ] + Var [X2 ] if X1 , X2 are independent, we have
X N (n , n2 + 2 ) (40)
4
since we assume that the residual error is conditionally independent of the parameter. Thus the predictive variance is
the uncertainty due to the observation noise 2 plus the uncertainty due to the parameters, n2 .
2.5 Marginal likelihood
Writing m = 0 and 2 = 02 for the hyper-parameters, we can derive the marginal likelihood as follows:
Z Y n
` = p(D|m, 2 , 2 ) = [ N (xi |, 2 )]N (|m, 2 )d (41)
i=1
2 n2 x
2 2 2
!
+ m
P 2
m2 + 2nxm
i xi 2 2
= exp 2 exp (42)
( 2)n n 2 + 2 2 2 2 2(n + 2 )
2
where
exp 21 (S 2 i x2i + T 2 m2 )
P
c = (47)
( 2/S)n ( 2/T )
So
S 2 i xi + T 2 m
Z P
` = c exp 21 (S 2 n + T 2 ) 2 2 d (48)
S2n + T 2
2 " 2 #
(S nx + T 2 m)2 S 2 nx + T 2 m
Z
1 2 2
= c exp exp 2 (S n + T ) d (49)
2(S 2 n + T 2 ) S2n + T 2
2
(S nx + T 2 m)2
2
= c exp (50)
2(S 2 n + T 2 ) S2n + T 2
exp 12 (S 2 i x2i + T 2 m2 )
2
(S nx + T 2 m)2
P
2
= exp 2n + T 2)
(51)
n
( 2/S) ( 2/T ) 2(S S n + T2
2
Now
1 2
p = (52)
2
(2)/T S n + T 2 N 2 + 2
and
( nx2 + m2 )2 (nx 2 + m 2 )2
= (53)
2( n2 + 12 ) 2 2 2 (n 2 + 2 )
n2 x2 2 / 2 + 2 m2 / 2 + 2nxm
= (54)
2(n 2 + 2 )
5
So
2 n2 x
2 2 2
!
+ m
P 2
m2 + 2nxm
i xi 2 2
p(D) = exp 2 exp (55)
( 2)n n 2 + 2 2 2 2 2(n + 2 )
2
3.2 Prior
The conjugate prior is the normal-Gamma:
def
N G(, |0 , 0 , 0 , 0 ) = N (|0 , (0 )1 )Ga(|0 , rate = 0 ) (63)
1 1 0
= 2 exp( ( 0 )2 )0 1 e0 (64)
ZN G (0 , 0 , 0 , 0 ) 2
1 0 1 2
= 2 exp 0 ( 0 ) + 20 (65)
ZN G 2
1
(0 ) 2 2
ZN G (0 , 0 , 0 , 0 ) = (66)
00 0
6
NG(=2.0, a=1.0, b=1.0) NG(=2.0, a=3.0, b=1.0)
0.4 0.4
0.2 0.2
0 0
4 4
2 2
2 0 2 0
0 2 0 2
0.4 0.4
0.2 0.2
0 0
4 4
2 2
2 0 2 0
0 2 0 2
(a)
p() (69)
ba
ba (70)
0 1
= (0 + ( 0 )2 )0 2 (71)
2
1 0 0 ( 0 )2 (20 +1)/2
= (1 + ) (72)
20 0
7
3.3 Posterior
The posterior can be derived as follows.
So
1 2
p(, |D) 2 e(/2)(0 +n)(n ) (81)
x) e
2 x
n( )2
(/2) 0 +n 0
0 +n/21 e0 e(/2) i (xi
P
0 (82)
1
N (|n , (( + n)) ) Ga(|0 + n/2, n ) (83)
where
n
X 0 n(x 0 )2
n = 0 + 1
2 (xi x)2 + (84)
i=1
2(0 + n)
In summary,
P We see that the posterior sum of squares, n , combines the prior sum of squares, 0 , the sample sum of squares,
2
i (xi x) , and a term due to the discrepancy between the prior mean and sample mean. As can be seen from
Figure 3, the range of probable values for and 2 can be quite large even after for moderate n. Keep this picture in
mind whenever someones claims to have fit a Gaussian to their data.
8
3.3.1 Posterior marginals
The posterior marginals are (using Equation 72)
p(Dnew , D)
p(Dnew |D) = (96)
p(D)
Zn+m Z0
= (2)(n+m)/2 (2)n/2 (97)
Z0 Zn
Zn+m
= (2)m/2 (98)
Zn
1
(n+m ) nn
n 2
= n+m (2)m/2 (99)
(n ) n+m n+m
In the special case that m = 1, it can be shown (see below) that this is a T-distribution
n (n + 1)
p(x|D) = t2n (x|n , ) (100)
n n
To derive the m = 1 result, we proceed as follows. (This proof is by Xiang Xuan, and is based on [GH94, p10].)
When m = 1, the posterior parameters are
9
1 P1 2
Use the fact that when m = 1, we have x1 = x (since there is only one observation), hence we have 2 i=1 (xi x) =
0. Lets use x denote Dnew , then n+1 is
n (x n )2
n+1 = n + (104)
2(n + 1)
So the posterior is
n
X
p(m, |D) = N G(n = x, n = n, n = (n 1)/2, n = 1
2 (xi x)2 ) (112)
i=1
x)2
P
i (xi
p(m|D) = tn1 (m|x, ) (113)
n(n 1)
which corresponds to the frequentist sampling distribution of the MLE . Thus in this case, the confidence interval
and credible interval coincide.
4 Gamma prior
If is known, and only is unknown (e.g., when implementing Gibbs sampling), we can use the following results,
which can be derived by simplifying the results for the Normal-NG model.
10
4.1 Likelihood
n
!
X
p(D|) n/2 exp (xi )2 (114)
2 i=1
4.2 Prior
4.3 Posterior
5.2 Prior
The normal-inverse-chi-squared prior is
p(, 2 ) = N I2 (0 , 0 , 0 , 02 ) (123)
= N (|0 , 2 /0 ) 2 ( 2 |0 , 02 ) (124)
1 1 2 (0 /2+1) 1 2 2
= ( ) exp 2 [0 0 + 0 (0 ) ] (125)
Zp (0 , 0 , 0 , 02 ) 2
p 0 /2
(2) 2
Zp (0 , 0 , 0 , 02 ) = (0 /2) (126)
0 0 02
11
NIX(0=0.0, 0=1.0, 0=1.0, 20=1.0) NIX(0=0.0, 0=5.0, 0=1.0, 20=1.0)
0.4 0.8
0.3 0.6
0.2 0.4
0.1 0.2
0 0
2 2
1.5 1 1.5 1
1 0.5 1 0.5
0 0
0.5 0.5
0.5 0.5
2 0 1 2 0 1
sigma sigma
(a) (b)
NIX(0=0.0, 0=1.0, 0=5.0, 20=1.0) NIX(0=0.5, 0=5.0, 0=5.0, 20=0.5)
0.4 2.5
2
0.3
1.5
0.2
1
0.1
0.5
0 0
2 2
1.5 1 1.5 1
1 0.5 1 0.5
0 0
0.5 0.5
0.5 0.5
2 0 1 0 1
sigma sigma2
(c) (d)
Figure 4: The N I2 (0 , 0 , 0 , 02 ) distribution. 0 is the prior mean and 0 is how strongly we believe this; 02 is the prior
variance and 0 is how strongly we believe this. (a) 0 = 0, 0 = 1, 0 = 1, 02 = 1. Notice that the contour plot (underneath the
surface) is shaped like a squashed egg. (b) We increase the strenght of our belief in the mean, so it gets narrower: 0 = 0, 0 =
5, 0 = 1, 02 = 1. (c) We increase the strenght of our belief in the variance, so it gets narrower: 0 = 0, 0 = 1, 0 = 5, 02 = 1.
(d) We strongly believe the mean and variance are 0.5: 0 = 0.5, 0 = 5, 0 = 5, 02 = 0.5. These plots were produced with
NIXdemo2.
See Figure 4 for some plots. The hyperparameters 0 and 2 /0 can be interpreted as the location and scale of , and
the hyperparameters u0 and 02 as the degrees of freedom and scale of 2 .
For future reference, it is useful to note that the quadratic term in the prior can be written as
Q0 () = S0 + 0 ( 0 )2 (127)
2
= 0 2(0 0 ) + (0 20 + S0 ) (128)
12
5.3 Posterior
(The following derivation is based on [Lee04, p67].) The posterior is
p(, 2 |D) N (|0 , 2 /0 )2 ( 2 |0 , 02 )p(D|, 2 ) (129)
1 2 (0 /2+1) 1 2 2
( ) exp 2 [0 0 + 0 (0 ) ] (130)
2
2 n/2 1 2 2
( ) exp 2 ns + n(x ) (131)
2
3 2 (n /2) 1
( ) exp 2 [n n + n (n ) ] = N I2 (n , n , n , n2 )
2 2
(132)
2
Matching powers of 2 , we find
n = 0 + n (133)
To derive the other terms, we will complete the square. Let S0 = 0 02 and Sn = n n2 for brevity. Grouping the
terms inside the exponential, we have
S0 + 0 (0 )2 + ns2 + n(x )2 = (S0 + 0 20 + ns2 + nx2 ) + 2 (0 + n) 2(0 0 + nx)(134)
Comparing to Equation 128, we have
n = 0 + n (135)
n n = 0 0 + nx (136)
Sn + n 2n = (S0 + 0 20 + ns2 + nx2 ) (137)
Sn = S0 + ns2 + 0 20 + nx2 n 2n (138)
One can rearrange this to get
Sn = S0 + ns2 + (1
0 +n
1 1
) (0 x)2 (139)
n0
= S0 + ns2 + (0 x)2 (140)
0 + n
We see that the posterior sum of squares, Sn = n n2 , combines the prior sum of squares, S0 = 0 02 , the sample sum
of squares, ns2 , and a term due to the uncertainty in the mean.
In summary,
0 0 + nx
n = (141)
n
n = 0 + n (142)
n = 0 + n (143)
1 X n0
n2 = (0 02 + (xi x)2 + (0 x)2 ) (144)
n i
0 + n
13
The modes of the marginal posterior are
mode[|D] = n (149)
n n2
mode[ 2 |D] = (150)
n + 2
A = n n2 + n (n )2 (158)
A
x = (159)
2
d A
= x2 (160)
dx 2
so
Z
p(|D) = C(+1) eA/2 d (161)
A
Z
= (A/2) C( )(+1) ex x2 dx (162)
2x
Z
1 x
A x e dx (163)
A (164)
= (n n2 + n (n )2 )(n +1)/2 (165)
(n +1)/2
n 2
1+ ( n ) (166)
n n2
tn (|n , n2 /n ) (167)
14
5.4 Marginal likelihood
Repeating the derivation of the posterior, but keeping track of the normalization constants, gives the following.
Z Z
p(D) = P (D|, 2 )P (, 2 )dd 2 (168)
Zp (n , n , n , n2 ) 1
= (169)
Zp (0 , 0 , 0 , 02 ) ZlN
/2 n /2
0 (n /2) 0 02 0
2 1
= 2
(170)
n (0 /2) 2 n n (2)(n/2)
(n /2) 0 (0 02 )0 /2 1
r
= (171)
(0 /2) n (n n2 )n /2 n/2
p(x, D)
= (173)
p(D)
(n n2 )n /2
r
((n + 1)/2) n 1
= (174)
(n /2) n + 1 (n n2 + n +1n
(x n )2 ))(n +1)/2 1/2
12 (n +1)/2
n (x n )2
((n + 1)/2) n
= 1+ (175)
(n /2) (n + 1)n n2 (n + 1)n n2
2
(1 + n )n
= tn (n , ) (176)
n
n = x (178)
n = n1 (179)
n = n (180)
2
P
x)
i (xi
n2 = (181)
n1
!
2 n2 1 X 2 2
p(, |D) exp 2 [ (xi x) + n(x ) ] (182)
2 i
(xi x)2
P
p( 2 |D) = 2 ( 2 |n 1, i ) (183)
n1
(xi x)2
P
p(|D) = tn1 (|x, i ) (184)
n(n 1)
15
which are very closely related to the sampling distribution of the MLE. The posterior predictive is
(1 + n) i (xi x)2
P
p(x|D) = tn1 x, (185)
n(n 1)
Note that [Min00] argues that Jeffreys principle says the uninformative prior should be of the form
1
lim N (|0 , 2 /k)2 ( 2 |k, 02 ) (2 2 ) 2 ( 2 )1 3 (186)
k 0
6.1 Likelihood
The likelihood can be written in this form
2 1 2 n/2 1 2 2
p(D|, ) = ( ) exp 2 ns + n(x ) (189)
(2)n/2 2
6.2 Prior
m0 = 0 (192)
1
V0 = (193)
0
0
a0 = (194)
2
0 02
b0 = (195)
2
6.3 Posterior
We can show that the posterior is also NIG:
The NIG posterior follows directly from the N I2 results using the specified substitutions. (The bn term requires
some tedious algebra...)
16
6.3.1 Posterior marginals
To be derived.
6.4 Marginal likelihood
For the marginal likelihood, substituting into Equation 171 we have
x = , y = x, 1 = 0 , A = I, b = 0, L1 = /N (207)
7.1 Prior
7.2 Likelihood
1
p(D|, ) N (x|, ) (209)
N
7.3 Posterior
17
7.4 Posterior predictive
8 Normal-Wishart prior
The multivariate analog of the normal-gamma prior is the normal-Wishart prior. Here we just state the results without
proof; see [DeG70, p178] for details. We assume X is a d-dimensional.
8.1 Likelihood
n
!
X
nd/2 n/2 T
p(D|, ) = (2) || exp 21 (xi ) (xi ) (216)
i=1
8.2 Prior
Posterior marginals
18
The MAP estimates are given by
n = x, Tn = S, n = n, n = n 1 (237)
S(n + 1)
p(x|D) = tnd (x, (240)
n(n d)
9 Normal-Inverse-Wishart prior
The multivariate analog of the normal inverse chi-squared (NIX) distribution is the normal inverse Wishart (NIW) (see
also [GCSR04, p85]).
19
9.1 Likelihood
The likelihood is
n
!
n 1X
p(D|, ) || 2 exp (xi )T 1 (xi ) (241)
2 i=1
n 1
= || 2 exp tr(1 S) (242)
2
(243)
9.2 Prior
The natural conjugate prior is normal-inverse-wishart
9.3 Posterior
The posterior is
|D IW (1
n , n ) (255)
n
|D = tn d+1 (n , ) (256)
n (n d + 1)
To see the connection with the scalar case, note that n plays the role of n n2 (posterior sum of squares), so
n n 2
= = (257)
n (n d + 1) n n n
20
9.4 Posterior predictive
n (n + 1)
p(x|D) = tn d+1 (n , ) (258)
n (n d + 1)
To see the connection with the scalar case, note that
n (n + 1) n (n + 1) 2 (n + 1)
= = (259)
n (n d + 1) n n n
9.5 Marginal likelihood
The posterior is given by
1 1 1
p(, |D) = N IW 0 (, |0 ) N 0 (D|, ) (260)
p(D) Z0 (2)nd/2
1
= N IW 0 (, |n ) (261)
Zn
where
0 ((0 +d)/2+1) 1 1 0 T 1
N IW (, |0 ) = || exp tr(0 ) ( 0 ) ( 0 ) (262)
2 2
n 1
N 0 (D|, ) = || 2 exp tr(1 S) (263)
2
is the unnormalized prior and likelihood. Hence
Zn 1 2n d/2 d (n /2)(2/n )d/2 |0 |0 /2 1
p(D) = = (264)
Z0 (2)nd/2 |n |n /2 20 d/2 d (0 /2)(2/0 )d/2 (2)nd/2
1 2n d/2 (2/n )d/2 d (n /2)
= (265)
(2)nd/2 20 d/2 (2/0 )d/2 d (0 /2)
d/2
1 d (n /2) |0 |0 /2 0
= (266)
nd/2 d (0 /2) |n |n /2 n
This reduces to Equation 171 if d = 1.
9.6 Reference analysis
A noninformative (Jeffreys) prior is p(, ) ||(d+1)/2 which is the limit of 0 0, 0 1, |0 |0 [GCSR04,
p88]. Then the posterior becomes
n = x (267)
n = n (268)
n = n1 (269)
X
n = S= (xi x)(xi x)T (270)
i
p(|D) = IWn1 (|S) (271)
S
p(|D) = tnd (|x, ) (272)
n(n d)
S(n + 1)
p(x|D) = tnd (x|x, ) (273)
n(n d)
Note that [Min00] argues that Jeffreys principle says the uninformative prior should be of the form
1 d
lim N (|0 , /k)IWk (|k) |2| 2 ||(d+1)/2 ||( 2 +1) (274)
k0
21
Gamma(shape=a,rate=b) Gamma(shape=a,rate=b)
1.8 3
a=0.5, b=1.0 a=0.5, b=3.0
1.6 a=1.0, b=1.0 a=1.0, b=3.0
a=1.5, b=1.0 a=1.5, b=3.0
2.5
a=2.0, b=1.0 a=2.0, b=3.0
1.4 a=5.0, b=1.0 a=5.0, b=3.0
1.2 2
1
1.5
0.8
0.6 1
0.4
0.5
0.2
0 0
0 1 2 3 4 5 0 1 2 3 4 5
Figure 5: Some Ga(a, b) distributions. If a < 1, the peak is at 0. As we increase b, we squeeze everything leftwards and upwards.
Figures generated by gammaDistPlot2.
Note that the shape parameter controls the shape; the scale parameter merely defines the measurement scale (the
horizontal axis). The rate parameter is just the inverse of the scale. See Figure 5 for some examples. This distribution
has the following properties (using the rate parameterization):
a
mean = (277)
b
a1
mode = for a 1 (278)
b
a
var = (279)
b2
10.2 Inverse Gamma distribution
Let X Ga(shape = a, rate = b) and Y = 1/X. Then it is easy to show that Y IG(shape = a, scale = b), where
the inverse Gamma distribution is given by
ba (a+1) b/x
IG(x|shape = a, scale = b) = x e , x, a, b > 0 (280)
(a)
22
IG(a,b)
1.4
a=0.10, b=1.00
a=1.00, b=1.00
1.2 a=2.00, b=1.00
a=0.10, b=2.00
a=1.00, b=2.00
1 a=2.00, b=2.00
0.8
0.6
0.4
0.2
0
0 0.5 1 1.5 2
Figure 6: Some inverse gamma distributions (a=shape, b=rate). These plots were produced by invchi2plot.
b
mean = , a>1 (281)
a1
b
mode = (282)
a+1
b2
var = , a>2 (283)
(a 1)2 (a 2)
See Figure 6 for some plots. We see that increasing b just stretches the horizontal axis, but increasing a moves the
peak up and closer to the left.
There is also another parameterization, using the rate (inverse scale):
1
IG(x|shape = , rate = ) = (a)x(+1) e1/(x) , x, , > 0 (284)
a
23
2(,2)
1.5
2
=1.00, =0.50
=1.00, 2=1.00
2
=1.00, =2.00
=5.00, 2=0.50
2
=5.00, =1.00
1
=5.00, 2=2.00
0.5
0
0 0.5 1 1.5 2
Figure 7: Some inverse scaled 2 distributions. These plots were produced by invchi2plot.
(So 1 () = ().) The mean and mode are given by (see also [Pre05])
mean = S (293)
mode = ( p 1)S, > p + 1 (294)
24
Wishart(dof=2.0,S=[4 3; 3 4]) Wishart(dof=10.0,S=[4 3; 3 4])
5 5 10
2 10 10
5
0 0 0 0 0 0
5
2 10 10
5 5 10
5 0 5 5 0 5 4 2 0 2 4 10 0 10 20 0 20 20 0 20
4 5
10
5 2 5 10
5
0 0 0 0 0 0
2 5 10
5 5
4 10
5
10 0 10 5 0 5 5 0 5 10 0 10 10 0 10 20 0 20
4 10
5 5 10 10
2 5
5 5
0 0 0 0 0 0
5 5
2 5 5
5 10 10
4 10
5 0 5 10 0 10 10 0 10 10 0 10 10 0 10 10 0 10
Figure 8: Some samples from the Wishart distribution. Left: = 2, right: = 10. We see that if if = 2 (the smallest valid
value in 2 dimensions), we often sample nearly singular matrices. As increases, we put more mass on the S matrix. If S = I2 ,
the samples would look (on average) like circles. Generated by wishplot.
|B|a
W i(X|a, B) = |X|a(p+1)/2 exp[tr(BX)] (295)
p (a)
We require that B is a p p symmetric positive definite matrix, and 2a > p 1. If p = 1, so B is a scalar, this reduces
to the Ga(shape = a, rate= b) density.
To get some intuition for this distribution, recall that tr(AB) is a vector which contains the inner product of the
rows of A and the columns of B. In Matlab notation we have
trace(A B) = [a(1,:)*b(:,1), ..., a(n,:)*b(:,n)]
If X W i (S), then we are performing a kind of template matching between the columns of X and S 1 (recall that
both X and S are symmetric). This is a natural way to define the distance between two matrices.
10.5 Inverse Wishart
This is the multidimensional generalization of the inverse Gamma. Consider a d d positive definite (covariance) ma-
trix X and a dof parameter > d 1 and psd matrix S. Some authors (eg [GCSR04, p574]) use this parameterization:
1 1 (+d+1)/2 1 1
IW (X|S ) = |X| exp T r(SX ) (296)
Z 2
|S|/2
Z = (297)
2d/2 d (/2)
where
d
Y +1i
d (/2) = d(d1)/4 ( ) (298)
i=1
2
25
The distribution has mean
S
EX = (299)
d1
In Matlab, use iwishrnd. In the 1d case, we have
2 (|0 , 02 ) = IW0 (|(0 02 )1 ) (300)
Other authors (e.g., [Pre05, p117]) use a slightly different formulation (with 2d < )
1
Yd
IW (X|Q) = 2(d1)d/2 d(d1)/4 (( d j)/2) (301)
j=1
1
|Q|(d1)/2 |X|/2 exp T r(X1 Q) (302)
2
which has mean
Q
EX = (303)
2d 2
10.6 Student t distribution
The generalized t-distribution is given as
( +1
2 )
2 1 x 2
t (x|, ) = c 1+ ( ) (304)
(/2 + 1/2) 1
c = (305)
(/2)
where c is the normalization consant. is the mean, > 0 is the degrees of freedom, and 2 > 0 is the scale. (Note
that the parameter is often written as a subscript.) In Matlab, use tpdf.
The distribution has the following properties:
mean = , > 1 (306)
mode = (307)
2
var = , >2 (308)
( 2)
Note: if x t (, 2 ), then
x
t (309)
which corresponds to a standard t-distribution with = 0, 2 = 1:
(( + 1)/2)
t (x) = (1 + x2 /)(+1)/2 (310)
(/2)
In Figure 9, we plot the density for different parameter values. As , the T approaches a Gaussian. T-
distributions are like Gaussian distributions with heavy tails. Hence they are more robust to outliers (see Figure 10).
If = 1, this is called a Cauchy distribution. This is an interesting distribution since if X Cauchy, then E[X]
does not exist, since the corresponding integral diverges. Essentially this is because the tails are so heavy that samples
from the distribution can get very far from the center .
It can be shown that the t-distribution is like an infinite sum of Gaussians, where each Gaussian has a different
precision:
Z
p(x|, a, b) = N (x|, 1 )Ga( |a, rate = b)d (311)
26
Student T distributions
0.4
t(=0.1)
0.35 t(=1.0)
t(=5.0)
0.3 N(0,1)
0.25
0.2
0.15
0.1
0.05
0.05
6 4 2 0 2 4 6
Figure 9: Student t-distributions T (, 2 , ) for = 0. The effect of is just to scale the horizontal axis. As , the
distribution approaches a Gaussian. See studentTplot.
0.5 0.5
0.4 0.4
0.3 0.3
0.2 0.2
0.1 0.1
0 0
5 0 5 10 5 0 5 10
(a) (b)
Figure 10: Fitting a Gaussian and a Student distribution to some data (left) and to some data with outliers (right). The Student
distribution (red) is much less affected by outliers than the Gaussian (green). Source: [Bis06] Figure 2.16.
27
T distribution, dof 2.0 Gaussian
0.2 2
0.15 1.5
0.1 1
0.05 0.5
0 0
2 2
1 2 1 2
0 1 1
0
0 0
1 1
1 1
2 2 2 2
Figure 11: Left: T distribution in 2d with dof=2 and = 0.1I2 . Right: Gaussian density with = 0.1I2 and = (0, 0); we see
it goes to zero faster. Produced by multivarTplot.
where is called the scale matrix (since it is not exactly the covariance matrix). This has fatter tails than a Gaussian:
see Figure 11. In Matlab, use mvtpdf.
The distribution has the following properties
Ex = if > 1 (315)
mode x = (316)
Cov x = for > 2 (317)
2
(The following results are from [Koo03, p328].) Suppose Y T (, , ) and we partition the variables into 2
blocks. Then the marginals are
Yi T (i , ii , ) (318)
and the conditionals are
28
References
[Bis06] C. Bishop. Pattern recognition and machine learning. Springer, 2006.
[BL01] P. Baldi and A. Long. A Bayesian framework for the analysis of microarray expression data: regularized
t-test and statistical inferences of gene changes. Bioinformatics, 17(6):509519, 2001.
[BS94] J. Bernardo and A. Smith. Bayesian Theory. John Wiley, 1994.
[DeG70] M. DeGroot. Optimal Statistical Decisions. McGraw-Hill, 1970.
[DHMS02] D. Denison, C. Holmes, B. Mallick, and A. Smith. Bayesian methods for nonlinear classification and
regression. Wiley, 2002.
[DMP+ 06] F. Demichelis, P. Magni, P. Piergiorgi, M. Rubin, and R. Bellazzi. A hierarchical Naive Bayes model
for handling sample heterogeneity in classification problems: an application to tissue microarrays. BMC
Bioinformatics, 7:514, 2006.
[GCSR04] A. Gelman, J. Carlin, H. Stern, and D. Rubin. Bayesian data analysis. Chapman and Hall, 2004. 2nd
edition.
[GH94] D. Geiger and D. Heckerman. Learning Gaussian networks. Technical Report MSR-TR-94-10, Microsoft
Research, 1994.
[Koo03] Gary Koop. Bayesian econometrics. Wiley, 2003.
[Lee04] Peter Lee. Bayesian statistics: an introduction. Arnold Publishing, 2004. Third edition.
[Min00] T. Minka. Inferring a Gaussian distribution. Technical report, MIT, 2000.
[Pre05] S. J. Press. Applied multivariate analysis, using Bayesian and frequentist methods of inference. Dover,
2005. Second edition.
29