Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- i = 1
- while(i == 1)
- {
- dist<-menu(c("Binomial","Geometric","Hypergeometric","Poisson"), graphics = TRUE, title = "Which distribution?")
- if (dist == 1)
- print("Binomial was selected")
- else if(dist == 2)
- print("Geometric was selected")
- else if(dist == 3)
- print("Hypergeometric was selected")
- else if(dist == 4)
- print("Poisson was selected")
- type<-menu(c("PDF","CDF"), graphics = TRUE, title = "PDF or CDF")
- if (type == 1)
- print("PDF was selected")
- else if(type == 2)
- print("CDF was selected")
- if(dist == 1)
- {
- if(type == 1)
- {
- x <- winDialogString("Please enter the N'th term","")
- x <- as.integer(x)
- x1 <- 0:x
- x1 <- as.integer(x1)
- size <- winDialogString("Enter Sample Size","")
- size <- as.integer(size)
- if (size <= 0)
- {
- print("Error : Sample Size must be greater than 0") #Validility check to make sure Size is > 0
- break
- }
- prob <- winDialogString("Enter the probability","")
- prob <- as.double(prob)
- if (prob < 0 || prob > 1)
- {
- print("Error : Probability must be between 0 and 1") #Validility check to make sure Probability is between 0 and 1
- break
- }
- pdf<-dbinom(x1, size, prob)
- print(round(pdf, 2)) #prints of the probability rounded to two decimal places
- plot(x1, pdf,
- xlab = "X = Number of Trials",
- ylab = "P(X<=x)",
- type = "h",main = "Binomial Pdf")
- }
- if(type == 2)
- {
- x <- winDialogString("Enter the n'th term","")
- x <- as.integer(x)
- x1 <- 0:x
- x1 <- as.integer(x1)
- size <- winDialogString("Enter sample space size","")
- size <- as.integer(size)
- if (size <= 0)
- {
- print("Error : Sample Size must be greater than 0")
- break
- }
- prob <- winDialogString("Enter the probability","")
- prob <- as.double(prob)
- if (prob < 0 || prob > 1)
- {
- print("Error : Probability must be between 0 and 1")
- break
- }
- cdf<-pbinom(x1, size, prob)
- print(round(cdf, 2))
- plot(x1, cdf,
- xlab = "X = Number of Trials",
- ylab = "P(X<=x)",
- type = "s",
- main = "Binomial Cdf")
- }
- }
- if(dist == 2)
- {
- if(type == 1)
- {
- size <- winDialogString("Enter sample space size","")
- size <- as.integer(size)
- if (size <= 0)
- {
- print("Error : Sample Size must be greater than 0")
- break
- }
- x <- 0:size
- x <- as.integer(x)
- prob <- winDialogString("Enter the probability","")
- prob <- as.double(prob)
- if (prob < 0 || prob > 1)
- {
- print("Error : Probability must be between 0 and 1")
- break
- }
- pdf <- dgeom(x, prob)
- print(round(pdf, 2))
- plot(x + 1, pdf,
- xlab = "X = Number of Trials",
- ylab = "P(X=x)",
- type = "h",
- main = "Geometric Pdf")
- }
- if(type == 2)
- {
- size <- winDialogString("Enter sample size","")
- size <- as.integer(size)
- if (size <= 0)
- {
- print("Error : Sample Size must be greater than 0")
- break
- }
- x <- 0:size
- x <- as.integer(x)
- prob1 <- winDialogString("Enter the probability","")
- prob1 <- as.double(y)
- if (prob1 < 0 || prob1 > 1)
- {
- print("Error : Probability must be between 0 and 1")
- break
- }
- cdf<-pgeom(x, prob1)
- print(round(cdf, 2))
- plot(x+1, cdf,
- xlab = "X = Number of Trials",
- ylab = "P(X=x)",
- type = "s",
- main = "Geometric Cdf")
- }
- }
- if(dist == 3)
- {
- if(type == 1)
- {
- total <- winDialogString("Please enter the n'th term","")
- total <- as.integer(total)
- y <- winDialogString("Enter number of successes","")
- y <- as.integer(y)
- #
- size <- winDialogString("Enter sample size","")
- size <- as.integer(size)
- if (size <= 0)
- {
- print("Error : Sample Size must be greater than 0")
- break
- }
- x <- 0:size
- mid <- (total - y)
- pdf <- dhyper(x, y, mid, size)
- print(round(pdf, 2))
- plot(x, pdf,
- xlab = "Number of trials",
- ylab = "Probability",
- main = "Hypergoemetric pdf",
- type = "h")
- }
- if(type == 2)
- {
- total <- winDialogString("Enter the n'th term","")
- total <- as.integer(total)
- y <- winDialogString("Enter number of successes","")
- y <- as.integer(y)
- size <- winDialogString("Enter sample size","")
- size <- as.integer(size)
- if (size <= 0)
- {
- print("Error : Sample Size must be greater than 0")
- break
- }
- x <- 0:size
- mid <- (total - y)
- cdf <- phyper(x, y, mid, size)
- print(round(cdf, 2))
- plot(x, cdf,
- xlab = "Number of trials",
- ylab = "Probability",
- main = "Hypergoemetric cdf",
- type = "s")
- }
- }
- if(dist == 4 )
- {
- if(type == 1)
- {
- }
- if(type == 2)
- {
- }
- }
- i <-menu(c("Yes","No"), graphics = TRUE, title = "Would you like another Distribution?")
- }
Add Comment
Please, Sign In to add comment