Created
April 24, 2017 08:49
-
-
Save rmcelreath/08380b0cfb1ea35ed444a73ed9662bdd to your computer and use it in GitHub Desktop.
Figure 9.1 from Statistical Rethinking (bottom-right plot)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p <- list() | |
p$A <- c(0,0,10,0,0) | |
p$B <- c(0,1,8,1,0) | |
p$C <- c(0,2,6,2,0) | |
p$D <- c(1,2,4,2,1) | |
p$E <- c(2,2,2,2,2) | |
p_norm <- lapply( p , function(q) q/sum(q)) | |
( H <- sapply( p_norm , function(q) -sum(ifelse(q==0,0,q*log(q))) ) ) | |
W <- function(n,N) factorial(N)/prod(factorial(n)) | |
ways <- sapply( p , W , N=10 ) | |
logwayspp <- log(ways)/10 | |
plot(logwayspp,H,xlab="log(ways) per pebble",ylab="entropy",pch=16) | |
abline(lm(H~logwayspp),lty=2,col=col.alpha("black",0.5)) | |
text( logwayspp , H , labels=c("A","B","C","D","E") , cex=1.1 , | |
pos=c(3,3,1,1,1) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment