Created
October 11, 2025 10:09
-
-
Save abikoushi/e9ea449d2d2ab09351836705cf7953bf to your computer and use it in GitHub Desktop.
triplet of Beta, Binomial, and Negative Binomial distribution
This file contains hidden or 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(ggplot2) | |
| NB_p <- function(p,x,r){ | |
| pnbinom(x, size = r, prob = p,lower.tail = TRUE) | |
| } | |
| B_p <- function(p,x,r){ | |
| pbinom(r-1, size = r+x, prob = p, lower.tail = FALSE) | |
| } | |
| Beta_p <- function(p,x,r){ | |
| pbeta(p, shape1 = r, shape2 = x+1, lower.tail = TRUE) | |
| } | |
| params = list(r = 10, x = 6) | |
| pp = ggplot()+ | |
| stat_function(fun = B_p, args = params, aes(linetype="binomial", colour="binomial"))+ | |
| stat_function(fun = Beta_p, args = params, aes(linetype="beta", colour="beta"))+ | |
| stat_function(fun = NB_p, args = params, aes(linetype="negative binomial", colour="negative binomial"))+ | |
| stat_function(geom = "point", fun = B_p, args = params, aes(shape="binomial", colour="binomial"), n=7)+ | |
| stat_function(geom = "point", fun = Beta_p, args = params, aes(shape="beta", colour="beta"), n=8)+ | |
| stat_function(geom = "point", fun = NB_p, args = params, aes(shape="negative binomial", colour="negative binomial"), n=9)+ | |
| xlim(c(0.001,0.999))+ | |
| labs(x="p", y="probability", colour="function", linetype="function",shape="function")+ | |
| theme_bw() | |
| print(pp) | |
| ggsave(filename = "betacdf3.png", plot = pp, width = 7, height = 7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment