Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Use the data consisting of 30 lactic acid concentrations in cheese,10 from example 8.5.4 and 20 from Exercise 16 in sec.8,6, Fit the same model used in Example 8.6.2 with the same prior distribution, but this time use the Gibbs sampling algorithm in Example 12.5.1. simulate 10,000 pairs of \(\left( {{\bf{\mu ,\tau }}} \right)\) parameters. Estimate the posterior mean of \({\left( {\sqrt {{\bf{\tau \mu }}} } \right)^{ - {\bf{1}}}}\), and compute the standard simulation error of the estimator.

Short Answer

Expert verified

Let\({x_{\scriptstyle1\atop\scriptstyle\,}},{x_{\scriptstyle2\atop\scriptstyle\,}},.....{x_{\scriptstylen\atop\scriptstyle\,}}\) be i.i.d. random variables from the normal distribution with unknown mean and unknown variance \({\sigma ^2} > 0.\)Suppose that for the prior joint distribution, the conditional distribution ofμ given\(\tau = {\raise0.7ex\hbox{$1$} \!\mathord{\left/ {\vphantom {1 {{\sigma ^2}}}}\right.\\} \!\lower0.7ex\hbox{${{\sigma ^2}}$}} > 0\) is from the normal distribution with mean \({\mu _{\scriptstyle0\atop\scriptstyle\,}}\)and precision\({\lambda _{\scriptstyle0\atop\scriptstyle\,}}\tau > 0\) and that the marginal distribution of \(\tau \)is the gamma

\(est{\rm{ }} = {\rm{ }}0.2171,\,\,\,\,3.11 \times {10^{ - 5}}\)

Step by step solution

01

Definition of Gibbs sampling

Gibbs Samplingis a Monte Carlo Markov Chain method for estimating complex joint distributions that draw an instance from the distribution of each variable iteratively based on the current values of the other variables.

The following comment shall be used to determine the posterior (parameters) hyperparameters required for the simulation

Let\({x_{\scriptstyle1\atop\scriptstyle\,}},{x_{\scriptstyle2\atop\scriptstyle\,}},.....{x_{\scriptstylen\atop\scriptstyle\,}}\) be i.i.d. random variables from the normal distribution with unknown mean and unknown variance \({\sigma ^2} > 0.\)

Suppose that for the prior joint distribution, the conditional distribution of μ given\(\tau = {\raise0.7ex\hbox{$1$} \!\mathord{\left/ {\vphantom {1 {{\sigma ^2}}}}\right.\\} \!\lower0.7ex\hbox{${{\sigma ^2}}$}} > 0\) is from the normal distribution with mean \({\mu _{\scriptstyle0\atop\scriptstyle\,}}\)and precision\({\lambda _{\scriptstyle0\atop\scriptstyle\,}}\tau > 0\) and that the marginal distribution of \(\tau \)is the gamma distribution with parameters \({\alpha _{\scriptstyle0\atop\scriptstyle\,}} > 0\,and\,\,{\beta _{\scriptstyle0\atop\scriptstyle\,}} > 0\,\) .

Then for the joint posterior distribution, the conditional distribution of μ given\(\tau = 1/{\sigma ^2} > 0\) is from the normal distribution with mean\({\mu _{\scriptstyle1\atop\scriptstyle\,}}\) and precision\({\lambda _{\scriptstyle1\atop\scriptstyle\,}}\tau > 0\)

The marginal distribution of τ is the gamma distribution with parameters \({\alpha _{\scriptstyle0\atop\scriptstyle\,}} > 0\,and\,\,{\beta _{\scriptstyle0\atop\scriptstyle\,}} > 0\,\) where

