Skip to content

Error in Replications 4 #1

@uasolo

Description

@uasolo

The contour plots are wrong because of the way alpha and beta are defined in your code:
beta = exp(v2)/(exp(v1)+1)
alpha = exp(v2+v1)/(exp(v1)+1)
this does not produce a grid of values, which is what you want.
Taking inspiration form:
http://avehtari.github.io/BDA_R_demos/demos_ch5/demo5_1.html
you can modify that code, which does not operate the coordinate transformation, with:
cv1 <- rep(v1, each = length(v2))
cv2 <- rep(v2, length(v1))
cA = exp(cv2+cv1)/(exp(cv1)+1)
cB = exp(cv2)/(exp(cv1)+1)
Add the Jacobian to lpfun:
lpfun <- function(a, b, y, n) log(a) + log(b) + log(a+b)*(-5/2) +
sum(lgamma(a+b)-lgamma(a)-lgamma(b)+lgamma(a+y)+lgamma(b+n-y)-lgamma(a+b+n))
lp <- mapply(lpfun, cA, cB, MoreArgs = list(y, n))
df_marg <- data.frame(x = cv1, y = cv2, p = exp(lp - max(lp)))
and plot as in that code, which will give the correct result.

Btw, it is not true that the Jacobian is applied only to the prior. In fact, when applied to the posterior it looks the same as if applied to the prior only: J * post = J * prior * likelihood = (J * prior) * likelihood.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions