If I run the following code in OpenBUGS:
MODEL
{
for (i in 1:50) {
variable[i] ~ dunif(50, 100)
}
item <- rank(variable[], 1)
}
I expect item
to be 0, as there are no components of variable
that can be below 1. This is based on the definition of the function rank
from the OpenBUGS user manual:
"rank(v, s)
: number of components of v
less than or equal to s
"
However, the posterior for item
is actually:
mean sd MC_error val2.5pc median val97.5pc start sample
item 25.4 14.39 0.4072 1.0 25.0 49.0 1 1000
Meaning that around 25 components of variable
are less than or equal to 1, when clearly none of the components of variable
can be less than 1--confirmed by the posterior distribution of variable
values:
mean sd MC_error val2.5pc median val97.5pc start sample
variable[1] 74.27 14.06 0.4417 51.51 73.73 98.96 1001 1000
variable[2] 74.32 14.29 0.5154 51.43 74.02 98.52 1001 1000
variable[3] 75.1 14.53 0.5623 51.34 75.2 99.07 1001 1000
variable[4] 75.78 14.41 0.3846 51.22 76.44 98.77 1001 1000
variable[5] 74.97 14.93 0.5557 51.24 74.8 99.18 1001 1000
variable[6] 75.13 14.61 0.4657 51.1 75.17 99.05 1001 1000
variable[7] 74.65 14.39 0.4296 51.58 74.44 98.57 1001 1000
variable[8] 75.01 14.28 0.4517 51.23 75.05 98.72 1001 1000
variable[9] 75.2 14.04 0.4309 52.09 74.83 98.7 1001 1000
variable[10] 75.3 14.47 0.4811 51.31 75.55 98.96 1001 1000
variable[11] 74.85 14.39 0.5504 51.55 74.65 98.7 1001 1000
variable[12] 74.85 14.42 0.4884 51.56 74.57 98.34 1001 1000
variable[13] 75.54 14.91 0.4995 50.95 76.14 98.97 1001 1000
variable[14] 75.43 14.46 0.4723 51.56 75.39 98.83 1001 1000
variable[15] 74.97 14.39 0.4658 51.14 75.58 98.74 1001 1000
variable[16] 75.39 14.46 0.5693 51.44 76.24 98.53 1001 1000
variable[17] 74.41 14.67 0.4356 51.03 73.34 98.78 1001 1000
variable[18] 75.09 14.22 0.3771 51.49 74.99 98.81 1001 1000
variable[19] 75.7 14.31 0.394 51.46 76.02 98.55 1001 1000
variable[20] 74.8 14.23 0.5463 51.64 75.12 98.86 1001 1000
variable[21] 74.83 14.56 0.4997 51.2 74.74 98.65 1001 1000
variable[22] 75.58 14.38 0.4412 51.38 76.6 98.3 1001 1000
variable[23] 74.64 14.42 0.4406 51.34 74.05 98.37 1001 1000
variable[24] 74.85 14.09 0.5247 51.6 74.72 98.96 1001 1000
variable[25] 75.48 14.39 0.4642 51.14 76.12 98.69 1001 1000
variable[26] 75.26 14.57 0.5391 51.18 75.07 98.92 1001 1000
variable[27] 74.49 14.5 0.4723 51.39 74.51 98.78 1001 1000
variable[28] 75.37 14.47 0.3562 51.09 75.5 98.64 1001 1000
variable[29] 74.64 14.37 0.4637 51.25 74.57 98.64 1001 1000
variable[30] 74.66 14.88 0.5224 51.1 74.73 98.83 1001 1000
variable[31] 75.48 14.31 0.4403 51.84 75.83 99.08 1001 1000
variable[32] 74.74 14.43 0.5379 51.1 74.07 99.13 1001 1000
variable[33] 74.67 14.33 0.4465 50.98 74.11 98.72 1001 1000
variable[34] 74.43 14.64 0.5293 51.05 73.72 99.05 1001 1000
variable[35] 74.51 14.44 0.4683 51.39 73.99 98.6 1001 1000
variable[36] 75.44 14.42 0.438 51.59 75.71 99.08 1001 1000
variable[37] 74.8 14.27 0.495 51.21 75.03 98.87 1001 1000
variable[38] 74.97 14.24 0.4463 52.05 75.64 98.73 1001 1000
variable[39] 74.82 14.67 0.5232 51.32 74.92 98.96 1001 1000
variable[40] 74.81 14.37 0.4862 51.3 74.58 98.79 1001 1000
variable[41] 74.77 14.51 0.3887 51.18 74.74 98.47 1001 1000
variable[42] 74.72 14.62 0.4296 51.35 74.37 98.66 1001 1000
variable[43] 75.18 14.12 0.4195 51.43 75.35 97.86 1001 1000
variable[44] 75.88 13.7 0.4136 51.86 76.14 99.0 1001 1000
variable[45] 74.6 14.2 0.3913 51.14 73.98 98.52 1001 1000
variable[46] 75.84 14.34 0.434 51.62 75.66 98.92 1001 1000
variable[47] 75.1 14.87 0.4791 51.13 75.11 99.07 1001 1000
variable[48] 75.06 14.14 0.4707 51.14 74.68 98.78 1001 1000
variable[49] 74.75 14.6 0.4521 51.3 74.4 98.93 1001 1000
variable[50] 75.2 14.36 0.4878 51.3 75.33 98.51 1001 1000
What is going on here?
From Andrew Millard, via the [BUGS] listserv:
The OpenBugs manual gives the definition as
rank(v, s)
number of components of v less than or equal to s
which is what I had based my code on, but the manual is wrong and it should be
rank(v, s)
number of components of v less than or equal to the s-th component of v