\({\beta _{\scriptstyle1\atop\scriptstyle\,}} = {\beta _{\scriptstyle0\atop\scriptstyle\,}} + \frac{1}{2}{s_{\scriptstylen\atop\scriptstyle\,}}^2 + {\frac{{n{\lambda _{\scriptstyle0\atop\scriptstyle\,}}\left( {\overline {{x_{\scriptstylen\atop\scriptstyle\,}}} - {\mu _{\scriptstyle0\atop\scriptstyle\,}}} \right)}}{{2\left( {{\lambda _{\scriptstyle0\atop\scriptstyle\,}} + n} \right)}}^2}.\)

Next, get the data from the two mentioned examples. There is a total of observations. Recall the following product of the likelihood and the prior distribution

\(\xi \left( {\mu ,\tau \mid x} \right)\infty \left\{ {{\tau ^{1/2}}{\rm{ }}exp\left( { - \frac{1}{2}{\lambda _{\scriptstyle1\atop\scriptstyle\,}}\tau {{\left( {\mu - {\mu _{\scriptstyle1\atop\scriptstyle\,}}} \right)}^2}} \right)} \right\}{\tau ^{{\alpha _{\scriptstyle1\atop\scriptstyle\,}}}}\exp \left( { - {\beta _{\scriptstyle1\atop\scriptstyle\,}}{\rm{ }}\tau } \right).\)

This equation may also be written as

\(\xi \left( {\mu ,\tau \mid x} \right)\infty \,\,{\tau ^{{\alpha _{\scriptstyle1 + 1/2 - 1\atop\scriptstyle\,}}}}exp\left\{ { - \tau {\rm{ }}exp\left( { - \frac{1}{2}{\lambda _{\scriptstyle1\atop\scriptstyle\,}}\tau {{\left( {\mu - {\mu _{\scriptstyle1\atop\scriptstyle\,}}} \right)}^2} + {\beta _{\scriptstyle1\atop\scriptstyle\,}}} \right)} \right\}\,\,\,(1)\)

Values \({\alpha _{\scriptstyle1\atop\scriptstyle\,}}\,,\,{\beta _{\scriptstyle1\atop\scriptstyle\,}},{\rm{ }}{\mu _{\scriptstyle1\atop\scriptstyle\,}},{\rm{ }}{\lambda _{\scriptstyle1\atop\scriptstyle\,}}{\rm{ }}\)shall be computed using the \({\rm{n = 30}}\)observations and the comment above.

From Eq\(\left( 1 \right)\). it is true that for fixed τ and μ as arguments of the function, is proportional to a probability density function of the normal distribution with mean\({\mu _{\scriptstyle1\atop\scriptstyle\,}}\) and variance\(1/\left( {\tau {\lambda _{\scriptstyle1\atop\scriptstyle\,}}{\rm{ }}} \right)\)

From Eq\(\left( 1 \right)\). it is true that for fixed μ and τ as arguments of the function, is proportional to a probability density function of the gamma distribution with parameters \({\alpha _{\scriptstyle1\atop\scriptstyle\,}}\, + {\raise0.7ex\hbox{$1$} \!\mathord{\left/ {\vphantom {1 2}}\right.\\} \!\lower0.7ex\hbox{$2$}}\,\) and \(\,{\lambda _{\scriptstyle1\atop\scriptstyle\,}}\tau {\left( {\mu - {\mu _{\scriptstyle1\atop\scriptstyle\,}}} \right)^2} + {\beta _{\scriptstyle1\atop\scriptstyle\,}}\)

The Gibbs Sampling Algorithm:

The steps of the algorithm are

\(\left( {1.} \right)\,\)Pick starting values \({x_2}^{\left( 0 \right)}\) for \(\,{x_2}\) , and let \(\,\,i = 0\,\)

\(\left( {2.} \right)\,\)let be a simulated value from the conditional distribution of \(\,{x_1}\)given that \(\,\,{X_1} = {x_2}^{\left( i \right)}\)

\(\left( {3.} \right)\,\)Let\(\,{x_2}^{\left( {i + 1} \right)\,\,}\,\) be a simulated value from the conditional distribution \(\,{x_2}\) given that \(\,{X_1} = {x_1}^{\left( {i + 1} \right)}\)

