Sample 500 variates starting with x 0 ¼À4anda ¼ 0:5. Note the long burn-in time and poor exploration of the state space (slow mixing of states) due to the small step length. 2 6 4 > seed:=randomize(59274); x:=mcmc(-4,0.5,500): PLOT(CURVES(x),TITLE("x-value against iteration number:a=0.5 "),AXESSTYLE(NORMAL)); seed:=59274 x-value against iteration number: a = 0.5 3 2 1 –1 –2 –3 –4 100 200 300 500 0 400 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 Now repeat w ith a ¼ 3. The situation is much improved in both respects. Note that prospective variates are fre quently rejected (horizontal sections of plot), resulting in no change in the variate from one iteration to the next. 2 6 6 6 4 > seed:=randomize(59274); x:=mcmc(-4,3,500): PLOT(CURVES(x),TITLE("x-value against iteration number:a=3"),A XESSTYLE(NORMAL)); seed:= 59274 x-value against iteration number: a = 3 2 1 –1 –2 –3 –4 100 200 300 400 500 0 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 300 Appendices Sample 100 000 variates, starting with initial value of 0, to produce a histogram showing their distribution, together with sample mean and variance. 2 6 4 > seed:=randomize(59274); x:=mcmc(-4,3,100000): res:= [ seq(op(2,x [ t ] ),t=1 100000) ] : histogram(res,title="distribution of sampled x- values",labels= [ "x","density" ] ,numbars=100); Mean=describe [ mean ] (res);StdDev=describe [ standarddeviation ] (res); seed:= 59274 distribution of sampled x-values 0.4 0.3 0.2 0.1 0 density –4 –2 2 4 x 0.4 0.3 0.2 0.1 Mean = 0.0001202304356 StdDev = 1.006266364 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 > h 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 8.2 Reliability inference We are interested in determining survival probabilities for co mponents. The age at failure of the ith component is X i ; i ¼ 1; 2; These are i.i.d. 2 6 6 6 6 6 4 6 6 6 6 6 6 6 6 6 6 4 Appendices 301 Weibull random variables with parameters and , where the joint prior distribution is gð; Þ¼ 4 1000 ð À1ÞÀ 1 þ 1 ; 1 <<1:5; 4 1000 ð2 ÀÞÀ 1 þ 1 ; 1:5 <<2; 8 > > > < > > > : and 2000=Àð1= þ1Þ <<3000=Àð1= þ1Þ. Then the joint posterior density given the data fx i ; i ¼ 1; ; ng is ð; Þ/ n Àn exp À X n i¼1 x i "# ðx 1 ÁÁÁx n Þ À1 gð; Þ: Using an independence sampler with the proposal density equal to the joint prior, and given that the current point is ð; Þ, the acceptance probability for a candidate pointð c ; c Þ is min 1; n c Àn c c exp À X n i¼1 x i c c "# ðx 1 ÁÁÁx n Þ c À1 n Àn exp À X n i¼1 x i "# ðx 1 ÁÁÁx n Þ À1 8 > > > > < > > > > : 9 > > > > = > > > > ; The candidate point is generated from the joint prior by noting that the marginal prior of c is a symmetric triangular density on supp ort (1,2). Therefore, given two uniform random numb ers R 1 and R 2 , we set c ¼ 1 þ0:5ðR 1 þ R 2 Þ: Given c , the conditional prior density of c is U 2000 Àð1= c þ 1Þ ; 3000 Àð1= c þ 1Þ so we set c ¼ 1000ð2 þR 3 Þ Àð1= c þ 1Þ : The procedure ‘fail’ performs k iterations of this independence sampler. It returns a matrix C having k rows and q þ 2 columns. The first q elements of the ith row give sampled survivor probabilities at specified ages y½1; ; y½q. The last two elements of the ith row give the sampled alpha and beta at this ith iteration (point). The plots show that the burn-in time is 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 302 Appendices negligible and that the mixing of states is quite reasonable. Bayes estimates are given for survival probabilities at ages 1000, 2000, and 3000 hours. Of course, if interval estimates are required it will be necessary to replicate these runs. It is instructive to see the effect of reducing the sample size (discard some of the original 43 ages at failure). The posterior density should then reflect the prior density more so, with the result that the acceptance probability becomes higher and successive and values are less correlated than previously. This is good from the viewpoint of reducing the variance of estimators. 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 > restart; h Here x is a list of 43 ages (in hours) at failure. h > x:= [ 293, 1902, 1272, 2987, 469, 3185, 1711, 8277, 356, 822,2303, 317, 1066, 1181, 923, 7756, 2656, 879, 1232, 697, 3368, 486, 6767, 484, 438, 1860, 113, 6062, 590, 1633, 2425, 367, 712, 953, 1989, 768, 600, 3041, 1814, 141, 10511, 7796, 1462 ] ; x :¼ [293, 1902, 1272, 2987, 469, 3185, 1711, 8277, 356, 822, 2303, 317, 1066, 1181, 923, 7756, 2656, 879, 1232, 697, 3368, 486, 6767, 484, 438, 1860, 113, 6062, 590, 1633, 2425, 367, 712, 953, 1989, 768, 600, 3041, 1814, 141, 10511, 7796, 1462] 2 6 6 6 6 6 6 6 6 6 6 6 6 6 4 The procedure ‘fail’ returns the simulation output from the MCMC. h > fail:=proc(k,a,b,n,x,q,y) local a1,b1,C,xp,sp,u,L1,i,r1,r2,r3,r4,r5,r6,mp,ap,rate,bp,L2,j; # k=# of iterat ions; # (a,b)=initial(alpha,beta); # x= failure data; # n=number of data items in x; # q=number of ages at which survivor probabilities are required; # y [ i ] =age at which a survivor probability is required for i=1 q a1:=a;b1:=b; C:=Matrix(k,q+2); # Compute log likelihood ( L1) for current point (a1,b1); xp:=1; sp:=0; for u from 1 to n do; xp:=xp*x [ u ] ; sp:=sp+x [ u ] ^a1; end do; xp:=ln(xp); L1:=evalf(n*ln(a1/b1^a1)+(a1-1)*xp-sp/b1^a1); 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6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 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 Appendices 303 # Perform k iterations; for i from 1 to k do; r1:=evalf(rand()/10^12);r2:=evalf(rand()/10^12);r3:=evalf (rand()/1 0^12);r4:=evalf(rand()/10^12); # Sample candidate point (ap,bp) and compute likelihood (L2)for (ap,bp); ap:=1+0. 5*(r1+r2); bp:=1000*(2+r3)/GAMMA(1/ap+1); sp:=0; for u from 1 to n do; sp:=sp+x [ u ] ^ap; end do; L2:=evalf(n*ln(ap/bp^ap)+(ap-1)*xp-sp/bp^ap); # Decide whether to accept or reject candidate point; i f ln(r4)<L2-L1 then a1:=ap; b1:=bp; L1:=L2; end if; # Enter survivor probs and alpha and beta values into ith row of C; for j from 1 to q do; C [ i,j ] :=evalf(exp(-(y [ j ] /b1)^a1)); end do; C [ i,q+1 ] :=evalf(a1);C [ i,q+2 ] :=evalf(b1); end do; C; end proc: 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 Set up parameter values. A sensible choice for initial is the mode of the prior marginal. The initial is set to the mode of its prior given . " > n:=43;a:=1.5;b:=2500/GAMMA(1/a+1);k:=5000;q:=3;y:=Vector (q);y [ 1 ] :=1000;y [ 2 ] :=2000;y [ 3 ] :=3000;y; n :=43 a :=1.5 b :=2769.330418 k :=5000 q :=3 y :¼ 0 0 0 2 4 3 5 y 1 :¼ 1000 y 2 :¼ 2000 y 3 :¼ 3000 1000 2000 3000 2 4 3 5 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 304 Appendices Perform 5000 iterations. h > randomize(561293);d:=fail(k,a,b,n,x,q,y); 561293 d :¼ 5000  5 Matrix Data Type: anything Storage: rectangular Order: Fortran order 2 6 6 4 3 7 7 5 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 > f:=Matrix(k,q+2); f :¼ 5000  5 Matrix Data Type: anything Storage: rectangular Order: Fortran order 2 6 6 4 3 7 7 5 2 6 6 6 6 6 6 6 6 6 6 6 6 4 > for i from 1 to k do: for j from 1 to q+2 do: f [ i,j ] := [ i,d [ i,j ]] : end do; end do: 2 6 6 6 6 6 4 Plot diagnostics for survivor probabilities and compute point estimates. h > f3:= [ seq(f [ i,3 ] ,i=1 k) ] :PLOT(CURVES(f3),TITLE("survival probability at 3000 hours against iteration number:"),AXESSTYLE(NORMAL)); wi th(stats [ statplots ] ):dat3:= [ seq(op(2,f3 [ i ] ),i=1 k) ] : Estimate_Prob_survive_3000_hours=describe [ mean ] (dat3); survival probability at 3000 hours against iteration number: 0.4 0.3 0 2000 4000 Estimate_Prob_survive_3000_hours = 0.2867886198 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 Appendices 305 > f2:= [ seq(f [ i,2 ] ,i=1 k) ] :PLOT(CURVES(f2),TITLE("survival probability at 2000 hours against iteration number:"),AXESSTYLE(NORMAL)); da t2:= [ seq(op(2,f2 [ i ] ),i=1 k) ] :Estimate_Prob_ survive_2000_hours=describe [ mean ] (dat2); survival probability at 2000 hours against iteration number: 0.55 0.5 0.45 0.4 0 1000 2000 3000 4000 5000 Estimate_Prob_survive_2000_hours =0.4529730938 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 > f1:= [ seq(f [ i,1 ] ,i=1 k) ] :PLOT(CURVES(f1),TITLE("survival probability at 1000 hours against iteration number:"),AXESSTYLE(NORMAL)); da t1:= [ seq(op(2,f1 [ i ] ),i=1 k) ] :Estimate_Prob_survive_1000 _hours=describe [ mean ] (dat1); 0.8 0.75 0.65 0 1000 survival probability at 1000 hours against iteration number: 2000 3000 4000 5000 0.7 Estimate_Prob_survive_1000_hours = 0.6952910744 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 Plot diagnostics for and together with empirical pos terior marginal densities. " > f5:= [ seq(f [ i,5 ] ,i=1 k) ] :PLOT(CURVES(f5),TITLE("beta values against iteration number"),AXESSTYLE(NORMAL)); dat5:= [ seq(op(2,f5 [ i ] ),i=1 k) ] :histogram(dat5);Bayes_ estimate_beta=describe [ mean ] (dat5); 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 306 Appendices beta values against iteration number 3200 3000 2800 2600 2400 2200 0 1000 2000 3000 4000 5000 0 2000 2200 2400 2600 2800 3000 3200 0.0015 0.001 0.0005 Bayes_estimate_beta = 2470.294876 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 > f4:= [ seq(f [ i,4 ] ,i=1 k) ] :PLOT(CURVES(f4),TITLE("alpha values against iteration number"),AXESSTYLE(NORMAL)); dat4:= [ seq(op(2,f4 [ i ] ),i=1 k) ] :histogram(dat4); Bayes_estimate_alpha=describe [ mean ] (dat4); alpha values against iteration number 0 1000 2000 3000 4000 5000 1.4 1.3 1.2 1.1 1 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 4 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 Appendices 307 6 5 4 3 2 1 0 1 1.1 1.2 1.3 1.4 Bayes_estimate_alpha = 1.131475342 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 The estimate for indicates that the components have a slowly increasing failure rate. It is left as an exercise (Problem 8.3) to mod ify the procedure ‘fail’ so as to obtain an estimate of the posterior expected time to failure of a component. It is not sufficient merely to substitute the Bayes estimates for and into Àð1= þ 1Þ. How do the Bayesian estimates compare with a classical analysis, using maximization of the likelihood function, subject to 1 <? (The parameter space is restricted to the space used for the prior. This ensures that the asymptotic Bayes and likelihood estimates would be identical.) Below, the unrestricted likelihood function, L1, and its contour plot are computed. This has a global maximum at ^ ¼ 0:97. Using NLPsolve from the optimization package, the constrained maximum is at ^ ¼ 1; ^ ¼ 2201. This represents a component with a constant failure rate (exponential life) and an expected time to failure of 2201 hours. 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 > with(plots): h > xp:=1: sp:=0: for u from 1 to n do: xp:=xp*x [ u ] : sp:=sp+x [ u ] ^a1: end do: xp:=ln(xp): L1:=evalf(n*ln(a1/b1^a1)+(a1-1)*xp-sp/b1^a1): 2 6 6 6 6 6 6 6 6 6 6 6 4 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6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 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 308 Appendices > contourplot(exp(L1),a1=0.5 2,b1=1300 4000,contours=30, grid= [ 100,100 ] ); 3000 2500 2000 1500 0.7 0.8 0.9 1.1 1.21 a1 b1 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 > with(Optimization); [ImportMPS, Interactive, LPSolve, LSSolve, Maximize, Minimize, NLPSolve, QPSolve ] 2 6 4 > NLPSolve(-L1, a1=1 2,b1=1000 3000); [373.966224564945776, [ bl = 2201.48837205595191, al =1.]] " 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 8.3 Pump failure The data are from D.P. Gaver and I.G. O’Muircheartaigh (1987), Robust empirical Bayes analyses of event rates, Technometrics 29, 1–15. The number of failures for pump i in time t½iði ¼ 1; ; 10Þ; x½i, are assumed to be i.i.d. Poissonð i t i Þ where i are i.i.d. gamma ½; and is a realization from gamma [,gam]. The hyperparameters ; , and gam have been esti- mated as described in the text. 6 6 6 6 6 6 6 6 6 6 6 6 6 4 Appendices 309 [...]... 1 to k do; r1:=evalf(rand() /10^ 12);r2:=evalf(rand() /10^ 12);r3:=evalf (rand() /10^ 12);r4:=evalf(rand() /10^ 12); # Sample candidate point (ap,bp) and compute likelihood (L2)for (ap,bp); ap:=1+0.5*(r1+r2); bp: =100 0*(2+r3)/GAMMA(1/ap+1); sp:=0; for u from 1 to n do; sp:=sp+x[u]^ap; end do; L2:=evalf(n*ln(ap/bp^ap)+(ap-1)*xp-sp/bp^ap); # Decide whether to accept or reject candidate point; if ln(r4) > X xi > > 6 > > > n Àn exp À ðx1 Á Á Á xn ÞÀ1 > 6 ; : 6 i¼1 6 6 6 6 The candidate point is generated from the joint prior by noting that the 6 6 marginal prior of c is a symmetric triangular density... at ages 100 0, 2000, and 3000 hours Of 6 6 course, if interval estimates are required it will be necessary to replicate these 6 6 runs It is instructive to see the effect of reducing the sample size (discard 6 6 some of the original 43 ages at failure) The posterior density should then 6 6 reflect the prior density more so, with the result that the acceptance 6 6 probability becomes higher and successive... probs and alpha and beta values into ith row of C; for j from 1 to q do; C[i,j]:=evalf(exp(-(y[j]/b1)^a1)); end do; C[i,q+1]:=evalf(a1);C[i,q+2]:=evalf(b1); end do; C; end proc: " Set up parameter values A sensible choice for initial is the mode of the prior marginal The initial is set to the mode of its prior given 2 6 > n:=43;a:=1.5;b:=2500/GAMMA(1/a+1);k:=5000;q:=3;y:=Vector 6 (q);y[1]: =100 0;y[2]:=2000;y[3]:=3000;y;... have a slowly increasing 6 6 6 failure rate It is left as an exercise (Problem 8.3) to modify the procedure 6 6 6 6 6 ‘fail’ so as to obtain an estimate of the posterior expected time to failure of a 6 6 6 6 component It is not sufficient merely to substitute the Bayes estimates for 6 6 6 6 6 and into Àð1= þ 1Þ 6 6 6 6 How do the Bayesian estimates compare with a classical analysis, using 6 6 6 6... contourplot(exp(L1),a1=0.5 2,b1=1300 4000,contours=30, grid= [100 ,100 ]); 3000 2500 b1 2000 1500 0.7 0.8 0.9 1 a1 1.1 1.2 2 > with( Optimization); 6 4 [ImportMPS, Interactive, LPSolve, LSSolve, Maximize, Minimize, NLPSolve, QPSolve ] " > NLPSolve(-L1, a1=1 2,b1 =100 0 3000); [373.966224564945776, [bl = 2201.48837205595191, al =1.]] 8.3 Pump failure The data are from D.P Gaver and I.G O’Muircheartaigh (1987), Robust empirical... i in time t½i ði ¼ 1; ; 10 ; x½i, are assumed to be i.i.d Poissonði ti Þ where i are i.i.d gamma ½; and is a realization from gamma [,gam] The hyperparameters ; , and gam have been estimated as described in the text 309 310 6 6 6 6 6 6 6 Appendices 6 6 6 6 6 6 The procedure ‘pump’ returns, for each pump i, a list of simulated 6 6 i ; ½i; i ; ð þ xi Þ=ð þ ti Þ values The latter are individual... Therefore, given two uniform random numbers R1 and R2 , we set 6 6 6 6 c ¼ 1 þ 0:5ðR1 þ R2 Þ: 6 6 6 6 Given c , the conditional prior density of c is 6 6 6 6 6 2000 3000 6 ; U 6 Àð1=c þ 1Þ Àð1=c þ 1Þ 6 6 6 6 so we set 6 6 100 0ð2 þ R3 Þ 6 : c ¼ 6 Àð1=c þ 1Þ 6 6 6 6 The procedure ‘fail’ performs k iterations of this independence sampler It 6 6 returns a matrix C having k rows and q þ 2 columns The first... asymptotic Bayes and likelihood estimates would be identical.) Below, the 6 6 6 6 unrestricted likelihood function, L1, and its contour plot are computed This 6 6 6 6 has a global maximum at ¼ 0:97 Using NLPsolve from the optimization ^ 6 6 6 ^ 6 package, the constrained maximum is at ¼ 1; ¼ 2201 This represents a 6 ^ 6 6 4 component with a constant failure rate (exponential life) and an expected . do; r1:=evalf(rand() /10^ 12);r2:=evalf(rand() /10^ 12);r3:=evalf (rand()/1 0^12);r4:=evalf(rand() /10^ 12); # Sample candidate point (ap,bp) and compute likelihood (L2)for (ap,bp); ap:=1+0. 5*(r1+r2); bp: =100 0*(2+r3)/GAMMA(1/ap+1); sp:=0; for. Þ: Using an independence sampler with the proposal density equal to the joint prior, and given that the current point is ð; Þ, the acceptance probability for a candidate pointð c ; c Þ is min. Appendices Sample 100 000 variates, starting with initial value of 0, to produce a histogram showing their distribution, together with sample mean and variance. 2 6 4 > seed:=randomize(59274); x: =mcmc( -4,3 ,100 000): res:= [ seq(op(2,x [ t ] ),t=1