#1: Uniform Distribution (continous distribution where all values within a range are all likely to occur)
# randomly generate a sample
uniform_sample <- runif(500, min=0, max=1)
summary(uniform_sample)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0008818 0.2682224 0.4988012 0.4981899 0.7313468 0.9982581
hist(uniform_sample, main = "Uniform Distribution", col = "lightgreen")
# probability of x less than 4
prob_uniform <- punif(4, min = 0, max = 10)
print(prob_uniform)
## [1] 0.4
#2: Exponential Distribution
exponential_sample <- rexp(500, rate = 0.1)
hist(exponential_sample, main = "Exponential Distribution", col = "red")
# probability that x is greater than 7
prob_exponential <- 1 - pexp(7, rate = 0.1)
print(prob_exponential)
## [1] 0.4965853
#3: Poisson Distribution
poisson_sample <- rpois(500, lambda = 3)
hist(poisson_sample, main = "Poisson Distribution", col = "pink")
# probability of exactly 4 events
prob_poisson <- dpois(4, lambda = 3)
print(prob_poisson)
## [1] 0.1680314
#4: Binomial Distribution
binomial_sample <- rbinom(500, size = 10, prob = 0.5)
hist(binomial_sample, main = "Binomial Distribution", col = "lightblue")
# probability of exactly 3 successes
prob_binomial <- dbinom(3, size = 10, prob = 0.5)
print(prob_binomial)
## [1] 0.1171875
#5: Comparisons
hist(uniform_sample, col = rgb(0.2,0.8,0.8,0.5), xlim = c(0,50))
hist(exponential_sample, col = rgb(0.3,0.7,0.3,0.5), add = TRUE)
hist(poisson_sample, col = rgb(0.8,0.3,0.3,0.5), add = TRUE)
hist(binomial_sample, col = rgb(0.7,0.7,0.1,0.5), add = TRUE)
#6: Conclusions
A. Compared to each other, each histogram takes on a different shape or form. Uniform distribution’s histogram is flat and even, which reflects the values being equally as likely to occur. Exponential distribution appears to start high, and slope downward, showcasing that smaller values are more likely to occur. Poisson distribution is more jagged or bumpy in terms of its appearance, since it measures how many times an event might happen. Finally, the binomial distribution’s histogram is bell shaped, since its centered around a specific amount of successes (5). B. The parameter of lambda affects exponential and poisson distributions in two distinct ways. If the lambda was smaller, then the histogram would be more spread out. Additionally, if the lambda was larger, the exponential histogram would be clustered more towards zero. A larger lambda would also affect poisson distribution by making it more bell curved (moving right).