Data Exploration

The Data Science unit on looking at data before modeling it, worked on 5,533 NHANES 2017-2018 adults joined from ten public files. Plots for one feature and for several, the evidence behind chart design, the tools that draw charts and the grammar of graphics behind them, a six-step routine for exploratory analysis that ends in a finding about blood cadmium and smoking, and the detection of outliers from z-scores to Mahalanobis distance, isolation forests and the local outlier factor.

Before a model is fitted, the data have to be looked at. This unit is about that look: the plots that show one feature or several, the rules that make a chart accurate to read and the evidence for them, the software that draws charts, a routine for the first systematic pass over a table with many columns, and the detection of values that do not fit. The definitions of the individual graphs (histograms, box plots, the empirical distribution function) and the rules that keep a single graph honest are in Tables and Graphs for Data; this unit is about the workflow of exploring a dataset with many features, and what each display can show or hide.

The running example is a table of 5,533 adults examined in the National Health and Nutrition Examination Survey (NHANES) of 2017 to 2018, joined on the respondent number from ten public files: demographics, blood pressure, body measures, glycohemoglobin, two cholesterol tests, C-reactive protein, blood metals, smoking and prescription medicines. Two smaller datasets serve where the table cannot: the 272 eruptions of the Old Faithful geyser, whose two clusters a box plot hides, and the 178 wines of the wine data, for parallel coordinates. Every number in the unit is computed by a script in tools/experiments/data-science/, and every article ends with worked problems that extend it on its own data and with open questions that the unit's experiments could settle.

Articles, in order

  • Visualizing Data with One Feature: kernel density estimates and the bandwidth that controls them, with the proof that an equal mixture of two normal curves has two peaks only when their means differ by more than twice the standard deviation, which is why the heights of men and women together have one peak; log scales for a variable spanning three orders of magnitude; violin and strip plots where a box plot hides two clusters; bar charts for a feature with 635 categories.
  • Visualizing Data with Multiple Features: scatterplot matrices; overplotting from sheer number and from coarse recording, and the remedies of jitter, transparency and hexagonal bins; correlation heatmaps and four ways a correlation misleads, among them a correlation of 0.04 that hides a clear curve and one of $-0.19$ that comes entirely from the difference between the sexes; color, shape, small multiples and parallel coordinates for further features.
  • Best Practices for Visualizing Data: Cleveland and McGill's ranking of the perceptual tasks a chart asks of its reader and the experiments behind it, with a later replication; pies, stacked bars and dot charts on the same blood pressure shares; honest axes, data-ink and direct labels; color scales measured for lightness along jet and viridis, and color pairs simulated for color-vision deficiency, where a red and green pair that differ by 120 units become nearly identical.
  • Tools for Visualizing Data: drawing commands against declarative specifications; the grammar of graphics of Wilkinson and Wickham, in which a pie chart is a stacked bar in polar coordinates, with the areas that pies, bullseyes and coxcombs give to the same shares computed; matplotlib, pandas, seaborn, plotly, ggplot2 and Vega-Lite; spreadsheets and the gene names they turn into dates; vector and raster output, and reproducible figures.
  • Performing Exploratory Data Analysis: Tukey's idea of exploration and its partner, confirmation; a routine of six steps, from question and provenance through structure, missing values, single columns and pairs to groups, and what each found in the NHANES table, from missing values in blocks to values filled in below detection limits; the finding the routine leads to, blood cadmium almost four times as high in current smokers as in people who never smoked, shown to be robust to how the filled values are treated.
  • Detecting Outliers: errors against genuine extremes; z-scores and their masking, with the bound on any z-score proved and extended to several equal errors; modified z-scores and Tukey's fences, and the share of errors each rule withstands; Mahalanobis distance with chi-squared cutoffs and its robust MCD version, applied to waist and BMI, where an adult ordinary on each measurement is unusual in combination; isolation forests and the local outlier factor; and what to do with an outlier once found, including one created by a processing rule.

The order runs from single displays to whole workflows. The first two articles build the displays; the third gives the evidence for designing them; the fourth covers the software; the fifth combines them into a routine; and the sixth takes up the unusual values the routine turns up.

Where the site goes deeper

Several subjects of the unit are proved or treated at length elsewhere. The basic graphs and summaries are in the course pages Tables and Graphs for Data, Measures of Center and Spread and Types of Numerical Data. The correlation coefficients, their bounds and their exact tests are in Correlation: Pearson, Spearman and Kendall. The Statistics unit Multivariate Statistics owns the theory behind the multivariate tools: Covariance Matrices and Quadratic Forms proves that the Mahalanobis distance of a normal vector is chi-squared, The Multivariate Normal Distribution derives the elliptical contours, and Gaussian Mixture Models fits mixtures of the kind the height example discusses. Outliers in a fitted regression, measured by leverage and influence, are in Leverage, Influence and Residual Diagnostics; the many comparisons an exploration makes are the subject of Multiple Testing. Density-based detection continues in Detecting Outliers Using DBSCAN, and the repairs that exploration calls for are in the Data Wrangling articles, starting with Cleaning Data.

Some subjects the unit touches would fit a later collection of their own: graphical perception and color science at the depth of their literatures, bandwidth and bin-width selection, displays of uncertainty, high-dimensional and network displays, interaction and accessible charts, and anomaly detection beyond the methods here.

References