Teaching Probability and Statistics:
A Problem Solving Approach

by
David Thompson
Minnesota Academy of Mathematics & Science
The Minnesota Preparatory Schools
1165 West Broadway
Winona MN 55987.
dave.thompson@academy.mps.org

Published in
Mathematica in Education and Research
Vol.4 No.1
Copyright 1995 TELOS/Springer-Verlag

This paper describes the use of Mathematica in teaching Probability and Statistics at the High School level.  The material is also very well suited to College level classes, both for beginning and more advanced students. It gives some examples I have used in teaching my Probability and Statistics class at the Minnesota Academy of Mathematics and Science.

Introduction

I recently taught a year-long course in Probability and Statistics at the
Minnesota Academy of Mathematics and Science.  The faculty of the Academy
decided to adopt Mathematica across the curriculum
(We believe we are the nation's first-ever high school to have a site
license for Mathematica).  A problem solving approach is embraced in many
of our classes.  I have found that after the students have overcome the
initial stages of learning Mathematica they are able to do problems which
have hither-to been the domain of experts in the field.
I started teaching this class in the traditional way, with a study of
elementary combinatorics.  I then quickly moved on to finite probability
theory, as in the examples "Tumbling Dice", "The Up Escalator", and
"Matching Shoes."   In these examples we see two different ways to solve
Probability problems: using a Monte Carlo approach (that is - computer
simulation of random events - such as tossing coins), and an exact
Enumeration approach.  Students are encouraged to get the answers of such
problems in as many different ways as possible (including using pencil and
paper)!

Another example uses a Monte Carlo approach to approximate Pi in the
example "A piece of Pi."

Using the standard Statistics packages, we can illustrate some important
theoretical aspects of Statistics including the central notions behind
elementary Inferential Statistics.  For example, the most important theorem
in Statistics - The Central Limit Theorem.   I conclude with a poker
example - which illustrates the programming capabilities of Mathematica in generating random events.

I should say that students are first of all introduced to the rudiments of
using Mathematica (using [Theodore W. Gray and Jerry Glynn 1992]) and are
then given many exercises in list handling - similar to those in Blachman's
book (pages 134 and 135) and ones specifically geared to finite probability
theory like the following example:

Problem

(a) Generate 10 trials of a throw of one die. Calculate the mean value of
the throws.

(b) Generate 10 trials of a throw of two dice. Calculate the mean value of
the sum of the throws.

Answers:

(a)

randomDie := Random[Integer,{1,6}]

tenTrials = Table[randomDie,{10}]

Mean[tenTrials]//N

(b)

tenSumTrials = Table[randomDie+randomDie,{10}]

Mean[tenSumTrials]//N

Students take a Mathematica laboratory - which is a three hour session once
a week in which they work in groups of either two or three (three, in some
senses, is ideal). There is continual interaction between student groups
and the instructor circulates from computer to computer, guiding students.
The instuctor, indeed, acts as the "guide on the side" and often students
will actively pursue their own investigative work. The Mathematica
application allows students to become engaged in statistical science - in
the sense of enabling them to do their own trial and error experiments.
They are then able to do problems like the ones following, in which they
generate their own Mathematica code. The students are asked to answer these
problems using as many different methods that they can think of and then
asked to compare their results. It si worth noting that by the time the
students come to do these problems they have been introduced to various
theories of Probability (Subjective, Objective and Relatistic Viewpoints)
and are asked to relate their results to these last two viewpoints.

Example Problems From Finite Probabilty Theory:

Tumbling Dice

PROBLEM: Find the probability that when three dice are tossed the sum of
the numbers is fourteen.

MONTE CARLO METHOD (Relativistic):

First we simulate 500 throws of 3 dice:

trialsOfThreedDice = Table[Random[Integer, {1,6}],
{500}, {3}];

Here is the shortened version:

Short[trialsOfThreedDice]

Then we use the select command with the Boolean function sumToFourteen to
select the ones that add up to fourteen:

sumToFourteen[{x_,y_,z_}] :=  x+y+z == 14
trialsThatSumToFourteen = Select[trialsOfThreedDice,
sumToFourteen];
Short[trialsThatSumToFourteen]

Dividing the length of this list by the number of trials gives us the
approximate probability:

approxProbOfFourteen = Length[trialsThatSumToFourteen]/
Length[trialsOfThreedDice]//N

EXACT ENUMERATION METHOD (Objective):

We use the function Outer to enumerate all the possibilities and again
select the ones that add up to fourteen:

