Created
August 27, 2024 16:24
-
-
Save abikoushi/3622a9fed9119327f7db16fcd0ed8379 to your computer and use it in GitHub Desktop.
A Comparison between confidence interval vs. credible interval
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
library(animation) | |
pvfun <- Vectorize(function(r, y){ | |
poisson.test(y, T = tau, r = r)$p.value | |
}) | |
postprob <- function(r, x, tau){ | |
pl <- pgamma(r, shape = x+0.5, rate = tau, lower.tail = FALSE) | |
pu <- pgamma(r, shape = x+0.5, rate = tau, lower.tail = TRUE) | |
2*pmin(pl,pu) | |
} | |
tau <- 10 | |
#y <- 5 | |
saveGIF({ | |
for(i in c(1:10, 10:1)){ | |
curve(pvfun(x,i),0, 3, n=1001, | |
col="orangered", ylab = "p-value", xlab="rate") | |
curve(postprob(x, i, tau), col="royalblue", add=TRUE,lty=2, lwd=2) | |
legend("topright",legend = c("p-value","posterior (Jeffreys prior)"), | |
col=c("orangered","royalblue"), lty=1:2) | |
} | |
}, movie.name = "poistest.gif", interval=0.2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment