Virtual Coin Toss

Needs["Statistics`DescriptiveStatistics`"]

The textbook states the relative frequency of event A approaches the probability of A as the sample size approaches infinity. In math terms,.....

P (A)  =  
      Limit[((Frequency of A)/n), 
        n -> ∞]

How does this work? A simple coin toss experiment can show this.  A fair coin has a probability of 0.50 (50%) of landing heads-up.  According the textbook, tossing a coin over a large number of times and recording the relative frequency of the coin landing heads-up will approach the value of 0.50. What is true is that the outcome of tossing a coin 1000 times is the same as tossing 1000 coins once.  What makes this convenient is that we can have the computer toss the coins, keep track of the outcomes and compute the relative frequency.  
        
        Below is a little Mathematica program. There are four initial settings.
        	Tosses -> the number of coins that the computer will toss at one time.
        	a-> a counter for the program.
         	H-> this will store the number of tosses that are heads.
          	T-> this stores the number of tail tosses.
            
            As the user, you can change the number of tosses (it is currently set at 100) and evaluate the program to find out how many heads and tails result from the toss. Note: as you increase the number, the time needed by the program to generate the results increases. Tossing more than 50,000 coins can take a number of minutes.

Tosses = 100; a = 0;   H = 0;   T = 0;

\(\(For[a = 1, \ 
        a\  <= Tosses, \(a++\)
		{\ 
			b = Random[]; 
			If[
              b > 0.500, 
				\ H += 1, 
				\ T += 
                1]; 
			\ Return[H]; 
			\ Return[
              T];
		}\ ];\)\)

H

T

RFHeads gives the relative frequency outcome for the number of heads.

RFHeads = N[(H/(H + T))]

Below are three data sets of trials I conducted. RF100 stores the relative frequency outcomes of ten trials -each trial consists of tossing 100 coins. RF1000 has ten trials -each trial  is the toss of 1,000 coins. RF10000 contains ten trials of 10,000 tosses.

If the limit condition is true, the trials with the larger number of tosses will have outcomes around 0.50 with very little variation.  The trials with the small number number of tosses will show more variation. We will able to see the variation through the range value (difference between the max. and min. value) and the standard deviation value.

RF100 = {0.49, 0.47, 0.51, 0.62, 0.45, 0.6, 0.46, 0.38, 0.49, 
          0.51};

RF1000 = { 0.51,  0.508, 0.478, 0.503, 0.524, 0.495, 0.49199, 
          0.493, 0.491, 0.502};

RF10000 = {0.4931,  0.4923,  0.5094999,  0.5051, 0.507, 0.5098, 
          0.4979, 0.49859, 0.505299, 0.495199};

\(\(Descriptives\  = \ {
	{"Statistics", \ "RF100", "RF1000", "RF10000"}, 
		{"Min", \ Min[RF100], \ 
            Min[RF1000], \ Min[RF10000]}, 
		{"Max", \ Max[RF100], \ 
            Max[RF1000], \ Max[RF10000]}, 	\ 
		{"Range"\ , \ 
            Max[RF100] - Min[RF100], Max[RF1000] - Min[RF1000], \ 
            Max[RF10000] - Min[RF10000]}, 
			{"Mean", \ 
            Mean[RF100], \ Mean[RF1000], \ 
            Mean[RF10000]}, 
			{"StD", \ StandardDeviation[RF100], 
            StandardDeviation[RF1000], \ 
            StandardDeviation[RF10000]}};\)\)

TableForm[Descriptives]

Above are the descriptive statistics. In every case, the mean relative frequency is around 0.50 (50%).
    
    The table of descriptive statistics supports the limit condition. The first column reports the descriptive statistics for the trials consisting of 100 coins. The range of values between the max and min is 0.24 (24.%). The standard deviation is 7.0%. The last column reports the statistics for the trials consisting of 10,000 coins. The range of relative frequency values between the max and min is 0.018 (1.8%) and the standard deviation is 0.0067 (0.67%) . The variation for column three is less than the variation found in column one. The variation reported in column 2 lies between columns 1 and 3.