fourteenList = Select[Partition[Flatten[
Outer[List, Range[6], Range[6], Range[6]]], 3],
sumToFourteen];
Short[fourteenlist]

We now have the exact probability:

Length[fourteenList]/6^3//N

The Up Escalator

Problem: Find the probability that in throwing a die three times in a row
we get a sequence of ascending numbers.
[Chung 1979]

APPROXIMATE MONTE CARLO SOLUTION:

The following is a Monte Carlo simulation which generates 1000 trials, each
trial consisting of a triple of three random integers in the range 1
through 6.  It then counts the number of these trials in which the numbers
are ascending and divides this number by 1000 (the length of the list r) to
give the approximate probability of such an event.

ascending[{x_,y_,z_}] :=  x < y < z
r = Table[Random[Integer, {1, 6}], {1000}, {3}];
Length[Select[r, ascending]]/Length[r]//N

EXACT ENUMERATION SOLUTION:

Another approach is to enumerate all the possibilities - thus giving the
exact probability of such an event.  It again uses the generalized outer
product Outer:

allEvents = Partition[Flatten[Outer[List, Range[1,6],
Range[1,6], Range[1,6]]], 3];

totalNumberOfEvents = Length[allEvents]

ascendingevents = Select[allEvents, ascending];
Short[ascendingEvents]

numberOfAscendingEvents = Length[ascendingEvents]

exactProbability = numberOfAscendingEvents/
totalNumberOfEvents

exactProbability//N

Matching Shoes

Problem: Four shoes are taken at random from five different pairs. What is
the probability that there is at least one pair among them? [Chung 1979]

ENUMERATION SOLUTION

We can represent our ten shoes in the following list:

shoeList = {1,2,3,4,5,1,2,3,4,5};

We can then take all groups of four shoes as follows:

groupsOfFourShoes = KSubsets[shoelist, 4];
Short[groupsOfFourShoes]

We can check we have them all as follows:

{Length[groupsOfFourShoes], Binomial[10,4]}

If there are no pairs in the generated list, then the length of the
Intersection of the list will be exactly 4:

noPairs[x_List] := Length[Intersection[x]]==4

groupsWithNoPairs = Select[groupsOfFourShoes, noPairs];
Short[groupsWithNoPairs]

Length[groupsWithNoPairs]

shoeProbability = 1-Length[groupsWithNoPairs]/
Length[groupsOfFourShoes]

shoeprobability//N

Geometric Probability Theory Example:

A Piece of Pi

Here the students are taught the theory behind finding areas
using a Monte Carlo Technique and then asked to write their own Mathematica
code to simulate the process (they usually need a hint or two!).

Problem: Use a computer dart board to calculate Pi.

One way we can do this is as follows: Generate 3000 points in the square
[0,2]x[0,2] and color them green.  Then select the points inside the
inscribed circle and color them red.  We would expect the ratio of the
number of red points to the total number of points to be that of the ratio
of the area of the circle to that of the area of the square - that is, in
the ratio Pi:4.
[Klitz Jr. 1981]

The following function checks if a given point is in the circle with radius
1 centered at (1,1):

insidecircle[{x_,y_}] :=  (x-1)^2+(y-1)^2 <= 1

Generate 3000 random points in the circumscribing square [0,2]x[0,2]:

points = Table[{Random[Real,{0,2}], Random[Real,{0,2}]},
{3000}];

pointsinsidecircle = Select[points, insidecircle];

All the points inside the circle are red:

redpoints = {Red, Map[Point, pointsinsidecircle]};

All points start off green:

allpoints = {Green, Map[Point, points]};

This plots the circle and its circumscribing square along with the points
inside and outside the circle (the red ones inside):

Needs["Graphics`Colors`"]

Show[Graphics[
	{PointSize[0.01], allpoints, redpoints,
	 Circle[{1,1},1],
	 Line[{{0,0},{0,2},{2,2},{2,0},{0,0}}]},
	AspectRatio -> Automatic]]

Finally we calculate the ratio of the points inside the circle to the total
number of points (3000 in this case):

approximationtopi = 4 Length[pointsinsidecircle]/
Length[points]//N;
Print["< is approximately ", approximationtopi]

Of course we would expect to get a better approximation by generating more
random points.

