In: Math
A fair coin is tossed until the first head occurs. Do this experiment T = 10; 100; 1,000; 10,000 times in R, and plot the relative frequencies of this occurring at the ith toss, for suitable values of i. Compare this plot to the pmf that should govern such an experiment. Show that they converge as T increases. What is the expected number of tosses required? For each value of T, what is the sample average of the number of tosses required?
A fair coin is tossed until the first head occurs. Let X be the number of tosses required. Then X ~ Geometric(p = 0.5).
We will use rgeom function in R to generate the samples for T = 10; 100; 1,000; 10,000
For T = 10, run the below R code to plot the relative frequencies and compare this plot to the pmf of Geometric distribution.
x1 = rgeom(10, 0.5)
hist(x1, probability = TRUE, xlab = "X", main = "Relative frequencies")
k = c(0:14)
lines(k, 0.5^k, lwd = 2, col = "blue") # To plot pmf P(X = k) = 0.5^k
For T = 100, run the below R code to plot the relative frequencies and compare this plot to the pmf of Geometric distribution.
x2 = rgeom(100, 0.5)
hist(x2, probability = TRUE, xlab = "X", main = "Relative frequencies")
k = c(0:14)
lines(k, 0.5^k, lwd = 2, col = "blue") # To plot pmf P(X = k) = 0.5^k
For T = 1000, run the below R code to plot the relative frequencies and compare this plot to the pmf of Geometric distribution.
x3 = rgeom(1000, 0.5)
hist(x3, probability = TRUE, xlab = "X", main = "Relative frequencies")
k = c(0:14)
lines(k, 0.5^k, lwd = 2, col = "blue") # To plot pmf P(X = k) = 0.5^k
For T = 10000, run the below R code to plot the relative frequencies and compare this plot to the pmf of Geometric distribution.
x4 = rgeom(10000, 0.5)
hist(x4, probability = TRUE, xlab = "X", main = "Relative frequencies")
k = c(0:14)
lines(k, 0.5^k, lwd = 2, col = "blue") # To plot pmf P(X = k) = 0.5^k
We see that as T increases, the PMF (shown in blue line) is more approaching towards the relative frequencies plot. Thus, hey converge as T increases.
From Geometric distribution, expected number of tosses required = 1/p = 1/0.5 = 2
Sample average of the number of tosses required for T = 10 is 0.7
mean(x1)
Sample average of the number of tosses required for T = 100 is 0.78
mean(x2)
Sample average of the number of tosses required for T = 1000 is 1.031
mean(x3)
Sample average of the number of tosses required for T = 10000 is 1.0079
mean(x4)