1. Beyond 95%
Now that you're familiar with the basics of confidence intervals let's dive into visualizing more than just a single interval.
2. Why show more than one interval? (a)
Why would we want to show more than a single interval? Often different questions need to be answered with different levels of uncertainty.
3. Why show more than one interval? (b)
For instance, a large company may have a policy to investigate the strategies of a competitor if they are estimated to make a profit at a 90% level.
4. Why show more than one interval? (c)
However, if that confidence level is 95%, they will attempt to partner with the company directly.
5. Why show more than one interval? (d)
Even more extreme, if the confidence level is 99%, they will look into directly acquiring the competitor.
6. Why show more than one interval? (e)
A multi-interval chart can show all these confidence levels in a single plot, rather than requiring a separate plot for each one. This adds a lot of information for very little extra 'ink'.
7. Overlaying multiple intervals
To overlay multiple intervals on your plot with hlines() you typically use a for loop to loop through each interval size, create the interval boundaries, and draw the respective line to the plot. The most common intervals are 99, 95, and 90%, which are created by moving 2.58, 1.96, and 1.67 standard errors out from either side of the point-estimate respectively.
We can supply interval size, multiplication amounts, and colors to our for loop as lists to draw each line.
The thicker the interval line is, the easier it is to differentiate the different interval colors, so we'll want to increase the linewidth as well.
Last, use the label argument to inform the legend which bar corresponds to which interval value.
8. Overlaying multiple intervals (plot)
From this code, we get nice gradient-style bars that the viewer can use to quickly assess the statistical confidence at the provided interval percents. Any more than three or so intervals and your plot will start to become trickier to read, so try to be conservative with how many break points you show.
9. Coloring your intervals
Now that we've started using color to distinguish our intervals we need to think about what colors to use. In this case, we have created ordinal classes, with a clear ordering due to the size of the intervals, and thus we should use an ordinal color palette.
Start with the lightest color for your widest interval and use darker colors as the interval narrows. This helps avoid the illusion of two separate intervals caused by a light center blending in with the background.
In addition, you will want to keep the color differences for each interval large enough, so the boundaries are clear, while still keeping the ordinal nature of the palette. Depending on the background of your plot you will often need to play around with different palettes to get the plot looking right.
10. Overlaying confidence bands (code)
We can also overlay confidence bands with multiple interval sizes just like we did with standard intervals.
To do so, we loop through the desired interval sizes and color with an ordinal color palette that follows the same rules as with the intervals.
One change is we usually will want to reduce the opacity of the bands to allow the plots grid lines to show through for visual anchoring when reading.
Last, like with the intervals we need to give each band an id so when we draw a legend later, it is properly labeled.
11. Overlaying confidence bands (plot)
The problems we saw in the last lesson with comparing bands don't occur here as the bands are nested strictly within each-other rather than crisscrossing. However, it still pays to keep the number of intervals low, often just two, as putting a lot of shades of color on the screen can still get distracting.
12. Using size instead of color
While color is a great way of encoding multiple interval sizes because of how little it physically adds to your chart, sometimes the luxury of color is not available to you.
In this case, it's relatively easy to modify the color-based interval code to use size instead.
Just replace the color encodings for the intervals with linewidth encodings.
13. Using size instead of color
The result works without any color and doesn't lose too much ease of reading compared to the color-encoded intervals.
14. Let's expand our boundaries!
Let's put these new techniques to work in the exercises!