Examples:
 

 

Example - Dice

* The "\" symbol has been used at the end of lines to indicate that the line was too long for the display and has been
wrapped to the line below in order to fit within the width of the web page. These lines would need to be joined in the normal
program editor.


I. Introduction

This program illustrates a fundamental theorem of probability — the Central Limit Theorem — which states that the distribution of the sum of a large number of independent identically distributed variables is approximately normal, no matter what the distribution of each variable is. The application used is the total score obtained when n (fair) dice are thrown.



II. Statistics Involved

The population mean score is ; the population standard deviation is (because of the additive property of mean and variance)



III. How the Program Works

1) Functionalities

The bar chart showing the frequency for each score is then amended to reflect the new value. Below is an example of what the results typically look like for ten dice and a few hundred samples.

It is clear that this resembles a normal bell-shaped curve; clicking the Add Normal curve button will demonstrate this:

When the Probabilities button is clicked, a dialog box is displayed:

Entering values for the total score and clicking Calculate will display the result under the normal approximation.


2) The samp() Procedure

Every time the dice are ‘thrown' the samp() procedure is called. Each die is assigned a value between 1 and 6 inclusive, with equal probability, and the total is calculated using the Summation() method.

SUB samp()
   'Roll the dice once
   DIM die%%(numdice%%)
   
   FOR i%% = 1 TO numdice%%
     die%%(i%%) = INT ( RND (1) * 6 + 1)
   NEXT i%%
   
   total%% = Superbase.Summation("die%%(i%%)","i%%",1,numdice%%)
   num%%(total%%) = num%%(total%%) + 1
   n%% = n%% + 1
   
   FOR i%% = 1 TO numdice%%
     CALL diedraw(i%%,die%%(i%%))
   NEXT i%%
   
   Dice.Refresh()
   CALL graphdraw()
   CALL calcs()
 END SUB 

3) T he calcprob() Procedure

These probabilities can be easily calculated because of the DistNormal() function (a continuity correction of one half is applied because a continuous normal model is being fitted to discrete data).

SUB calcprob()
   DIM d AS Dialog

   SET d = me.Parent
   lower%% = INT ( VAL (d.lower.Text))
   upper%% = INT ( VAL (d.upper.Text))
   IF lower%% > upper%% OR d.lower.Text = "" OR d.upper.Text = "" THEN 
     d.lower.Text = ""
     d.upper.Text = ""
     d.lower.SetFocus()
     d.display.Caption = ""
   ELSE 
     plower% = Superbase.DistNormal((lower%% - 0.5 - pmean%) / psd%)
     pupper% = Superbase.DistNormal((upper%% + 0.5 - pmean%) / psd%)
     prob% = pupper% - plower%
     d.display.Caption = STR$ (prob%,"0.000")
   END IF 
 END SUB