Organizing and Summarizing Data

Relative frequency charts

Lesson Overview

Goals

Students will be able to describe the steps needed to create a relative frequency plot.

Students will be able to create a relative frequency plot from data provided.

Instructor Presentation

Introduction

When qualitative data is collected, we often want to determine how the individual data elements relate to one another and to the whole data set.  This lesson plan outlines the process to turn raw data into information using a Relative Frequency Plot.
Lets start with a small data set of patient problems associated with a Therapists office.  :

patients1={Back, Wrist, Elbow, Back, Hip, Back, Back, Back, Shoulder, Knee, Hand, Groin, Back, Shoulder, Hip, Neck, Shoulder, Back, Knee, Hand, Knee, Shoulder, Back, Knee, Back, Knee, Back, Back, Back, Wrist}

This represents the type of injury that a Physical Therapist has seen in one day.  Once we have the data set, we really would like to tally the number of individual data elements.  To tally, we count up the number of each data element.  We list the data element in the left column and place the number of individual data elements directly to the right of the data element.  The result is what is know as a Frequency Table.

frequencytable=Tally[patients1];
fulldata=Prepend[frequencytable,{"Body Part","Number of Patients"}];
DisplayTable[fulldata,TableLabel->"Typical Physical Therapist's Day",ItemSize->13]

Lets look at that again:

frequencytable=Tally[patients1];
fulldata=Prepend[frequencytable,{"Body Part","Number of Patients"}];
DisplayTable[fulldata,TableLabel->"Typical Physical Therapist's Day",ItemSize->13]

We most likely would present the above table in an article, but if we were going present this to a group of people, we most likely would create a small graph out of this.  The most appropriate graph is called a Frequency Plot.

BarChart[frequencytable[[All,2]],PlotLabel->"Frequency Plot"]

Making this a bit more formal:

BarChart[frequencytable[[All,2]],ChartLabels->{frequencytable[[All,1]]},ChartStyle->"DarkRainbow",PlotLabel->Style["Therapy Patients",18,Blue]]

So it is easy to see that "Back" patients are by far the most common patients seen that day.  But say someone asked you what percent of the therapy patients have shoulder problems.

frequencytable=Tally[patients1];
fulldata=Prepend[frequencytable,{"Body Part","Number of Patients"}];
DisplayTable[fulldata,TableLabel->"Typical Physical Therapist's Day",ItemSize->13]

Well we could use the above table, but most business professionals prefer to see an additional column added to this table.  The column is called Relative Frequency and it will help you estimate the number of shoulder patients that you typically see.

The Relative Frequency column is calculated in two steps.  First, you add up the number of data elements in the data set.

dataelements=Length[patients1]

Then you divide the number of specific data elements found in column two by the total number of data elements in the set.  And Wa-La.

relfrequencytable=Table[{frequencytable[[n,1]],frequencytable[[n,2]],(((frequencytable[[n,2]])/dataelements))},{n,1,Length[frequencytable]}];
relfulldata=Prepend[relfrequencytable,{"Body Part","Number of Patients","Relative Frequency"}];
DisplayTable[relfulldata,TableLabel->"Typical Physical Therapist's Day",ItemSize->13]

This says that there is about a (2/5) chance that the next patient through the door has a back problem and there is only a (1/30) chance that the next patient has an elbow problem. (assuming the flow of past patients is an indicator of the flow of future patients).

Lets look at that table again.  This time with the Relative Frequency stated as a decimal.

relfrequencytable=Table[{frequencytable[[n,1]],frequencytable[[n,2]],N[(((frequencytable[[n,2]])/dataelements)),2]},{n,1,Length[frequencytable]}];
relfulldata=Prepend[relfrequencytable,{"Body Part","Number of Patients","Relative Frequency"}];
DisplayTable[relfulldata,TableLabel->"Typical Physical Therapist's Day",ItemSize->13]

So now we know the Relative Frequency of each element within the data set.  Now lets put it into a Relative Frequency chart.

BarChart[relfrequencytable[[All,3]]]

Making this a bit more formal:

BarChart[relfrequencytable[[All,3]],ChartLabels->{relfrequencytable[[All,1]]},ChartStyle->"DarkRainbow",PlotLabel->Style["Therapy Patients",18,Blue]]

Concept Exploration

Steps

There are four steps to creating a Relative Frequency plot.

Tally the elements within the data set

Count the elements within the data set

Divide the frequency of each data element by the count

Chart the result

Examples

Example 1