It is Mathematica's list handling abilities that really make enumerative
combinatorics and statistical sampling exceedingly easy. This enables
students to do repeated trials and do statistical experiments to discover
or confirm theoretical results that are later discussed in theory class.
This is so helpful when dealing with big theorems like the Central Limit
Theorem.  This theorem is indeed central to the study of statistics, but
the theory behind it is even difficult for beginning graduate students (let
alone high school students!).  The students repeat their own such sampling
experiments and start to see patterns emerge. They are asked to identify
these patterns and to generalize their results if they can. Although they
may still not totally understand the abstract theory behind the Central
Limit Theorem, they will have, at least, an intuitive idea of why the
result is true and how it is used in practice.
This kind of investigative work can be done on paper (See  [Kissane Barry
K. 1981.]) but is much easier to do using a computer.

The Central part of The Central Limit Theorem:

The students are given an arbitrary distribution, for example, the
chi square distribution below.  They are then given a worksheet detailing
the steps necessary to investigate the sampling-mean distribution (in a
fashion similar to [Kissane Barry K. 1981]):
They then generate their own  Mathematica code to achieve this goal. This
can be done, for example, as follows:

arbDist = ChiSquareDistribution[5];
arbPdf = PDF[arbDist, x];
arbPlot = Plot[arbPdf, {x, 0, 20}];

We now take 1000 samples of size 30 from this distribution:

samps = Table[Random[arbDist], {1000}, {30}];

and compute the corresponding sample means:

sampMeans = Map[Mean, samps];

In order to graphically represent our data we need the maximum and minimum
values of this list:

maxi = Max[sampMeans]

mini = Min[sampMeans]

We now use Bincounts to find the number of points in the bins from mini to
maxi with binsize equal to 0.1.

theBinSize = 0.1;

binData = BinCounts[sampmeans, {mini-theBinSize/2, maxi,
theBinSize}]

Short[binData]

In order for the area under our graph to be equal to 1 we must compensate
for the fact that the binsize is 0.1 and the total frequency is 2000:

xValues=Range[mini-theBinSize/2,
maxi,theBinSize];

binDataSum = Apply[Plus, binData];
binData = binData/(binDataSum theBinSize);
graphPoints = Transpose[{xValues, binData,
Table[theBinSize, {Length[xValues]}]}];

Short[graphPoints]

Now we do a GeneralizedBarChart of this data and superimpose this with the
graph of the Standard Bell Graph:

graph = GeneralizedBarChart[graphPoints,
DisplayFunction->Identity];

meanie = Mean[arbDist];

stanDevie = StandardDeviation[arbDist]/Sqrt[30]//N

theoreticSampleDist =
        NormalDistribution[meanie,stanDevie];
theoreticSampleDistPdf = PDF[theoreticSampleDist, x];

theoreticSampleDistPdfGraph =
        Plot[theoreticSampleDistPdf,
        {x, mini, maxi}, PlotStyle->{Thickness[.008]},
        DisplayFunction->Identity];

Show[graph,theoreticSampleDistPdfGraph,
PlotRange->All];

We can see that the empirical distribution is modeled pretty well by the
Normal Distribution, exactly as we would expect from the Central Limit
Theorem.

The students need have no previous experience of using Mathematica before
taking this class and are not given any instruction in structured
programming.  Instead they interact at a very basic level with the
computer. However, by a somewhat dialectic process of trial and
modification, the students can construct quite complex programs somewhat
similar to the program in the next example.  My students, in fact,
developed a program that would essentially generate two poker hands (and
display the results graphically) and then have the program check which of
the two hands is better.

The complete program is a little long to include in this paper, since, to
acheive their graphics output they needed to generate a list of fiftytwo
graphics for each card in a deck. For example, the following generates an
Ace of Hearts:

acehearts=Show[Graphics[{Line[{{0,0},
{1,0},{1,1},{0,1},{0,0}}],
Text["A",{.15,.9}],
{RGBColor[1,0,0],Text[")",{.5,.5}]},
Text["A",{.9,.15}]}],
AspectRatio->GoldenRatio,DefaultFont->{"Symbol",15}];

Poker-A Gambler's Anonymous Function

PROBLEM: Generate a poker hand and get the program to print out what kind
it is (to make the exercise easier we exclude runs from consideration).

The following generates a deck of cards:

fullDeck = Flatten[Outer[Times, Union[{"jack", "queen",
"king", "ace"}, Range[2,10]],
{Spades,Diamonds,Hearts,Clubs}]]

The following StringOrder will make gambling easier for you:

