Get startedGet started for free

Making a confidence band

Vandenberg Air Force Base is often used as a location to launch rockets into space. You have a theory that a recent increase in the pace of rocket launches could be harming the air quality in the surrounding region. To explore this, you plotted a 25-day rolling average line of the measurements of atmospheric NO2. To help decide if any pattern observed is random-noise or not, you decide to add a 99% confidence band around your rolling mean. Adding a confidence band to a trend line can help shed light on the stability of the trend seen. This can either increase or decrease the confidence in the discovered trend.

This exercise is part of the course

Improving Your Data Visualizations in Python

View Course

Exercise instructions

  • Construct upper and lower 99% interval bands by adding and subtracting 2.58 standard errors from the mean.
  • Make the point-estimate line white.
  • Make the point-estimate line semi-transparent by setting alpha to 0.4.
  • Tell plt.fill_between() what values to fill between for each day.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Draw 99% inverval bands for average NO2
vandenberg_NO2['lower'] = vandenberg_NO2['mean'] ____ ____*vandenberg_NO2['std_err']
vandenberg_NO2['upper'] = vandenberg_NO2['mean'] ____ ____*vandenberg_NO2['std_err']

# Plot mean estimate as a white semi-transparent line
plt.plot('day', 'mean', data = vandenberg_NO2,
         color = '____', alpha = ____)

# Fill between the upper and lower confidence band values
plt.fill_between(x = 'day', 
                 ____ = 'lower', ____ = 'upper', 
                 data = vandenberg_NO2)

plt.show()
Edit and Run Code