Creating frequency tables from data
Looking at something like the Class Data can be a little overwhelming. It contains so much information, so much raw (unsorted) data. I’ve helped a little by putting all the female first and then all the male, both because this gives us two smaller sub-groups to look at and also because later in the course we’ll want to compare the statistics for males and females.
But you’d be hard pressed to summarize any aspect of the class using this sheet alone. So today we’ll consider ways you can organize the data sets into tables and graphs to help see their essential natures. And to do this you have to consider what level of measurement a data set is at, because this determines the kinds of tables and graphs you can use.
First of all, let’s do tables. Say, for instance, that you wanted to make sense of the men’s favorite color data. Favorite color is a categorical, or qualitative, variable, at the nominal level of measurement. There’s no order to the colors. So we make what’s called a categorical frequency distribution table (easier than it sounds). To do it by hand, we start reading down the list of favorite colors, and every time we find a new color we write it down and place a tally mark next to it. Of course, with technology, it is no longer necessary to use the tally marks anymore, but it's still good to know how to do it if you are going to, say, create a software that will create a frequency distribution.
Many software are capable of creating frequency distributions from the raw data, as well as the results were recorded consistently. At the very least, most spreadsheet software can sort the data according to a certain criterion. For example, when I use Excel to sort the class data by using COLOR, I get a spreadsheet that lists all the favorite colors in alphabetical order:
|
Row Number |
Color |
|
35 |
Black |
|
36 |
Blue |
|
37 |
Blue |
|
38 |
Blue |
|
39 |
Blue |
|
40 |
Blue |
|
41 |
Brown |
A handy trick in counting these rows is to use the row
numbers: if we are counting the number of rows that show Blue, we need to
decide how many numbers are there from 36, 37, … 40. Although it's tempting to
get this number via a simple subtraction: 40-36 = 4, a quick inspection of the
table shows that there are 5 rows. If you haven't seen it previously, here is
the correct formula to count the number of consecutive integers from m to n: .
This can be very useful if you are counting a large data set: for example, Row
142 to Row 285 contains 285-142+1 = 144 rows.
After you’ve counted all the colors and write that number in
a new column. These numbers have a special name that we’ll be using all
semester. They’re called frequencies, and that just means how many there are in
a category, or class. The symbol for frequency is .
When we add up all the frequencies, which we symbolize by writing , where is
the capital Greek ‘
’ and obviously stands for sum, we get the
size of the sample which we are tabulating. We call this sample size n, and we
will all semester. Make sure you use a lower-case n for the sample size; we
need the upper-case N for something else. So here’s an equation:
You’re learning the notation of descriptive statistics!
Finally, maybe you’re interested not so much in how many men
chose, say, blue, for their favorite color, but in what fraction of the group
did. We call this fraction the relative frequency, and it has the formula .
We can give it as a fraction (not so helpful) or a decimal or a percent, and if
it’s one of the last two, we might have to round, so we specify how that should
be done. Let’s give it as a percent to the nearest whole percent.
Here’s how the finished product looks:
|
Color |
Frequency |
Relative Frequency |
|
Brown |
7 |
15.2% |
|
Blue |
9 |
19.6% |
|
Black |
11 |
23.9% |
|
Purple |
13 |
28.3% |
|
Other |
6 |
13.0% |
|
|
|
|
I know the percents should add up to 100%, but what with rounding up and down they often don’t, as in this case. Not to worry, unless the sum is far away from 100%, in which case you probably made a mistake.
So much for categorical data. What about a variable at the interval or ratio level? (We’ll skip the ordinal in this discussion, but you might want to think about it.)
Let’s look at the men’s ages, as an example. Instead of just listing them as they come, we want to look at them in order, since the order of the numbers means something. Furthermore, we don’t want to look at each year separately. That would be too many separate numbers. What we want to do is group the ages into a small enough number of groups that we can see any patterns that exist. So what we’re going to make is a grouped frequency distribution table.
But how do we group them? What we do is pick two numbers, one called the lower limit of the first class, and one called the class width, such that if we all use these numbers, and use them correctly, we’ll get identical tables.
The lower limit of the first class is the smallest number we’re going to tally, and for classes that are not the first one, it is also the upper limit of the previous class. So to count everyone, the lower limit must of course be either the age of the youngest person or an even younger age. The class width is a little more complicated. It is the difference between the lower and upper limits in each class.
Because that we have let the lower and upper limits of adjacent classes overlap, caution must be taken to make sure no data value is counted twice. For this purpose, I will choose the class delimits so that no data value will be exactly the same as a limit.
For example, suppose the youngest person in class is 16, and the oldest person is 38. Suppose you want about 5 classes in your frequency table. So the first thing is to estimate what might be an appropriate class width. This can be done with a little bit of calculation like the follows:
So far us, the right class width seems to be around:
But for convenience, we might want to round that to a whole number (say 5), so that people can look at the limits and recognize that all the classes have the same width.
Let’s use 15.5 as the lower limit of the first class and 5 as the class width. This gives us class limits of 15.5-20.5, 20.5-25.5, 25.5-30.5,30.5-35.5, 35.5-40.5. We can stop here since we have included in the last person in the group. Because everyone reports her/his age in whole numbers, using the these limits ensures that you only count each person once in the frequency table.
|
Class Limits |
Frequency |
Relative Frequency |
|
15.5-20.5 |
13 |
33% |
|
20.5-25.5 |
19 |
49% |
|
25.5-30.5 |
4 |
10% |
|
30.5-35.5 |
1 |
3% |
|
35.5-40.5 |
2 |
5% |
Once you created the frequency table, it's fairly straightforward to put them into a histogram, which uses either the frequencies or the relative frequencies as the Y-axis, and the class limits as the X-axis. Although the histogram is a two-dimensional display of the data, it's useful to recognize the there is only one variable involved in the histogram. Although we are not going to discuss any of the statistical graphs in these notes, our textbook contains many examples of histogram, as well as how to create them both by hand and by software.
At last, there is a notion that becomes useful when we introduce the idea of a probability function for quantitative data. Instead of asking what percentage lies in each class (e.g. the relative frequency), we can also ask what percentage was included in the classes up to this point. In other words, we are adding the relative frequencies from the rows above as well. This new quantity is called the cumulative relative frequency. In our example, we can calculate the Cumulative Relative Frequencies as follows:
|
Class Limits |
Frequency |
Relative Frequency |
Cumulative Relative Frequency |
|
15.5-20.5 |
13 |
33% |
33% |
|
20.5-25.5 |
19 |
49% |
33% + 49% = 82% |
|
25.5-30.5 |
4 |
10% |
82% + 10% = 92% |
|
30.5-35.5 |
1 |
3% |
92% + 3% = 95% |
|
35.5-40.5 |
2 |
5% |
95% + 5% = 100% |
As you can see, the last row in the Cumulative Relative Frequencies should always be 100%. If you are not getting 100%, and your relative frequencies are correct, then it’s just a matter of small rounding errors, which is not a big deal.
Cumulative Relative Frequencies is the discrete version of what’s known as “Cumulative Distribution Functions”, which we will use a great deal when we enter the chapter of probability.