Skip to content

Final Prep

Last edited 775 days ago by Eddie Coda.

Question 1.

A die is tossed until the first 6 occurs. What is the probability that it takes 4 or more tosses? Estimate the probability for this geometric distribution by simulating 1000 random samples. Create a histogram of your simulations and describe the shape of the distribution.
# Step 1: Set up the problem
p_success <- 1/6
p_failure <- 5/6

# Step 2: Calculate the probability using the CCDF
p_4or_more <- (1 - p_failure^3)
p_4or_more

# Step 3: Simulate 10,000 random samples using the geometric distribution
set.seed(42) # Set the seed for reproducibility
n <- 10000
simulations <- rgeom(n, prob = p_success) + 1

# Step 4: Create a histogram using ggplot2
library(ggplot2)
ggplot(data.frame(simulations), aes(x = simulations)) +
geom_histogram(binwidth = 1, color = "black", fill = "skyblue") +
labs(title = "Waiting for the 6: A Board Game Enthusiast's Journey",
x = "Number of Rolls to Get the First 6",
y = "Frequency") +
theme_minimal()

# Step 5: Describe the distribution
image.png

The histogram resembles a mountain, with the peak located at the first roll, and the slopes gradually descending as we move to the right. It shows that the majority of the time, Zoe will get her first 6 within the initial few rolls. As the number of rolls increases, the frequency decreases, making it less likely for Zoe to wait too long for her favorite number to appear.

Question 2.

UFO sightings have been reported to occur at an average rate of five per hour during certain clear nights. What is the probability that a UFO hunter will spot exactly ten UFOs in two hours?
- Run a random sample of this event and simulate it to estimate the probability and compare it to the exact probability.
- Create a histogram and describe the shape of the distribution.
lambda <- 5 * 2 # Rate per hour * number of hours
k <- 10 # Number of UFOs
exact_prob <- dpois(k, lambda)

n_simulations <- 10000
simulated_UFOs <- rpois(n_simulations, lambda)

estimated_prob <- sum(simulated_UFOs == k) / n_simulations

hist(
simulated_UFOs,
main="Simulated UFO Sightings 🛸",
xlab="Number of UFOs Spotted",
col="lightblue", border="black",
breaks=seq(min(simulated_UFOs
), max(simulated_UFOs), 1))
image.png

The histogram of simulated UFO sightings 🛸 displays a unimodal distribution, with a peak around 12 UFOs. The distribution appears slightly right-skewed, with a longer tail extending toward higher numbers of UFO sightings. Overall, the shape of the histogram suggests that most UFO hunters are likely to spot between 8 and 16 UFOs during the 2-hour observation period, with fewer sightings as we move further away from this range.

Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.