gmacro Coins ### Simulation to illustrate the evolution of the relative frequency of ### heads as a fair coin is tossed many times. The relative frequency ### estimates the exact probability of 1/2 . ### Execute this macro in a blank Minitab project. ### Macro created 2003 03 14 and last modified 2021 02 16 by G.H. George ### mtitle / endmtitle needed to keep all output in one output pane mtitle "Coin tossing simulation" erase c1-c3 # needed to ensure clear space in the worksheet ### Constants: ### k1 = coin index number (loop counter) let k2 = 1500 # number of coins let k3 = 0 # accumulator = number of heads in the first k1 coins ### Columns: name c1 'trial' # number of coin tosses so far name c2 'head?' # = 1 if this coin is a head, = 0 if a tail name c3 'Rel.Freq.' # proportion of heads so far ### Place the first (k2) natural numbers into column c1: set c1 1:k2 end. ### assign 0 (tail), 1 (head) randomly to the k2 coins: random k2 c2; integer 0 1. ### toss the coin k2 times, recording number & proportion of heads so far: do k1=1:k2 let k3 = k3 + c2(k1) let c3(k1)=k3/k1 enddo let k1 = c3(k2) note The last estimated probability of a head is print k1 note Compare this with the true probability of 0.500000 ### Plot the relative frequency as a time series plot: Tsplot 'Rel.Freq.'; Scale 2; MODEL 1; Tick 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7; Min 0.3; Max 0.7; EndMODEL; AxLabel 1; ADisplay 1; Label "# coins"; ALevel 1; Index; Connect; Symbol; Type 0; Size 0.7; Grid 2; Title "ENGR 4421 Empirical Probability"; SubTitle "Coin Tossing Experiment"; Footnote; FPanel; NoDTitle. endmtitle endmacro