The blood type of the first 50 people who donated blood at the local Red Cross drive were recorded.  The blood types were O,O,A,A,O,B,O,B,A,O,AB,B,A,A,B,AB, O, A,A,O, AB,O, B,A,O,AB,AB,O,A,B,O,O,B,O,AB,O,A,B,O,A,B,A,B,B,O,AB,O,O,A,B,AB,O.  Create relative frequency chart of this data.

1: Tally the elements within the data set

bloodtypes={O,O,A,A,O,B,O,B,A,O,AB,O,B,A,A,B,AB,O,A,A,O,AB,O,B,A,O,AB,O,A,O,O,B,O,AB,O,A,B,O,A,B,A,B,B,O,AB,O,O,A,O,O};
bloodfrequency=Tally[bloodtypes];
fulldata=Prepend[bloodfrequency,{"Blood Type","Count"}];
DisplayTable[fulldata,TableLabel->"Donor Blood Types",ItemSize->13]

2: Count the elements within the data set

number=Length[bloodtypes]

3: Divide the frequency of each data element by the count

relbloodfrequency=Table[{bloodfrequency[[n,1]],bloodfrequency[[n,2]],N[(((bloodfrequency[[n,2]])/number)),2]},{n,1,Length[bloodfrequency]}];
relfulldata=Prepend[relbloodfrequency,{"Blood Type","Donors","Relative Frequency"}];
DisplayTable[relfulldata,TableLabel->"Donor Blood Types",ItemSize->13]

4: Chart the result

BarChart[relbloodfrequency[[All,3]],ChartLabels->{relbloodfrequency[[All,1]]},ChartStyle->"ValentineTones",PlotLabel->Style["Blood Donors",18,Blue]]

Example 2

Lets give it a try with a smaller data set.

Your Mathematics teacher graded the last test and determined the following grades:  A,C,D,B,B,A,C,B,C,A,D,B,C,C,C,B,A.     Create a Relative Frequency Chart for the grades.

1: Tally the elements within the data set

grades={A,C,D,B,B,A,C,B,C,A,D,B,C,C,C,B,A};
gradefreq=Tally[Sort[grades]]

2: Count the elements within the data set

tests=Length[grades]

3: Divide the frequency of each data element by the count

relgradefrequency=Table[{gradefreq[[n,1]],gradefreq[[n,2]],N[(((gradefreq[[n,2]])/tests)),2]},{n,1,Length[gradefreq]}];
relfulldata=Prepend[relgradefrequency,{"Grade Earned","Number of Tests","Relative Frequency"}];
DisplayTable[relfulldata,TableLabel->"Grades for Business Stats",ItemSize->13]

4: Chart the result

BarChart[relgradefrequency[[All,3]],ChartLabels->{relgradefrequency[[All,1]]},ChartStyle->"FruitPunchColors",PlotLabel->Style["Test 1 Results",18,Blue]]

Example 3

Lets look at an example of the relative frequency plot that is a bit more dynamic.

Set the sliders in the following demonstration to correspond to the following data set.   {C,A,C,E,D,A,B,C,A,E,A,C,B,E,B,A,D,E}  .

Manipulate[
Module[{scaleNote=Text["123",{-1,5000}],xmax,ymax},BarCharts`BarChart[{e1,e2,e3,e4,e5},BarOrientation->hv,ImageSize->{400,300},Frame->{True,True,False,False},Axes->False,ImagePadding->50,BarLabels->Function[list,MapIndexed[Column[{{"A","B","C","D","E"}[[#2[[1]]]]}~Join~#,Center,Spacings->0]&,Transpose[{list,Map[Row[{NumberForm[If[FractionalPart[#]==0,IntegerPart[#],#]&[N[If[Plus@@list==0,0,#/Plus@@list 100]]],3],"%"}]&,list]}]]][{e1,e2,e3,e4,e5}]]],
{{hv,Vertical,"bar chart orientation"},{Horizontal->"horizontal",Vertical->"vertical"},ControlPlacement->Top},
Style["quantities",Bold],
{{e1,1,"A"},0,20,ImageSize->Tiny},
{{e2,2,"B"},0,20,ImageSize->Tiny},
{{e3,3,"C"},0,20,ImageSize->Tiny},
{{e4,4,"D"},0,20,ImageSize->Tiny},
{{e5,5,"E"},0,20,ImageSize->Tiny},
Initialization:>{
Get["BarCharts`"]},ControlPlacement->Left]

💡  Move sliders A through E to see how the Frequency and Relative Frequency numbers below the labels are affected.  Exact numbers can be added by clicking on the  +.

Initializations

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