Home   About Kurtosis   Courses   Course Calendar   Booking Information   Ideas   Technique   Clients   Contact

 

   

Superimposing deciles

How to overlay percentiles on a histogram in Microsoft Excel

[By the way, decile is pronounced “dess-isle”, with “isle” as in “Isle of Skye”.]

When you’re looking at a hospital length of stay frequency distribution (the example below is for emergency medical admissions at a medium-sized district general hospital), it sometimes helps if people can see at a glance what percentage of patients were discharged in less than a day or in less than three days or in more than 15 days and so on.

And if you are just looking at a histogram on its own like this, it can be difficult to see these percentages without having to do some awkward mental arithmetic.

However, if you superimpose deciles onto the chart, then you can see at a glance how the distribution is spread out in percentage terms:

Now we can see that 30% of the patients had lengths of stay less than 24 hours, and that 10% of patients were in for longer than 17 days, and so on.

You could superimpose the deciles just by using Excel’s drawing tools, by pasting vertical lines over the top of the chart in the right places. But that would be a bit clunky, a bit "amateur-ish", so this article shows you how to do it “properly” using Excel’s Y-error bar functionality.

The data we'll work with is shown in the worksheet in Step One, which you'll find in this Excel workbook:

Deciles.xls (2.7 Mb)

All you’ve got is a whole load of numbers (6,446 to be exact), each of which is an individual length of stay figure (measured in days) for the patients admitted as emergencies in 2011. Here are the first ten lengths of stay:

LOS                  
0.73                  
0.96                  
18.15                  
0.74                  
5.99                  
0.70                  
0.81                  
4.93                  
0.27                  
0.50                  

 

Step Two shows how we’ve generated a frequency table of these length of stay figures using the =FREQUENCY function.

LOS   Length of stay (days) No. of discharges            
0.73   1 1,781            
0.96   2 947            
18.15   3 491            
0.74   4 427            
5.99   5 345            
0.70   6 310            
0.81   7 260            
4.93   8 234            
0.27   9 163            
0.50   10 161            
1.31   11 119            
0.33   12 107            
4.07   13 121            
0.96   14 93            
1.55   15 74            
0.38   16 66            
1.79   17 57            
0.58   18 50            
1.03   19 52            
1.08   20 45            
10.79   21 33            
3.24   22 29            
6.41   23 35            
0.77   24 28            
0.58   25 16            
1.41   26 18            
1.09   27 23            
0.90   28 20            
1.07   >28 341            
0.97   Total 6,446            

 

Step Three shows that we’ve had to insert a column that will have the labels as we’d like to see them in the histogram. We’ve done this because the labels in the frequency array function are upper limits instead of lower limits. In the example above, the first figure of 1,781 represents all the patients who had a length of stay of up to one day. In reality (and to satisfy the demands of convention) it's usually better if we label such patients as having a zero-day length of stay.

LOS   Length of stay (days) X-axis labels No. of discharges          
0.73   1 0 1,781          
0.96   2 1 947          
18.15   3 2 491          
0.74   4 3 427          
5.99   5 4 345          
0.70   6 5 310          
0.81   7 6 260          
4.93   8 7 234          
0.27   9 8 163          
0.50   10 9 161          
1.31   11 10 119          
0.33   12 11 107          
4.07   13 12 121          
0.96   14 13 93          
1.55   15 14 74          
0.38   16 15 66          
1.79   17 16 57          
0.58   18 17 50          
1.03   19 18 52          
1.08   20 19 45          
10.79   21 20 33          
3.24   22 21 29          
6.41   23 22 35          
0.77   24 23 28          
0.58   25 24 16          
1.41   26 25 18          
1.09   27 26 23          
0.90   28 27 20          
1.07   >28 28+ 341          
0.97   Total   6,446          

 

Step Four shows the histogram that’s been drawn using the data in columns D and E of the Step Three worksheet.

Now for the deciles. In the worksheet in Step Five we’ve calculated the 10th, 20th, 30th, 40th , 50th, 60th, 70th, 80th and 90th deciles for the length of stay data in columns H and I.

LOS   Length of stay (days) X-axis labels No. of discharges     Decile X-value  
0.73   1 0 1,781     1 0.4  
0.96   2 1 947     2 0.8  
18.15   3 2 491     3 1.1  
0.74   4 3 427     4 1.9  
5.99   5 4 345     5 3.0  
0.70   6 5 310     6 4.7  
0.81   7 6 260     7 6.9  
4.93   8 7 234     8 10.3  
0.27   9 8 163     9 17.9  
0.50   10 9 161          

 

We now have to superimpose these deciles onto the histogram that we created in Step Four.

First of all—and this is what we’ve done in Step Six—we’ve assigned a Y-value of 2,000 to each of the deciles that were calculated in Step Five. We’ve done this because we’re going to draw a scatterplot of these points in a minute, and we want each point to be positioned horizontally along the 2,000 line on the y-axis, but with an x-co-ordinate that corresponds to their decile position (that’s why we calculated the deciles in Step Five).

LOS   Length of stay (days) X-axis labels No. of discharges     Decile X-value Y-value
0.73   1 0 1,781     1 0.4 2,000
0.96   2 1 947     2 0.8 2,000
18.15   3 2 491     3 1.1 2,000
0.74   4 3 427     4 1.9 2,000
5.99   5 4 345     5 3.0 2,000
0.70   6 5 310     6 4.7 2,000
0.81   7 6 260     7 6.9 2,000
4.93   8 7 234     8 10.3 2,000
0.27   9 8 163     9 17.9 2,000
0.50   10 9 161          

 

Next, we draw the scatterplot of these nine pairs of points and we format it so that it looks like the one in Step Seven:

Next we add Y-error bars to the nine points so that we get vertical lines dropping down to the x-axis. This is what you should be able to see in Step Eight:

If you’ve never copied and pasted one chart over another chart in Excel, you might be surprised by Step Nine because that’s what we’re going to do. In order to show it we’ve made a copy of the histogram that we drew back in Step Four, so that it now becomes Step Nine. And then I’ve copied the scatterplot chart from Step Eight and pasted it slap bang over the top of the histogram in Step Nine.

It will look a bit weird at first. But if we do a few more things to it you’ll see that it starts to look like we want it to turn out.

In Step Ten, for example, you can see that we’ve right-clicked on the histogram data series (which had been temporarily turned into a scatterplot) and we’ve clicked on Chart Type… and we’ve turned it back into a histogram (whilst leaving the deciles as a scatterplot).

But the biggest problem we need to fix is that the Y-error bars are dropping in the wrong places. The first decile (the 10th percentile) has kind of disappeared off the left of the graph. And the ninth decile (the 90th percentile) is hitting the x-axis at 17.4 days when it should be hitting it at 17.9 days.

To fix this we need to plot the scatterplot dots on a secondary x-axis which we will then re-scale so that it is in harmony with the existing primary x–axis.

Step Eleven shows the chart with a secondary y-axis (which—strictly speaking—you don’t actually need but the only way I know of getting a secondary x-axis is to put a secondary y-axis in place first then go into Chart Options… and then add in the secondary x-axis from the Axes tab.

But if you scale your secondary x-axis so that it has got exactly the same number of points on it as the primary x-axis then you should get your deciles so that are all nicely in the right place.

Then, with a bit of final formatting, you should end up with a chart that looks something like the one in Step Twelve:

[28 February 2012]

 

Make a comment

Name:

Job Title:

Organisation:

Email address:

     
© Kurtosis 2012. All Rights Reserved.