Transcription of MAS3301 Bayesian Statistics Problems 3 and Solutions
1 MAS3301 Bayesian StatisticsProblems 3 and SolutionsSemester 22008-9 Problems 31. In a small survey, a random sample of 50 people from a large population is selected. Eachperson is asked a question to which the answer is either Yes or No. Let the proportion inthe population who would answer Yes be .Our prior distribution for is a beta( , )distribution. In the survey, 37 people answer Yes. (a) Find the prior mean and prior standard deviation of .(b) Find the prior probability that < (c) Find the likelihood.(d) Find the posterior distribution of .(e) Find the posterior mean and posterior standard deviation of .(f) Plot a graph showing the prior and posterior probability density functions of on thesame axes.(g) Find the posterior probability that < :The probability density function of a beta(a,b) distribution isf(x) =kxa 1(1 x)b 1wherekis a beta(a,b) then the mean ofXisE(X) =aa+band the variance ofXisvar(X) =ab(a+b+ 1)(a+b) beta(a,b) then you can use a command such as the following in R to find Pr(X < c).
2 Pbeta(c,a,b)To plot the prior and posterior probability densities you may use R commands such as <-seq( , , )prior<-dbeta(theta,a,b)posterior<-dbeta (theta,c,d)plot(theta,posterior,xlab=exp ression(theta),ylab="Density",type="l")l ines(theta,prior,lty=2)12. The populations,ni,and the number of cases,xi,of a disease in a year in each of six districtsare given in the table suppose that the numberXiin a district with populationniis a Poisson random variablewith meanni number in each district is independent of the numbers in otherdistricts, given the value of .Our prior distribution for is a gamma distribution with and standard deviation (a) Find the parameters of the prior distribution.(b) Find the prior probability that < (c) Find the likelihood.(d) Find the posterior distribution of .(e) Find the posterior mean and posterior standard deviation of.
3 (f) Plot a graph showing the prior and posterior probability density functions of on thesame axes.(g) Find the posterior probability that < :The probability density function of a gamma(a,b) distribution isf(x) =kxa 1exp( bx)wherekis a gamma(a,b) then the mean ofXis E(X) =a/band the variance ofXis var(X) =a/(b2).IfX gamma(a,b) then you can use a command such as the following in R to find Pr(X < c).pgamma(c,a,b)To plot the prior and posterior probability densities you may use R commands such as <-seq( , , )prior<-dgamma(lambda,a,b)posterior<-dga mma(lambda,c,d)plot(lambda,posterior,xla b=expression(lambda),ylab="Density",type ="l")lines(lambda,prior,lty=2)3. Geologists note the type of rock at fixed vertical intervals of six inches up a quarry face. Atthis quarry there are four types of rock. The following model is conditional probability that the next rock type isjgiven that the present type isiandgiven whatever has gone before 4j=1pij= 1 for following table gives the observed (upwards) transition rock1234 From rock15613244215932235320251531146351144 Our prior distribution for the transition probabilities is as follows.
4 For eachiwe have auniform distribution over the space of possible values ofpi1,.., prior distributionofpi1,..,pi4is independent of that forpk1,..,pk4fori6= the matrix of posterior expectations of the transition that the integral ofxn11xn22xn33xn44over the region such thatxj>0 forj= 1,..,4 and 4j=1xj= 1,wheren1,..,n4are positive is 10xn11 1 x10xn22 1 x1 x20xn33(1 x1 x2 x3) (n1+ 1) (n2+ 1) (n3+ 1) (n4+ 1) (n1+n2+n3+n4+ 4)4. A biologist is interested in the proportion, ,of badgers in a particular area which carrythe infection responsible for bovine tuberculosis. The biologist s prior distribution for is abeta(1,19) distribution.(a)i. Find the biologist s prior mean and prior standard deviation for .ii. Find the cumulative distribution function of the biologist s prior distribution andhence find values 1, 2such that, in the biologist s prior distribution, Pr( < 1) =Pr( > 2) = (b) The biologist captures twenty badgers and tests them for the infection.
5 Assume that,given ,the number,X,of these carrying the infection has a binomial(20, ) observed number carrying the infection isx= Find the likelihood Find the biologist s posterior distribution for .iii. Find the biologist s posterior mean and posterior standard deviation for .iv. Use R to plot a graph showing the biologist s prior and posterior probability densityfunctions for .5. A factory produces large numbers of packets of nuts. As part of the quality control process,samples of the packets are taken and weighed to check whether they are underweight. Letthe true proportion of packets which are underweight be and assume that, given ,thepackets are independent and each has probability of being underweight. A beta(1,9) priordistribution for is used.(a) The procedure consists of selecting packets until either an underweight packet is found,in which case we stop and note the numberXof packets examined, orm= 10 packetsare examined and none is underweight, in which we case we stop and note this Find the posterior distribution for whenX= 7 is Find the posterior distribution for when no underweight packets are found out ofm= 10.
6 (b) Now consider varying the value R to find the posterior probability that < when no underweight packets are found out 10, 20, The numbers of patients arriving at a minor injuries clinic in 10 half-hour intervals arerecorded. It is supposed that, given the value of a parameter ,the numberXjarriving inintervaljhas a Poisson distributionXj Poisson( ) andXjis independent ofXkforj6= prior distribution for is a gamma(a,b) distribution. The prior mean is 10 and the priorstandard deviation is 5.(a)i. Find the values LetW valuesw1,w2such that Pr(W < w1) = Pr(W > w2) = find valuesl1,l2such that, in the prior distribution, Pr( < l1) = Pr( >l2) = Using R (or otherwise) find a 95% prior highest probability density interval for .iv. Compare these two intervals.(b) The data are as 12 16 12 16 11 18 13 12 19i.
7 Find the posterior distribution of .ii. Using R (or otherwise) find a 95% posterior highest probability density interval for .7. The numbers of sales of a particular item from an Internet retail site in each of 20 weeks arerecorded. Assume that, given the value of a parameter ,these numbers are independentobservations from the Poisson( ) prior distribution for is a gamma(a,b) distribution.(a) Our prior mean and standard deviation for are 16 and 8 respectively. Find the valuesofaandb.(b) The observed numbers of sales are as 19 14 21 22 33 15 13 16 19 27 22 27 21 16 25 14 23 22 17 Find the posterior distribution of .(c) Using R or otherwise, plot a graph showing both the prior and posterior probabilitydensity functions of .(d) Using R or otherwise, find a 95% posterior hpd interval for .(Note: The R functionhpdgammais available from the Module Web Page).
8 8. In a medical experiment, patients with a chronic condition are asked to say which of twotreatments, A, B, they prefer. (You may assume for the purpose of this question that everypatient will express a preference one way or the other). Let the population proportion whoprefer A be .We observe a sample ofnpatients. Given ,thenresponses are independentand the probability that a particular patient prefers A is .Our prior distribution for is a beta(a,a) distribution with a standard deviation of (a) Find the value ofa.(b) We observen= 30 patients of whom 21 prefer treatment A. Find the posterior distri-bution of .(c) Find the posterior mean and standard deviation of .(d) Using R or otherwise, plot a graph showing both the prior and posterior probabilitydensity functions of .(e) Using R or otherwise, find a symmetric 95% posterior probability interval for.
9 (Hint:The R commandqbeta( ,a,b)will give the point of a beta(a,b)distribu-tion).49. The survival times, in months, of patients diagnosed with a severe form of a terminal illnessare thought to be well modelled by an exponential( ) distribution. We observe the survivaltimes ofnsuch patients. Our prior distribution for is a gamma(a,b) distribution.(a) Prior beliefs are expressed in terms of the median lifetime, an expression formin terms of .(b) In the prior distribution, the lower 5% point formis and the upper 5% point Find the corresponding lower and upper 5% points for .Let these bek1, k2respectively.(c) Letk2/k1= , to the nearest integer, the value of such that, in a 2 distribution,the 95% point divided by the 5% point isrand hence deduce the value ofa.(d) Using your value ofaand one of the percentage points for ,find the value ofb.
10 (e) We observen= 25 patients and the sum of the lifetimes is 502. Find the posteriordistribution of .(f) Using the relationship of the gamma distribution to the 2distribution, or otherwise,find a symmetric 95% posterior interval for .Note: The R commandqchisq( ,nu)will give the lower point of a 2distri-bution onnudegrees of 3 Solutions to Questions7, 8, 9of Problems 3 are to be submitted in the Homework Letterbox nolater than on Monday March (a) In the priora= andb= the mean isaa+b= variance isab(a+b)2(a+b+ 1)= 4=116so the standard deviation is14= (b) Using R the prior probability that < is > pbeta( , , )[1] (c) The likelihood is(5037) 37(1 )13.(d) The prior density is proportional to 1(1 ) 1 The likelihood is proportional to 37(1 )13 Hence the posterior density is proportional to 1(1 ) 1 The posterior distribution is beta( , ).