$StringOrder = {{"j", "A"}, {"b", "B"}, {"c", "C"},
{"d", "D"}, {"e", "E"}, {"f", "F"}, {"g", "G"},
{"h", "H"}, {"i", "I"},
{"q", "J"},
{"k", "K"}, {"l", "L"}, {"m", "M"}, {"n", "N"},
{"o", "O"}, {"p", "P"}, {"a", "Q"}, {"r", "R"},
{"s", "S"}, {"t", "T"}, {"u", "U"}, {"v", "V"},
 {"w", "W"}, {"x", "X"}, {"y", "Y"}, {"z", "Z"},
  "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};

Using this order we can sort the values by ascending card value (Ace being
high):

values = Union[{"jack", "queen",
"king", "ace"}, Range[2,10]]

The function randomize is used to shuffle the deck and then we can generate
a poker hand as follows:

randomize[anylist_List] :=
Map[Last, Sort[Map[{Random[],#}&,anylist],
(#1[[1]] > #2[[1]])&
]]

-See [Blachman Nancy 1991] page 302.

pokerHand = Take[randomize[fullDeck], 5];

Print["Hand is: ", hand=Sort[pokerHand]];

The following give the face values and the suits:

faceValues = Map[FullForm[#][[1,1]]&,hand]

suits = Map[FullForm[#][[1,2]]&,hand]

and here are the corresponding frequencies:

Needs["Statistics`DataManipulation`"]

ffv = 
   frequenciesOfFaceValues=Frequencies[faceValues]

frequenciesSuits = Frequencies[suits]

The following is the list of sorted frequencies:

expression =
   Sort[Map[#[[1]]&, frequenciesOfFaceValues]]

The following commands sort the hand out according to what expression and
frequenciessuits evaluate as, and hence according to what kind of hand we
have, and then prints the result (The program has a Switch command inbedded
in an If command):

If[Length[frequenciessuits]!=1,
  Switch[expression, {1,1,1,1,1},
Print["It just has a ", Last[Sort[faceValues]], " High"],
{1,1,1,2},
Print["It has one pair---two ",
Select[ffv,#[[1]]==2&][[1,2]],"'s"],
{1,2,2},
Print["It has two pair-two ",
Select[ffv,#[[1]]==2&][[1,2]] ,
"'s  and two ",
 Select[ffv,#[[1]]==2&][[2,2]], "'s"],
{1,1,3},
Print["It has three of a kind---three ",
Select[ffv,#[[1]]==3&][[1,2]], "'s"],
{2,3},
Print["It has a full house-two ",
Select[ffv,#[[1]]==2&][[1,2]],
 " 's and three ",
 Select[ffv,#[[1]]==3&][[1,2]], "'s"],
{1,4},
Print["It has four ",
Select[ffv,#[[1]]==4&][[1,2]] ,"'s"]],
Print["It has a " ,
Last[Sort[faceValues]], " High Flush"]]

Repeatedly running this kind of program the students can find approximate
probabilities for the various hands that one can be dealt.

Conclusion

With the use of examples like those given above the subject of statistics
can come alive.  We can illustrate important results like the Central Limit
Theorem without going into involved proofs. Enumerative Combinatorial
Problems (which traditionally students find particularly difficult) are
easily dealt with and this can greatly increase the students understanding.
This kind of approach, in conjunction with a more traditional one
emphasizing the theoretical aspects of the subject, can help students in
their study of Statistics - making the subject amenable to a wider
audience.

Acknowledgments

I would like to thank my colleagues: Peter Guidinger, Myoung Eun Lee, Mark
Ordal.  I would also like to thank my students: Becky, Brian, Casey,
Catherine, Clay, Damien, Emily, Erin, Joe, Mandi, Maria, and Monique.

References

Blachman Nancy 1992. Mathematica : a Practical Approach. pp. 302. Prentice Hall

Chung, Kai Lai 1979. Elementary Probability Theory with Stochastic
Processes. Springer Verlag.

Theodore W. Gray and Jerry Glynn 1992. The beginner's guide to Mathematica
(Version 2).Addision-Wesley

Klitz Jr. Ralph H. 1981. Projects In Teaching Statistics and Probability
National Council of Teachers of Mathematics 1981 Yearbook. Edited by Albert
P Shulte and James Smart.

Kissane Barry K. 1981. Activities in Inferential Statistics  In Teaching
Statistics and Probability  National Council of Teachers of Mathematics
1981 Yearbook. Edited by Albert P Shulte and James Smart.

Olson Chester L 1987. Essentials of Statistics. Allyn and Bacon

Version

$Version

Biography

David Thompson is an Instructor of Mathematics at the Minnesota Academy of
Mathematics and Science.  He received his Ph.D. in Mathematics from the
University of North Carolina at Chapel Hill in 1988.  He trained as a High
School Teacher of Mathematics in his native Northern Ireland and has about
ten years experience teaching Mathematics at both Secondary and University
level.