\(\left( {4.} \right)\)Repeat steps \(\,2.\,\,and\,3.\) \(\,i\) where\(\,i + 1\)

The number of simulations I , shall be large enough. The given code below gives all required values and the algorithm itself. The initial hyperparameters of the prior distributions are

\({\lambda _{\scriptstyle0\atop\scriptstyle\,}} = 1,\,\,\,{\mu _{\scriptstyle0\atop\scriptstyle\,}} = 1,\,\,\,{\alpha _{\scriptstyle0\atop\scriptstyle\,}}\, = 0.5,\,\,\,\,\,{\beta _{\scriptstyle0\atop\scriptstyle\,}} = 0.5\)

02

Prior parameters

\(data{\rm{ }} = {\rm{ }}c\left( \begin{aligned}{l}0.86,{\rm{ }}1.53,{\rm{ }}1.57,{\rm{ }}1.81,{\rm{ }}0.99,{\rm{ }}1.09,{\rm{ }}1.29,{\rm{ }}1.78,{\rm{ }}\\1.29,{\rm{ }}1.58,{\rm{ }}1.68,{\rm{ }}1.9,{\rm{ }}1.06,{\rm{ }}1.3,{\rm{ }}1.52,{\rm{ }}1.74,{\rm{ }}\\1.16,{\rm{ }}1.49,{\rm{ }}1.63,{\rm{ }}1.99,{\rm{ }}1.15,{\rm{ }}1.33,{\rm{ }}1.44,{\rm{ }}2.01,{\rm{ }}\\1.31,{\rm{ }}1.46,{\rm{ }}1.72,{\rm{ }}1.25,{\rm{ }}1.08,{\rm{ }}1.25\end{aligned} \right)\)

