Problem 1a: The tallest bar (4) is the same as the expected value for the data given. np is how you find this value which is 80.5 = 4.

y <- rbinom(1000, size = 8, prob = 0.5)
barplot(table(y), col = rainbow(9), main = "Bar Plot of Sample from Binomial(8, 0.5)",
        xlab = "Value of Y", ylab = "Frequency")

Problem 1b: These two answers are very close to each other, only differing by about 0.02. They are two slightly different methods to getting the answer so neither are wrong, and they are still very close to each other.

y <- rbinom(1000, size = 8, prob = 0.5)
direct_prob <- sum(y >= 3 & y < 7) / length(y)
pbinom_prob <- pbinom(6, size = 8, prob = 0.5) - pbinom(2, size = 8, prob = 0.5)
print(paste("Direct Calculation:", direct_prob))
## [1] "Direct Calculation: 0.829"
print(paste("pbinom() Calculation:", pbinom_prob))
## [1] "pbinom() Calculation: 0.8203125"

Problem 2a:

b <- rpois(1000, lambda = 10)
hist(b, col = "orange", main = "Histogram of Variable B",
     xlab = "Values of B", ylab = "Frequency")

Problem 2b: Again, these values are extremely close to each other, only differing by about 0.008”. Due to the lower and upper limits in the “ppois” function, there are different calculations which lead to the slightly different answer. Overall, the two values are very close to each other.

b <- rpois(1000, 10)
direct_prob <- mean(b < 8)
ppois_prob <- ppois(7, 10)
print(paste("Direct Calculation:", direct_prob))
## [1] "Direct Calculation: 0.206"
print(paste("Using ppois() function:", ppois_prob))
## [1] "Using ppois() function: 0.220220646601699"

Problem 3a:

x <- rnorm(1000, mean = 100, sd = 9)
hist(x, col = "purple", main = "Frequency Histogram", xlab = "Values of X", ylab = "Frequency")

Problem 3b: Again, these values are very similar. They differ barely due to the fact that direct calculations require a set of randomized samples, whereas pnorm() can be done using data from the question itself. It comes out to be similar in the end, but the ways of getting there are different.

x <- rnorm(1000, mean = 100, sd = 9)
prob_x_gt_72_data <- mean(x > 72)
prob_x_gt_72_pnorm <- 1 - pnorm(72, mean = 100, sd = 9)
comparison <- data.frame(
  Method = c("Direct Calculation", "pnorm() Function"),
  Probability = c(prob_x_gt_72_data, prob_x_gt_72_pnorm)
)

comparison
##               Method Probability
## 1 Direct Calculation   0.9970000
## 2   pnorm() Function   0.9990681