Track 3 · Visualising and Exploring Data · Lesson 5 of 11

Density curves and violin plots

Explain how a kernel density estimate is built, read heights and areas from a density curve, judge the effect of the bandwidth, and choose between violin and box plots.

30 minIntermediate8 graded exercisesMembers

A pay-equity review compares salary distributions across five job levels. Histograms side by side are cluttered and box plots hide shape; smooth density curves — and violins built from them — show where salaries pile up in each level, provided the reader knows that a curve's height is not a probability.

A histogram depends on where its bins start and how wide they are. A kernel density estimate (KDE) removes the bin edges: it places a small smooth bump — the kernel — centred on every observation, and adds the bumps up. Where observations crowd together, the bumps pile up into a peak; where they are sparse, the curve stays low. The result is a smooth curve whose total area is 1, like a histogram drawn on the density scale.

Included with a Formula Quest membership

It has 8 graded exercises with feedback, hints and worked solutions. After it you will be able to:

  • Compute a Gaussian kernel density estimate at a point and Scott's bandwidth
  • Read a density curve: heights are rates per unit, areas are proportions
  • Recognise under- and over-smoothing and boundary problems such as spikes at zero
  • Choose between violin plots, box plots and strip plots for comparing groups