\(\begin{aligned}{*{20}{l}}{n{\rm{ }} = {\rm{ }}length\left( {data} \right)}\\{\;\# initialization{\rm{ }}of{\rm{ }}the{\rm{ }}prior{\rm{ }}hyperparameters}\end{aligned}\)

\(\begin{aligned}{l}\,\,mu0{\rm{ }} &= {\rm{ }}1{\rm{ }}\\\,\,lambda0 &= {\rm{ }}1\\{\rm{ }}alpha0 &= 0.5{\rm{ }}\\\,\,beta0{\rm{ }} &= {\rm{ }}0.5{\rm{ }}\\\,\,\# initialization{\rm{ }}of{\rm{ }}the{\rm{ }}posterior{\rm{ }}parameters\end{aligned}\)

\(\# using{\rm{ }}the{\rm{ }}comment{\rm{ }}in{\rm{ }}the{\rm{ }}exercise\)\(\begin{aligned}{l}\,AvgXn{\rm{ }} &= {\rm{ }}mean\left( {data} \right)\\{\rm{ }}mu1{\rm{ }} &= {\rm{ }}\left( {lambda0*mu0{\rm{ }} + {\rm{ }}n*AvgXn} \right)/\left( {lambda0{\rm{ }} + {\rm{ }}n} \right){\rm{ }}\\lambda1{\rm{ }} &= {\rm{ }}lambda0{\rm{ }} + {\rm{ }}n\end{aligned}\)

\(\# initialization{\rm{ }}for{\rm{ }}the{\rm{ }}simulation\)

\(\begin{aligned}{l}I{\rm{ }} &= {\rm{ }}10000{\rm{ }}\\mu{\rm{ }} &= {\rm{ }}rep\left( {NA,{\rm{ }}I} \right){\rm{ }}\\tau{\rm{ }} &= {\rm{ }}rep\left( {NA,{\rm{ }}I} \right){\rm{ }}\\BurnIn{\rm{ }} &= {\rm{ }}100{\rm{ }}\end{aligned}\)

\(\begin{aligned}{l}EstimatedMean{\rm{ }} &= {\rm{ }}rep\left( {NA,{\rm{ }}5} \right)\\SimulationSD{\rm{ }} &= {\rm{ }}rep\left( {NA,{\rm{ }}5} \right)\end{aligned}\)

\(\begin{aligned}{l}\# initialization{\rm{ }}for{\rm{ }}the{\rm{ }}Markov{\rm{ }}chains{\rm{ }}\\\# the{\rm{ }}starting{\rm{ }}values{\rm{ }} - {\rm{ }}5{\rm{ }}chains\\\# mu\left( 1 \right){\rm{ }} &= {\rm{ }}c\left( {0.4,{\rm{ }}0.7,{\rm{ }}1,{\rm{ }}1.3,{\rm{ }}1.7} \right)\\muVec{\rm{ }} &= {\rm{ }}c\left( {0.4,{\rm{ }}0.7,{\rm{ }}1,{\rm{ }}1.3,{\rm{ }}1.7} \right)\end{aligned}\)

\(\begin{aligned}{l}for\left( {j{\rm{ }}in{\rm{ }}1:5} \right)\{ {\rm{ }}\\mu\left( 1 \right){\rm{ }} = {\rm{ }}muVec\left( j \right){\rm{ }}\\for\left( {i{\rm{ }}in{\rm{ }}2:I} \right)\{ \end{aligned}\)

\(\begin{aligned}{l}tau(i) = rgamma(1,shape &= alpha1 + 1/2,\,\,\,\\scale &= lambda1*{(mu(i - 1) - mu1)^2}/2 + beta1)mu(i) &= rnorm(1,mean = \\mu1,sd &= sqrt(1/(tau(i)*lambda1)))\end{aligned}\)

\(\begin{aligned}{l}\,mu{\rm{ }} &= {\rm{ }}mu\left( { - \left( {1:BurnIn} \right)} \right)\\{\rm{ }}tau{\rm{ }} &= {\rm{ }}tau\left( { - \left( {1:BurnIn} \right)} \right)\end{aligned}\)

\(\begin{aligned}{l}{\rm{ }}\# find{\rm{ }}mean{\rm{ }}for{\rm{ }}each{\rm{ }}chain\\{\rm{ }}EstimatedMean\left( j \right){\rm{ }} = {\rm{ }}mean\left( {1/\left( {sqrt\left( {tau} \right)*{\rm{ }}mu} \right)} \right)\\{\rm{ }}SimulationSD\left( j \right){\rm{ }} = {\rm{ }}sd\left( {1/\left( {sqrt\left( {tau} \right)*mu} \right)} \right)/1000\} \end{aligned}\)

\(\begin{aligned}{l}mu{\rm{ }} &= {\rm{ }}mu\left( { - \left( {1:BurnIn} \right)} \right){\rm{ }}\\tau{\rm{ }} &= {\rm{ }}tau\left( { - \left( {1:BurnIn} \right)} \right){\rm{ }}\\\\\# the{\rm{ }}final{\rm{ }}estimate{\rm{ }}FinalEstimate{\rm{ }} &= {\rm{ }}mean\left( {EstimatedMean} \right){\rm{ }}\\FinalSimulationSD{\rm{ }} &= {\rm{ }}mean\left( {SimulationSD} \right)\end{aligned}\)

The initial result obtained with the code is

\({\alpha _{\scriptstyle1\atop\scriptstyle\,}}{\rm{ }} = {\rm{ }}15.5,{\rm{ }}{\lambda _{\scriptstyle1\atop\scriptstyle\,}}{\rm{ }} = {\rm{ }}31,{\rm{ }}{\mu _{\scriptstyle1\atop\scriptstyle\,}}{\rm{ }} = 1.4277,{\rm{ }}{\beta _{\scriptstyle1\atop\scriptstyle\,}} = 0.6406\)

Then, after the simulation, the estimate of the mean is

\(1/{\left( {\sqrt {\tau \mu } } \right)^{ - 1}}\)

\(est{\rm{ }} = {\rm{ }}0.2171,\)

and the simulation standard error is close to \(3.11 \times {10^{ - 5}}\)

Hence,

\(est{\rm{ }} = {\rm{ }}0.2171,\,\,\,\,3.11 \times {10^{ - 5}}\)

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Use the data in table 11.19 on page 762.This time fits the model developed in Example 12.5.6.use the prior hyperparameters \(\,{{\bf{\lambda }}_{\scriptstyle{\bf{0}}\atop\scriptstyle\,}}{\bf{ = }}{{\bf{\alpha }}_{\scriptstyle{\bf{0}}\atop\scriptstyle\,}}\,{\bf{ = 1,}}\,\,{{\bf{\beta }}_{\scriptstyle{\bf{0}}\atop\scriptstyle\,}}{\bf{ = 0}}{\bf{.1}},{{\bf{\mu }}_{\scriptstyle{\bf{0}}\atop\scriptstyle\,}}{\bf{ = 0}}{\bf{.001}}\)and \({{\bf{\psi }}_{\scriptstyle{\bf{0}}\atop\scriptstyle\,}}{\bf{ = 800}}\)obtain a sample of 10,000 from the posterior joint distribution of the parameters. Estimate the posterior mean of the three parameters \({{\bf{\mu }}_{\scriptstyle{\bf{1}}\atop\scriptstyle\,}}{\bf{,}}{{\bf{\mu }}_{\scriptstyle{\bf{2}}\atop\scriptstyle\,}}{\bf{,}}{{\bf{\mu }}_{\scriptstyle{\bf{3}}\atop\scriptstyle\,}}\)

Let \({\bf{f}}\left( {{{\bf{x}}_{{\bf{1}}\,}}{\bf{,}}{{\bf{x}}_{{\bf{2}}\,}}} \right){\bf{ = cg}}\left( {{{\bf{x}}_{{\bf{1}}\,}}{\bf{,}}{{\bf{x}}_{{\bf{2}}\,}}} \right)\) be a joint p.d.f for \(\left( {{{\bf{x}}_{{\bf{1}}\,}}{\bf{,}}{{\bf{x}}_{{\bf{2}}\,}}} \right){\bf{,}}\)each \({x_{2\,}}\)let\({{\bf{h}}_{{\bf{2}}\,}}\left( {{{\bf{x}}_{{\bf{1}}\,}}} \right){\bf{ = g}}\left( {{{\bf{x}}_{{\bf{1}}\,}}{\bf{,}}{{\bf{x}}_{{\bf{2}}\,}}} \right)\) that is what we get by considering \({\bf{g}}\left( {{{\bf{x}}_{{\bf{1}}\,}}{\bf{,}}{{\bf{x}}_{{\bf{2}}\,}}} \right)\) as a function of \({{\bf{x}}_{{\bf{1}}\,}}\)for fixed \({{\bf{x}}_{2\,}}\)show that there is a multiplicative factor \({{\bf{c}}_{{\bf{2}}\,}}\)that does not depend on such that is the conditional p.d.f of \({{\bf{x}}_{{\bf{1}}\,}}\) given \(\left( {{{\bf{x}}_{{\bf{2}}\,}}{\bf{,}}{{\bf{x}}_{{\bf{2}}\,}}} \right)\)

Test the t pseudo-random number generator on your computer. Simulate 10,000 t pseudo-random variables with m degrees of freedom for m=1,2,5,10,20. Then draw t quantile plots

Let \(U\) have the uniform distribution on the interval\((0,1)\). Show that the random variable \(W\)defined in Eq. (12.4.6) has the p.d.f. \(h\)defined in Eq. (12.4.5).

Show how to simulate Cauchy random variables using the probability integral transformation.

See all solutions

Recommended explanations on Math Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free