Discrete Data

Calculating range,variance and standard deviation

Lesson Overview

Goals

Students will be able to compute the Range of a Discrete Random Variable

Students will be able to compute the Variance of a Discrete Random Variable

Student will be able to compute the Standard Deviation of a discrete random variable

Instructor Presentation

Introduction

Recall that when we describe the distribution of a variable, we describe its center, spread and shape.  We will be using the Range, the  Variance and the Standard Deviation  to describe the spread.
Recall that we calculated the Mean in a previous chapter.  We learned that there are two calculations for the Mean, the population Mean ((Subscript[μ, X])) and the sample Mean ((OverBar[x])).  To calculate the spread of the Discrete Random Variable we will use a calculation of the Mean.

Lets look at two different Discrete Random Variables, the IQ scores from two different universities.

univaplot=Histogram[universitya,ChartElementFunction->"FadingRectangle",ChartStyle->Orange,ChartLabels->{Placed[{"University A"},Above]}];
univbplot=Histogram[universityb,ChartElementFunction->"FadingRectangle",ChartStyle->Blue,ChartLabels->{Placed[{"University B"},Above]}];
GraphicsRow[{univaplot,univbplot},ImageSize->600]

The simplest measure of spread is the Range.  It is by far the easiest to calculate.

The Range, R, of a variable is the difference between the largest data value and the smallest data value.  That is,

Range = R = largest data value - smallest data value

Lets calculate the Range of the two university IQ test results.

rangea=Max[universitya]-Min[universitya]
rangeb=Max[universityb]-Min[universityb]

We can see from above that the spread of IQ test results from University B is far less than the spread of IQ test results from University A.

Example

Example 1

Calculate the Range for the following examples:

1.1: Calculate the Range for flight times (minutes) for a flight from Chicago to Seattle.  The recorded flight times are 282,270,260,266,257,260, and 267.

1.2:  Calculate the Range for the number of fish caught on a ten day fishing trip.  The daily fish count is 9, 24, 8, 9, 5, 8, 9, 10, 8, and 10.

1.3:  Old Faithful erupts many times each day.  The length of time for each eruption varies.  The length of the eruptions were recorded (in seconds) and the following lengths were recorded:  109, 109, 99,105, 103, 103, 94, 102, 99, 106, 90, 104, 110, 110, 103, 109, 109, 111, 101, 101, 110, 102, 105, 110, 106, 104, 104, 100, 103, 102, 120, 90, 113, 116, 95, 105, 103, 101, 100, 101, 107, 110, 92, and 108.    Find the Range of the eruption times?

Exploration

While the Range allows us to see the spread of the data based on the Maximum and Minimum values, it fails to give us any information about any of the other data elements.  In order to gain in insight into how all elements of the data set are arranged, we introduce the concept of Variance.  Variance gives us details about how the data elements by describing the deviation around the mean.  Variance is represented symbolically as (σ^2).
Variance is a function of subtracting the X data elements from the mean value of the data set, called deviation.  The deviation from the mean for the ith data element can be represented as:

(Subscript[x, i]) - μ

Since the mean is the central value, logically we can understand the values of x are found above the mean and values of x are found below the mean.  This results in some deviations being negative and some being Positive.  Therefore, when we add up all of the deviations we will obtain a total of 0.  Mathematically represented as:

Σ ((Subscript[x, i]) - μ)  =  0

