fhoces / bda3 Goto Github PK
View Code? Open in Web Editor NEWTutorial on Bayesian Statistics using Bayesian Data Analysis 3 (Gelman et.at 2014)
Tutorial on Bayesian Statistics using Bayesian Data Analysis 3 (Gelman et.at 2014)
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.