First we generate the data using the information given in the question. The 10 theta values I have chosen as 1, 2, …, 10 and the population variance as 1. I generate 25 sample points from each population and display first few readings and a box-plot of the same.
| Type 1 | Type 2 | Type 3 | Type 4 | Type 5 | Type 6 | Type 7 | Type 8 | Type 9 | Type 10 |
|---|---|---|---|---|---|---|---|---|---|
| 0.4395244 | 0.3133067 | 3.253318 | 5.025571 | 4.289593 | 5.348050 | 7.787739 | 6.904004 | 11.198810 | 10.059750 |
| 0.7698225 | 2.8377870 | 2.971453 | 3.715227 | 5.256884 | 6.235387 | 7.769042 | 8.037788 | 10.312413 | 9.295404 |
| 2.5587083 | 2.1533731 | 2.957130 | 2.779282 | 4.753308 | 6.077961 | 7.332203 | 8.310481 | 8.734855 | 9.282782 |
| 1.0705084 | 0.8618631 | 4.368602 | 4.181304 | 4.652457 | 5.038143 | 5.991623 | 8.436523 | 9.543194 | 10.884650 |
| 1.1292877 | 3.2538149 | 2.774229 | 3.861109 | 4.048381 | 5.928692 | 6.880547 | 7.541635 | 8.585660 | 8.984407 |
| 2.7150650 | 2.4264642 | 4.516471 | 4.005764 | 4.954972 | 7.444551 | 6.719605 | 6.936674 | 8.523753 | 11.955294 |
We run a Markov Chain of size 10,000 and choose the last 5000 values for estimation of each population mean.
Here we choose the hyperparamters as moderately vague and the mean for the Normal distribution is chosen to be zero. We display estimates of all 10 means whose true values are 1, 2, 3, …, 10.
# Hyper parameters
u0 <- 0 # Mean of the Normal distribution
v0 <- 10 # Variance of the Normal distribution
a1 <- 0.1 # as defined in book
b1 <- 0.1 # as defined in book
a2 <- 0.1 # as defined in book
b2 <- 0.1 # as defined in book
The estimates are:
0.9830428
2.114153
3.017667
4.284433
4.722796
5.766093
7.205333
7.850506
9.08568
9.854426
We obtain reasonable estimates.
Next we use the same vague priors but use a larger hyperparameter for the mean of the Normal distribution to see if there is some difference.
# Hyper parameters
u0 <- 50 # Mean of the Normal distribution
v0 <- 10 # Variance of the Normal distribution
a1 <- 0.1 # as defined in book
b1 <- 0.1 # as defined in book
a2 <- 0.1 # as defined in book
b2 <- 0.1 # as defined in book
The estimates are:
0.9662683
2.102985
3.009338
4.282624
4.722492
5.772413
7.216608
7.8611
9.105483
9.87523
We obtain similar estimates as before.
Next we use the same vague priors but use a much larger hyperparameter for the mean of the Normal distribution to see if there is some difference.
# Hyper parameters
u0 <- 1000 # Mean of the Normal distribution
v0 <- 10 # Variance of the Normal distribution
a1 <- 0.1 # as defined in book
b1 <- 0.1 # as defined in book
a2 <- 0.1 # as defined in book
b2 <- 0.1 # as defined in book
The estimates are:
0.9651634
2.101969
3.008228
4.281849
4.721804
5.770914
7.215595
7.860368
9.104549
9.874419
We obtain similar estimates as before. This indicates that the u0 hyperparameter does not effec the results. Next we increase the vagueness of priors.
We use some very vague priors.
# Hyper parameters
u0 <- 0 # Mean of the Normal distribution
v0 <- 1000000 # Variance of the Normal distribution
a1 <- 0.000001 # as defined in book
b1 <- 0.000001 # as defined in book
a2 <- 0.000001 # as defined in book
b2 <- 0.000001 # as defined in book
The estimates are:
0.9651365
2.100891
3.008035
4.282231
4.721153
5.771179
7.213425
7.860911
9.105514
9.875362
There is no noticeable difference from previous estimates. Next we choose priors that are not vague.
# Hyper parameters
u0 <- 0 # Mean of the Normal distribution
v0 <- 0.01 # Variance of the Normal distribution
a1 <- 100 # as defined in book
b1 <- 100 # as defined in book
a2 <- 100 # as defined in book
b2 <- 100 # as defined in book
The estimates are:
0.9466822
2.07878
2.970404
4.218997
4.657986
5.681872
7.109531
7.753166
8.97402
9.730353
We do not see appreciable change in results.
We run the sampler and produce the estimates.
Compiling model graph
Resolving undeclared variables
Allocating nodes
Graph information:
Observed stochastic nodes: 250
Unobserved stochastic nodes: 13
Total graph size: 520
Initializing model
Now we check the estimates.
The estimates are:
1.000002
1.999997
2.999999
3.999991
4.999999
5.999991
6.999997
7.999997
8.999985
10
The results are way more accurate than those obtained by the previous Gibbs Sampler.