Since we are looking for a measure of spread, the distance that the data value fall from the mean, we need to find a method for eliminating the summing to zero problem.  Additionally, it also follows that the farther away the data element is from the mean, the greater the contribution to the overall spread the data value will have.  In order to resolve both problems, summing to zero and contribution for distance, we will square the deviation values ( ( (Subscript[x, i]) - μ )^2   .  And by adding all of these deviations, we get a measure of spread for the data set.

The population Variance of a variable is the sum of the squared deviations about the population mean divided by the number of observations in the population, N.

Variance = (σ^2)  = (( Σ ((((Subscript[x, i]) - μ))^2))/N)

Since we are discussing Discrete Random Variables, we often are given the discrete value x and the Probability of observing the discrete variable x.  For Discrete Random Variables when we are given the P(x) we can calculate the variance with the following formula:

Variance = (Subscript[(σ^2), x])  =  Σ [((((Subscript[x, i]) - μ))^2)* P(x)]
or
Variance = (Subscript[(σ^2), x])  =  Σ [(x^2)* P(x)] -(Subscript[(μ^2), x])

To find the standard deviation of a Discrete Random Variable, take the square root of the variance.  That is:

(Subscript[σ, x])  =   (Sqrt[(Subscript[(σ^2), x])])

Concept Exploration

Further Example of Variance

Lets try to calculate a couple Variances.

We are given the following Discrete Probability Distribution:

frequencytable={{0,0.01},{1,.10},{2,.38},{3,.51}};
fulldata=Prepend[frequencytable,{"Goals per Game(x)","Probability P(x)"}];
DisplayTable[fulldata,TableLabel->"Goals Made Per Game",ItemSize->13]

(Labeled[({{"Goals per Game(x)", "Probability P(x)"}, {0, 0.01`}, {1, 0.1`}, {2, 0.38`}, {3, 0.51`}}), "Goals Made Per Game"])

Compute the variance and the standard deviation for the above.

Recall that the (Subscript[μ, x]) is the sum of the Discrete Variable times the Probability of obtaining that variable.  Written as Σ(x*P(x)) .  Therefore the mean is

mean=Total[{0*0.01}+{1*0.10}+{2*0.38}+{3*0.51}]

Now we are able to calculate the variance.

frequencytable={{0,0.01,"(0-2.39)^2*0.01 = 0.057121"},{1,.10,"(1-2.39)^2*0.1 = 0.19321"},{2,.38,"(2-2.39)^2*0.38 = 0.057798"},{3,.51,"(3-2.39)^2*0.51 = 0.189771"},{"","","Σ(x-(Subscript[μ, x]))^2*P(x) = 0.4979"}};
fulldata=Prepend[frequencytable,{"Goals per Game(x)","Probability P(x)","(x-(Subscript[μ, x]))^2* P(x)"}];
DisplayTable[fulldata,TableLabel->"Goals Made Per Game",ItemSize->13]

(Labeled[({{"Goals per Game(x)", "Probability P(x)", "(x-\!\(\*SubscriptBox[\(μ\), \(x\)]\)\!\(\*SuperscriptBox[\()\), \(2\)]\)* P(x)"}, {0, 0.01`, "(0-2.39\!\(\*SuperscriptBox[\()\), \(2\)]\)*0.01 = 0.057121"}, {1, 0.1`, "(1-2.39\!\(\*SuperscriptBox[\()\), \(2\)]\)*0.1 = 0.19321"}, {2, 0.38`, "(2-2.39\!\(\*SuperscriptBox[\()\), \(2\)]\)*0.38 = 0.057798"}, {3, 0.51`, "(3-2.39\!\(\*SuperscriptBox[\()\), \(2\)]\)*0.51 = 0.189771"}, {"", "", "Σ(x-\!\(\*SubscriptBox[\(μ\), \(x\)]\)\!\(\*SuperscriptBox[\()\), \(2\)]\)*P(x) = 0.4979"}}), "Goals Made Per Game"])

The Variance is 0.4979 and therefore, the standard deviation is (Sqrt[0.4979])   or   0.70562.

Example

Example 2

Calculate the Variance and Standard Deviation for the following examples:

2.1: Calculate the Variance and Standard Deviation for the number of field goals kicked per football game.

frequencytable={{0,0.2},{1,.2},{2,.2},{3,.2},{4,.2}};
fulldata=Prepend[frequencytable,{"Field Goals Kicked per Game(x)","Probability P(x)"}];
DisplayTable[fulldata,TableLabel->"Field Goals Kicked Per Game",ItemSize->13]

(Labeled[({{"Field Goals Kicked per Game(x)", "Probability P(x)"}, {0, 0.2`}, {1, 0.2`}, {2, 0.2`}, {3, 0.2`}, {4, 0.2`}}), "Field Goals Kicked Per Game"])

2.2:  Calculate the Variance and Standard Deviation for the following distribution.

frequencytable={{10,0.1},{20,0.23},{30,0.22},{40,0.4},{50,0.05}};
fulldata=Prepend[frequencytable,{"x","P(x)"}];
DisplayTable[fulldata,TableLabel->"Distribution",ItemSize->13]

(Labeled[({{"x", "P(x)"}, {10, 0.1`}, {20, 0.23`}, {30, 0.22`}, {40, 0.4`}, {50, 0.05`}}), "Distribution"])

2.3:  We are given the following bar chart.  For 50-54 year old mothers giving birth in 2005, the chart highlights the number of children that Mother has.  Please calculate the variance and standard deviation of the data set.

BarChart[{0.292,0.251,0.167,0.128,0.060,0.031,0.022,0.049},ChartElementFunction->"GlassRectangle",ChartStyle->"AvocadoColors",PlotLabel->"Number of Children: 50 to 54-Year-Old Mothers",ChartLegends->{"1","2","3","4","5","6","7","8"},ChartLabels->
{Placed[{"0.292","0.251","0.167","0.128","0.060","0.031","0.022","0.049"},Above]}]

Examples Answer Key

Example 1

Calculate the Range for the following examples:

1.1: Calculate the Range for flight times (minutes) for a flight from Chicago to Seattle.  The recorded flight times are 282,270,260,266,257,260, and 267.

flightrange=Max[{282,270,260,266,257,260, 267}]- Min[{282,270,260,266,257,260, 267}]

1.2:  Calculate the Range for the number of fish caught on a ten day fishing trip.  The daily fish count is 9, 24, 8, 9, 5, 8, 9, 10, 8, and 10.

fishrange= Max[{9,24,8,9,5,8,9,10,8,10}] - Min[{9,24,8,9,5,8,9,10,8,10}]

1.3:  Old Faithful erupts many times each day.  The length of time for each eruption varies.  The length of the eruptions were recorded (in seconds) and the following lengths were recorded:  109, 109, 99,105, 103, 103, 94, 102, 99, 106, 90, 104, 110, 110, 103, 109, 109, 111, 101, 101, 110, 102, 105, 110, 106, 104, 104, 100, 103, 102, 120, 90, 113, 116, 95, 105, 103, 101, 100, 101, 107, 110, 92, and 108.    Find the Range of the eruption times?

oldfaithrange=Max[{109,109,99,105,103,103,94,102,99,106,90,104,110,110,103,109,109,111,101,101,110,102,105,110,106,104,104,100,103,102,120,90,113,116,95,105,103,101,100,101,107,110,92,108}] -
Min[{109,109,99,105,103,103,94,102,99,106,90,104,110,110,103,109,109,111,101,101,110,102,105,110,106,104,104,100,103,102,120,90,113,116,95,105,103,101,100,101,107,110,92,108}]

Example 2

Calculate the Variance and Standard Deviation for the following examples:

2.1: Calculate the Variance and Standard Deviation for the number of field goals kicked per football game.

frequencytable={{0,0.2},{1,.2},{2,.2},{3,.2},{4,.2}};
fulldata=Prepend[frequencytable,{"Field Goals Kicked per Game(x)","Probability P(x)"}];
DisplayTable[fulldata,TableLabel->"Field Goals Kicked Per Game",ItemSize->13]

(Labeled[({{"Field Goals Kicked per Game(x)", "Probability P(x)"}, {0, 0.2`}, {1, 0.2`}, {2, 0.2`}, {3, 0.2`}, {4, 0.2`}}), "Field Goals Kicked Per Game"])

mean=Total[{0*0.2}+{1*.2}+{2*.2}+{3*.2}+{4*.2}]

frequencytable={{0,0.2,"(0-2)^2* .2 = .8"},{1,.2,"(1-2)^2* .2 = .2"},{2,.2,"(2-2)^2* .2 = 0"},{3,.2,"(3-2)^2* .2 = .2"},{4,.2,"(4-2)^2* .2 = .8"},{"","","(σ^2)= 2"}};
fulldata=Prepend[frequencytable,{"Field Goals Kicked per Game(x)","Probability P(x)","(x-(Subscript[μ, x]))^2* P(x)"}];
DisplayTable[fulldata,TableLabel->"Field Goals Kicked Per Game",ItemSize->13]

(Labeled[({{"Field Goals Kicked per Game(x)", "Probability P(x)", "(x-\!\(\*SubscriptBox[\(μ\), \(x\)]\)\!\(\*SuperscriptBox[\()\), \(2\)]\)* P(x)"}, {0, 0.2`, "(0-2\!\(\*SuperscriptBox[\()\), \(2\)]\)* .2 = .8"}, {1, 0.2`, "(1-2\!\(\*SuperscriptBox[\()\), \(2\)]\)* .2 = .2"}, {2, 0.2`, "(2-2\!\(\*SuperscriptBox[\()\), \(2\)]\)* .2 = 0"}, {3, 0.2`, "(3-2\!\(\*SuperscriptBox[\()\), \(2\)]\)* .2 = .2"}, {4, 0.2`, "(4-2\!\(\*SuperscriptBox[\()\), \(2\)]\)* .2 = .8"}, {"", "", "\!\(\*SuperscriptBox[\(σ\), \(2\)]\)= 2"}}), "Field Goals Kicked Per Game"])

The variance is 2 and therefore the standard deviation is (Sqrt[(σ^2)]) = (Sqrt[2]) = 1.41421.

2.2:  Calculate the Variance and Standard Deviation for the following distribution.

frequencytable={{10,0.1},{20,0.23},{30,0.22},{40,0.4},{50,0.05}};
fulldata=Prepend[frequencytable,{"x","P(x)"}];
DisplayTable[fulldata,TableLabel->"Distribution",ItemSize->13]

(Labeled[({{"x", "P(x)"}, {10, 0.1`}, {20, 0.23`}, {30, 0.22`}, {40, 0.4`}, {50, 0.05`}}), "Distribution"])

mean=Total[{10*0.1}+{20*0.23}+{30*0.22}+{40*0.4}+{50*0.05}]

frequencytable={{10,0.1,"(10-30.7)^2* .1 = 42.849"},{20,0.23,"(20-30.7)^2* .23 = 26.3327"},{30,0.22,"(30-30.7)^2* .22 = .1078"},{40,0.4,"(40-30.7)^2* .4 = 34.596"},{50,0.05,"(50-30.7)^2* .05 = 18.6245"},{"","","(σ^2)= 122.51 "}};
fulldata=Prepend[frequencytable,{"x","P(x)","(x-(Subscript[μ, x]))^2* P(x)"}];
DisplayTable[fulldata,TableLabel->"Distribution",ItemSize->15]

(Labeled[({{"x", "P(x)", "(x-\!\(\*SubscriptBox[\(μ\), \(x\)]\)\!\(\*SuperscriptBox[\()\), \(2\)]\)* P(x)"}, {10, 0.1`, "(10-30.7\!\(\*SuperscriptBox[\()\), \(2\)]\)* .1 = 42.849"}, {20, 0.23`, "(20-30.7\!\(\*SuperscriptBox[\()\), \(2\)]\)* .23 = 26.3327"}, {30, 0.22`, "(30-30.7\!\(\*SuperscriptBox[\()\), \(2\)]\)* .22 = .1078"}, {40, 0.4`, "(40-30.7\!\(\*SuperscriptBox[\()\), \(2\)]\)* .4 = 34.596"}, {50, 0.05`, "(50-30.7\!\(\*SuperscriptBox[\()\), \(2\)]\)* .05 = 18.6245"}, {"", "", "\!\(\*SuperscriptBox[\(σ\), \(2\)]\)= 122.51 "}}), "Distribution"])

The variance is 122.51 and therefore the standard deviation is (Sqrt[(σ^2)]) = (Sqrt[122.51]) = 11.0684

2.3:  We are given the following bar chart.  For 50-54 year old mothers giving birth in 2005, the chart highlights the number of children that Mother has.  Please calculate the variance and standard deviation of the data set.

BarChart[{0.292,0.251,0.167,0.128,0.060,0.031,0.022,0.049},ChartElementFunction->"GlassRectangle",ChartStyle->"AvocadoColors",PlotLabel->"Number of Children: 50 to 54-Year-Old Mothers",ChartLegends->{"1","2","3","4","5","6","7","8"},ChartLabels->
{Placed[{"0.292","0.251","0.167","0.128","0.060","0.031","0.022","0.049"},Above]}]

mean=Total[{1*0.292}+{2*0.251}+{3*0.167}+{4*0.128}+{5*0.060}+{6*0.031}+{7*0.0022}+{8*0.049}]

frequencytable={{1,0.292,"(1-2.7004)^2* .292 = .844277"},{2,0.251,"(2-2.7004)^2* .251 = .123131"},{3,0.167,"(3-2.7004)^2* .167 = .149899"},{4,0.128,"(4-2.7004)^2* .128 = .216187"},{5,0.060,"(5-2.7004)^2* .060 = .31729"},{6,0.031,"(6-2.7004)^2* .031 = .337508"},{7,0.0022,"(7-2.7004)^2* .022 = .406704"},{8,0.049,"(8-2.7004)^2* .049 = 1.3762"},{"","","(σ^2)= 3.7712"}};
fulldata=Prepend[frequencytable,{"x","P(x)","(x-(Subscript[μ, x]))^2* P(x)"}];
DisplayTable[fulldata,TableLabel->"Distribution",ItemSize->16]

(Labeled[({{"x", "P(x)", "(x-\!\(\*SubscriptBox[\(μ\), \(x\)]\)\!\(\*SuperscriptBox[\()\), \(2\)]\)* P(x)"}, {1, 0.292`, "(1-2.7004\!\(\*SuperscriptBox[\()\), \(2\)]\)* .292 = .844277"}, {2, 0.251`, "(2-2.7004\!\(\*SuperscriptBox[\()\), \(2\)]\)* .251 = .123131"}, {3, 0.167`, "(3-2.7004\!\(\*SuperscriptBox[\()\), \(2\)]\)* .167 = .149899"}, {4, 0.128`, "(4-2.7004\!\(\*SuperscriptBox[\()\), \(2\)]\)* .128 = .216187"}, {5, 0.06`, "(5-2.7004\!\(\*SuperscriptBox[\()\), \(2\)]\)* .060 = .31729"}, {6, 0.031`, "(6-2.7004\!\(\*SuperscriptBox[\()\), \(2\)]\)* .031 = .337508"}, {7, 0.0022`, "(7-2.7004\!\(\*SuperscriptBox[\()\), \(2\)]\)* .022 = .406704"}, {8, 0.049`, "(8-2.7004\!\(\*SuperscriptBox[\()\), \(2\)]\)* .049 = 1.3762"}, {"", "", "\!\(\*SuperscriptBox[\(σ\), \(2\)]\)= 3.7712"}}), "Distribution"])

The variance is 3.7712 and therefore the standard deviation is (Sqrt[(σ^2)]) = (Sqrt[3.7712]) = 1.94196

Initialization Cell

DisplayTable[data_List,opts:OptionsPattern[]]:=CellPrint[TextCell[Labeled[Grid[data,FilterRules[{opts},Options[Grid]],Frame->All,ItemSize->14,Alignment->Center,BaseStyle->{FontFamily->"Helvetica",FontSize->18},Background->LightYellow,Frame->All,Spacings->{2,0.62}],Style[OptionValue[TableLabel],FontFamily->"Times", 16]],"DisplayFormula",ShowStringCharacters->False]]

universitya={73,103,91,93,136,108,92,104,90,78,108,93,91,78,81,130,82,86,111,93,102,111,125,107,80,90,122,101,82,115,103,110,84,115,85,83,131,90,103,106,71,69,97,130,91,62,85,94,110,85,102,109,105,97,104,94,92,83,94,114,107,94,112,113,115,106,97,106,85,99,102,109,76,94,103,112,107,101,91,107,107,110,106,103,93,110,125,101,91,119,118,85,127,141,129,60,115,80,111,79};
universityb={86,91,107,94,105,107,89,96,102,96,92,109,103,106,98,95,97,95,109,109,93,91,92,91,117,108,89,95,103,109,110,88,97,119,90,99,96,104,98,95,87,105,111,87,103,92,103,107,106,97,107,108,89,96,107,107,96,95,117,97,98,89,104,99,99,87,91,105,109,108,116,107,90,98,98,92,119,96,118,98,97,106,114,87,107,96,93,99,89,94,104,88,99,97,106,107,112,97,94,107};