Books in black and white
 Books Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

# Introduction to Bayesian statistics - Bolstad M.

Bolstad M. Introduction to Bayesian statistics - Wiley Publishing, 2004. - 361 p.
ISBN 0-471-27020-2 Previous << 1 .. 109 110 111 112 113 114 < 115 > 116 117 118 119 120 121 .. 126 >> Next USING THE INCLUDED MINITAB MACROS 311 Table C.6 Minitab commands for Bayesian inference on n with a continuous prior
Minitab Commands
Meaning
%<insert path>BinoGCP.mac 12 ;
prior c1 c2
observation 4;
likelihood c3;
posterior c4.
"n=12 trials"
"inputs n in c1, prior g(n) in c2" "y=4 successes observed"
"store likelihood in c3"
"store posterior g(n|y = 4) in c4"
Table C.7 Minitab commands to integrate posterior density of n
Minitab Commands
Meaning
%<insertpath>tintegral.mac c1 c4; output k1 c6.
"integrates posterior density"
"stores definite integral over range in k1" "stores definite integral function in c6"
print c1 c6
commands from Table c.6 into the command line editor. The output of BinoGCP.mac does not print out the posterior mean and standard deviation. Neither does it print out the values that give the tail areas of the integrated density function that we need to determine credible interval for n. Instead we use the macro tintegral.mac which numerically integrates a function over its range to determine these things. We can find the integral of the posterior density g(n|y) using this macro. In the "edit" menu pull down "command line editor" and type the commands from Table C.7 into the command line editor. To find a 95% credible interval (with equal tail areas) we find the values in c1 that correspond to .025 and .975 in c6 respectively. We can also find the posterior mean and variance by numerically evaluating
using the macro tintegral.mac. In the "edit" menu pull down "command line editor" and type the commands from Table C.8 into the command line editor.
CHAPTER 10: BAYESIAN INFERENCE FOR NORMAL MEAN Discrete Prior for д
m
and
NormDP. mac is used to find the posterior when we have a column of normal (m, a2) observations and a2 is known, and we have a discrete prior for ^. For example,
312 USING THE INCLUDED MINITAB MACROS
Table C.8 Minitab commands to find posterior mean and variance
Minitab Commands Meaning
let c7=c1*c4 "n x g(n|y)
%<insertpath>tintegral.mac c1 c7; "finds posterior mean"
output k1 c8.
let c9=(c1-k1)**2 * c4
%<insert path>tintegral.mac c1 c9; "finds posterior variance"
output k2 c10.
let k3=sqrt(k2) "finds posterior st. deviation"
print k1-k3
Table C.9 Discrete prior distribution for ^
p f (n)
2 .2
2.5 .2
3 .4
3.5 .2
4 .1
suppose p has the discrete distribution with 5 possible values, 2 2.5, 3, 3.5 and ,4. Suppose the prior distribution is given in Table C.9. and we want to find the posterior distribution after a random sample of n = 5 observations from a normal (p, a2 = 1) that are 1.52, 0.02, 3.35, 3.49 1.82 . In the "edit" menu pull down "command line editor" and type the commands from Table C.10 into the command line editor.
Normal(m, s2) Prior for ц
NormNP.mac is used when we have a column c5 containing a random sample of n observations from a normal (p, a2) distribution (with a2 known) and we use a normal (m,s2) prior distribution. The normal family of priors is conjugate for normal (p, a2) observations, so the posterior will be another member of the family, normal[m', (s')2] where the new constants are given by
1=1 n
(s')2 s2 Н a2
and
1 n
' b2 i <r2 —
m = —^— x m Н—j— x y
W) W)
USING THE INCLUDED MINITAB MACROS 313
Table C.10 Minitab commands for Bayesian inference on ^ with discrete prior
Minitab Commands Meaning
set c1 puts "p in c1"
2:4/.5
end
set c2 "puts g(p) in c2
.1 .2 .4 .2 .1
end
set c5 "puts data in c5
1.52,0.02,3.35,3.49 1.82
end
%<insert path>NormDP.mac c5 1; "observed data in c5, known a = 1"
prior c1 c2 "p in c1, prior g(p) in c2"
likelihood c3; "store likelihood in c3"
posterior c4. "store posterior g(pldata) in c4"
Table C.11 Minitab commands for Bayesian inference on ^ with normal prior
Minitab Commands Meaning
set c5 "puts data in c5
2.99,5.56, 2.83, and 3.47
end
%<insertpath>NormNP.mac c5 1; "observed data in c5, known a = 1"
norm 3 2 "prior mean 3, prior std 2"
prior c1 c2 "store p in c1, prior g(p) in c2"
likelihood c3; "store likelihood in c3"
posterior c4. "store posterior g(pldata) in c4"
For example, suppose we have a normal random sample of 4 observations from normal (p, a2 = 1) which are 2.99, 5.56, 2.83, and 3.47. Suppose we use a normal (3,22) prior for p. In the "edit" menu pull down "command line editor" and type the commands from Table C.11 into the command line editor. We can determine an (equal tail area) credible interval for p either by looking at the values of y1 corresponding to the desired values of invf printed out by NormNP.mac. We can find the posterior mean and variance from the output.
314 USING THE INCLUDED MINITAB MACROS
Table C.12 Minitab commands for Bayesian inference on ^ with continuous prior
Minitab Commands Meaning
set c5 "puts data in c5
2.99,5.56, 2.83, and 3.47
end
%<insertpath>NormGCP.mac c5 1; "observed data in c5, known a = 1"
prior c1 c2 "p in c1, prior g(p) in c2"
likelihood c3; "store likelihood in c3" Previous << 1 .. 109 110 111 112 113 114 < 115 > 116 117 118 119 120 121 .. 126 >> Next 