stan-dev / example-models

Example models for Stan
http://mc-stan.org/
771 stars 479 forks source link

Fix exercise 5 in repeated binary trials #97

Open bob-carpenter opened 7 years ago

bob-carpenter commented 7 years ago

Gertjan Verhoeven pointed out a bug in exercise 5. That was based on exercise 5.9(b) of BDA 3 (p. 136). But the phrasing was botched int he text and exercise. It should be as follows.

BDA 3, Problem 5.9(b):

Assume p(alpha / (alpha + beta), alpha + beta) is uniform and show that

p(alpha, beta) propto (alpha + beta)^{-5/2}.

First note that alpha, beta > 0.

Step 1. Let

f(kappa) = kappa^{-0.5} = gamma

so that

f^{-1}(gamma) = gamma^{-2} = kappa

and assume a uniform so that that p_G(gamma) = const. Then with the usual change of variables, we get

p_K(kappa) = p_G(f^{-1}(kappa)) | d/d.kappa f^{-1}(kappa) |

  = const | d/d.kappa kappa^{-0.5} |

  propto kappa^{-1.5}

Step 2. Compute the Jacobian of the inverse transform h, defined by

h(alpha, beta) = (alpha / (alpha + beta), (alpha + beta))

the Jacobian of which is

J_h

= |  d/d.alpha (alpha / (alpha + beta))      d/d.alpha (alpha + beta)  |
  |  d/d.beta (alpha / (alpha + beta))        d/d.beta (alpha + beta)  |

= | beta / (alpha + beta)^2       1 |
  | - alpha / (alpha + beta)^2    1 |

which using the rule for determinants for 2 x 2 matrices, provide an absolute Jacobian determinant of:

|J_h| = (alpha + beta)^{-1}

Step 3. Multiply the distribution from Steps 1 and 2 by the absolute Jacobian determinant to adjust for change of variables, and the final result is

p(alpha, beta)
  = (alpha + beta)^{-3/2} * (alpha + beta)^{-1}
  = (alpha + beta)^{-5/2}

Or you could just put the two bits together and derive the compound Jacobian, but it seems clearer this way in two steps.