Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- plot_g_cdf <- function(x, p)
- {
- plot(x+1, pgeom(x, prob = p), xlab = "X", ylab = "Y", type = "s", main = "Geometric CDF")
- }
- plot_g_pdf <- function(x, p)
- {
- plot(x+1, dgeom(x, prob = p), xlab = "X", ylab = "Y", type = "h", main = "Geometric PDF")
- }
- geometric <- function()
- {
- x <- winDialogString("Enter start of range: ", " ")
- y <- winDialogString("Enter end of range: ", " ")
- x <- as.numeric(x)
- y <- as.numeric(y)
- range <- seq(x,y)
- x <- winDialogString("Enter probability: ", " ")
- probability <- as.numeric(x)
- x <- menu(c("CDF", "PDF"), graphics = TRUE, title = "CDF or PDF?")
- if(x==1){
- print(round(pgeom(range,probability), 2))
- plot_g_cdf(range,probability)
- }
- else if(x==2){
- print(round(dgeom(range,probability), 2))
- plot_g_pdf(range,probability)
- }
- }
- plot_p_cdf <- function(x, l)
- {
- plot (x, ppois(x, l), xlab = "X", ylab = "Y",type = "s", main= "Poisson CDF")
- }
- plot_p_pdf <- function(x, l)
- {
- plot (x, dpois(x, l), xlab = "X", ylab = "Y",type = "h", main= "Poisson PDF")
- }
- poisson <- function()
- {
- x <- winDialogString("Enter start of range: ", " ")
- y <- winDialogString("Enter end of range: ", " ")
- x <- as.numeric(x)
- y <- as.numeric(y)
- range <- seq(x,y)
- x <- winDialogString("Enter lambda: ", " ")
- lambda <- as.numeric(x)
- x <- menu(c("CDF", "PDF"), graphics = TRUE, title = "CDF or PDF?")
- if(x==1){
- print(round(ppois(range,lambda), 2))
- plot_p_cdf(range,lambda)
- }
- else if(x==2){
- print(round(dpois(range,lambda), 2))
- plot_p_pdf(range,lambda)
- }
- }
- plot_b_cdf <- function(x, s, p)
- {
- plot(x, pbinom(x, size = s, prob = p), xlab = "X", ylab = "Y", ylim = c(0, 1), type = "s", main = "Binomial CDF")
- }
- plot_b_pdf <- function(x, s, p)
- {
- plot(x, dbinom(x, size = s, prob = p), xlab = "X", ylab = "Y", type = "h", main = "Binomial CDF")
- }
- binomial <- function()
- {
- x <- winDialogString("Enter start of range: ", " ")
- y <- winDialogString("Enter end of range: ", " ")
- x <- as.numeric(x)
- y <- as.numeric(y)
- range <- seq(x,y)
- x <- winDialogString("Enter size: ", " ")
- size <- as.numeric(x)
- x <- winDialogString("Enter probability: ", " ")
- probability <- as.numeric(x)
- x <- menu(c("CDF", "PDF"), graphics = TRUE, title = "CDF or PDF?")
- if(x==1){
- print(round(pbinom(range,size,probability), 2))
- plot_b_cdf(range, size, probability)
- }
- else if(x==2){
- print(round(dbinom(range,size,probability), 2))
- plot_b_pdf(range, size, probability)
- }
- }
- plot_hg_cdf <- function(x, m, l, n)
- {
- plot(x, phyper(x, m, l, n), xlab = "X", type = "s", ylab = "Y", main = "HyperGeometric CDF")
- }
- plot_hg_pdf <- function(x, m, l, n)
- {
- plot(x, dhyper(x, m, l, n), xlab = "X", type = "h", ylab = "Y", main = "HyperGeometric PDF")
- }
- hypergeometric <- function()
- {
- x <- winDialogString("Enter start of range: ", " ")
- y <- winDialogString("Enter end of range: ", " ")
- x <- as.numeric(x)
- y <- as.numeric(y)
- range <- seq(x,y)
- x <- winDialogString("Enter success possible: ", " ")
- success <- as.numeric(x)
- x <- winDialogString("Enter failures possible: ", " ")
- failure <- as.numeric(x)
- x <- winDialogString("Enter amount: ", " ")
- amount <- as.numeric(x)
- x <- menu(c("CDF", "PDF"), graphics = TRUE, title = "CDF or PDF?")
- if(x==1){
- plot_hg_cdf(range,success,failure,amount)
- print(round(phyper(range,success,failure,amount), 2))
- }
- else if(x==2){
- print(round(dhyper(range,success,failure,amount), 2))
- plot_hg_pdf(range,success,failure,amount)
- }
- }
- run <- function()
- {
- answer <- 1
- while(answer==1)
- {
- selection <- menu(c("Hypgeometric", "Binomial", "Geometric", "Poisson"), graphics = TRUE, title = "Which distribution?")
- if(selection==1)
- {
- hypergeometric()
- }
- else if(selection==2)
- {
- binomial()
- }
- else if(selection==3)
- {
- geometric()
- }
- else if(selection==4)
- {
- poisson()
- }
- answer <- menu(c("Yes", "No"), graphics = TRUE, title = "Would you like to plot again?")
- }
- }
Add Comment
Please, Sign In to add comment