Experiment Steps 1. Initialization: Create a data frame to hold the results of each experiment. 2. Simulation Function: Write a function to simulate the rolling of three dice and calculate their sum. 3. Performing Experiments: Conduct 2,000 experiments, starting with 10 rolls, and increasing the number of rolls by 10 with each subsequent experiment. 4. Calculating Proportions: For each experiment, determine the proportion of times the sum of the dice is either 9 or 10. 5. Recording Results: Save the proportion results into the data frame. 6. Visualization: Plot the proportions for the sums of 9 and 10 as the number of rolls increases.
library(ggplot2)
library(gridExtra) # For arranging plots
set.seed(123) # Set a seed for reproducibility
# Define a function to simulate rolling three dice and calculate the sum
roll_dice_once <- function() {
sum(sample(1:6, size = 3, replace = TRUE))
}
# Initialize a data frame to store the results
simulation_results <- data.frame(
Experiment = 1:2000,
NumRolls = seq(10, 2000, by = 10),
ProportionSum9 = numeric(2000),
ProportionSum10 = numeric(2000)
)
# Perform simulations
for (i in 1:nrow(simulation_results)) {
# Roll the dice 'NumRolls' times for the 'i'th experiment
rolls <- replicate(simulation_results$NumRolls[i], roll_dice_once())
# Calculate the proportions for sum of 9 and sum of 10
simulation_results$ProportionSum9[i] <- mean(rolls == 9)
simulation_results$ProportionSum10[i] <- mean(rolls == 10)
}
# View the summary of results
summary(simulation_results[c("ProportionSum9", "ProportionSum10")])
## ProportionSum9 ProportionSum10
## Min. :0.0000 Min. :0.0000
## 1st Qu.:0.1088 1st Qu.:0.1174
## Median :0.1159 Median :0.1254
## Mean :0.1159 Mean :0.1255
## 3rd Qu.:0.1232 3rd Qu.:0.1328
## Max. :0.2500 Max. :0.4000
# Plot the proportions for sum of 9 and sum of 10 as the number of rolls increases
ggplot(simulation_results, aes(x = NumRolls)) +
geom_point(aes(y = ProportionSum9, color = "Sum 9"), alpha = 0.6) +
geom_point(aes(y = ProportionSum10, color = "Sum 10"), alpha = 0.6) +
scale_color_manual(values = c("Sum 9" = "blue", "Sum 10" = "red")) +
theme_minimal() +
labs(
title = "Proportion of Sums 9 and 10 as Number of Rolls Increases",
x = "Number of Rolls",
y = "Proportion",
color = "Sum"
) +
theme(legend.position = "bottom")
Based on the plot of the simulation results, which shows the proportions of sums 9 and 10 across an increasing number of rolls, we can draw the following conclusions:
Convergence: Both proportions for sums 9 and 10 decrease and start to converge as the number of rolls increases. This is in line with the Law of Large Numbers, which states that as the number of trials increases, the experimental probabilities (proportions) will converge to the true probabilities.
Stabilization: As the number of rolls gets larger, the variance in the proportion for each sum seems to reduce, and the values stabilize. This suggests that the larger the number of rolls, the closer we get to the expected theoretical probability for each sum.
Comparison of Sums: The red dots (sum 10) and the blue dots (sum 9) show the proportion of occurrences of each sum. It appears that the sum of 10 consistently occurs slightly more frequently than the sum of 9, as the red dots are generally above the blue dots, especially as the number of rolls increases and the proportions stabilize.
Probability Difference: The noticeable separation between the two sums’ proportions, even as the number of rolls increases, suggests that there may indeed be a difference in the likelihood of rolling a sum of 9 versus a sum of 10. Given that the number of combinations to achieve both sums is the same, this difference might seem counterintuitive at first, but it highlights the difference in distribution of these combinations across the sample space of dice rolls.
Gamblers’ Observation: If we relate this to the historical context where gamblers felt that a sum of 10 was more likely than a sum of 9, the simulation results seem to support their observations, despite the equal number of combinations for both sums.
In summary, the simulation suggests that while both sums 9 and 10 tend towards their true probabilities with a large number of rolls, sum 10 does indeed seem to occur slightly more frequently than sum 9. This aligns with the gambler’s observation and can be attributed to the distribution of the sums within the sample space of possible dice rolls.