Question 6

In this question we know the form of the posterior distribution of the location parameter theta up to a proportionality constant. If we take the uniform prior then then this just looks like the liklihood of the data. In order to find HPD credible set for theta we can sample from this distribution using MCMC. Then we can calculate sample quantiles of any order and thereby find minimum length credible sets of desired probability (.99 or .95).

First we do it for sample size 5, then for sample size 20 and then for sample size 100. In each case the location parameter we set as 5 for generating the data.

To calculate the HPD credible set we just iterate over all possible sets with desired probability and find the one with minimum length. By all possible I mean only a finite number but chosen at the granularity of 6th decimal place.

Sample size n = 5

Generating a sample from the Cauchy distribution using location parameter equal to 5.

[1] 6.416674 4.658129 5.544989 4.758054 5.547089

Now we sample from the posterior using JAGS. First we set up the sampler and check its output.

Compiling model graph
   Resolving undeclared variables
   Allocating nodes
Graph information:
   Observed stochastic nodes: 5
   Unobserved stochastic nodes: 1
   Total graph size: 11

Initializing model

Now we take a sample of 1000 from this posterior distribution for HPD credible set calculation. First we calculate a 95% HPD credible set.

95% HPD credible set is
 2.6026% 97.6026% 
4.381691 6.338948 

Next we calculate 99% HPD credible set.

99% HPD credible set is
 0.5005% 99.5005% 
3.985680 6.603874 

Sample size n = 20

Generating a sample from the Cauchy distribution using location parameter equal to 5.

Compiling model graph
   Resolving undeclared variables
   Allocating nodes
Graph information:
   Observed stochastic nodes: 20
   Unobserved stochastic nodes: 1
   Total graph size: 26

Initializing model
95% HPD credible set is
 1.2012% 96.2012% 
4.466145 5.721654 
99% HPD credible set is
 0.7007% 99.7007% 
4.371501 6.033171 

Sample size = 100

Compiling model graph
   Resolving undeclared variables
   Allocating nodes
Graph information:
   Observed stochastic nodes: 100
   Unobserved stochastic nodes: 1
   Total graph size: 106

Initializing model
95% HPD credible set is
 2.6977% 97.6977% 
4.782707 5.494566 
99% HPD credible set is
 0.6997% 99.6997% 
4.646164 5.601910 

Conclusion

The HPD credible sets become more accurate and narrower as sample size increases.

Question 2

Jeffrey’s prior = Beta(0.5, 0.5)

We work with a sample of size 30. For a fixed value of the parameter (calling it p) we draw 100 size 30 samples and for each we construct 95% confidence intervals and 95% HPD credible sets and check how many times these intervals contain the true value of the parameter.

p = 1/8

Number of times the confidence intervals contains the true value 92
Number of times the HPD confidence set contains the true value 91

p = 1/4

Number of times the confidence intervals contains the true value 96
Number of times the HPD confidence set contains the true value 96

p = 1/2

Number of times the confidence intervals contains the true value 97
Number of times the HPD confidence set contains the true value 97

p = 3/4

Number of times the confidence intervals contains the true value 91
Number of times the HPD confidence set contains the true value 91

p = 7/8

Number of times the confidence intervals contains the true value 90
Number of times the HPD confidence set contains the true value 88