TL;DR
VMC (Visualizing Model Checks) is a new declarative grammar and R package designed to streamline the process of comparing statistical model predictions against observed data. By decoupling data sampling from visual encoding, it reduces the code required for complex model checks by roughly 30% and helps researchers explore model fit more deeply without the "viscosity" of low-level plotting libraries.
What Problem Does This Paper Address?
In statistical modeling, "model checking"—the process of ensuring a model's predictions align with reality—is essential but often tedious. Researchers typically face a frustrating trade-off between two types of tools:
- Low-level grammars (e.g.,
ggplot2): These are highly flexible but require significant "boilerplate" code to align model samples with observed data. This makes it easy to introduce errors (like mismatched scales) and discourages exploration because changing a plot type often requires a total rewrite of the data pipeline. - High-level "canned" libraries (e.g.,
bayesplot): These are easy to use but offer limited customization. If a researcher wants a specific view not provided by the library, they are out of luck.
VMC addresses this by creating a "Grammar for Model Checks" that understands the semantics of the task: comparing a model-generated quantity to an observed one.
Methods
The authors propose a formal grammar consisting of four primary components:
- Sampling Specification (
Sampling_spec): Defines what to draw from the model (e.g., posterior predictive distributions or specific parameters like $\mu$ or $\sigma$). - Data Transformation (
Data_transformation): Specifies how to process observed data to make it comparable to model output (e.g., calculating a mean or standard deviation). - Visual Representation (
Visual_representation): Maps data to marks (lines, ribbons, dots) and defines how to group samples (e.g., "collapsing" all samples into one density curve or "animating" them as Hypothetical Outcome Plots). - Comparative Layout (
Comparative_layout): Controls how model and data are juxtaposed. VMC introduces "nested juxtaposition" as a first-class citizen, allowing model and data marks to be placed side-by-side within the same coordinate system.
The system is implemented as an R package that generates ggplot2 objects, allowing users to further customize plots using standard R tools.
Datasets
The authors validated VMC using:
- Canonical Examples: A collection of 27 model check visualizations drawn from popular Bayesian textbooks (like Gelman’s Bayesian Data Analysis) and recent HCI literature.
- Air Quality Data: A real-world dataset of $PM_{2.5}$ pollution measurements used to demonstrate a step-by-step modeling workflow.
- User-Provided Models: In an interview study, three expert modelers applied VMC to their own ongoing research models.
Key Insights and Ideas
- Reduced "Edit Distance": One of the most powerful features of VMC is that switching from a density plot to a residual plot, or from a global check to a faceted marginal check, requires changing only one or two lines of code. This encourages "exploratory model checking."
- Alignment as a First-Class Citizen: By forcing the user to define how model quantities and observed data relate, the grammar prevents common "silent errors" where a user might accidentally compare a model parameter on a log scale to observed data on a linear scale.
- Nested Juxtaposition: The authors found that experts highly valued the ability to place model and data marks side-by-side (juxtaposition) rather than just on top of each other (superposition). This reduces visual clutter and makes it easier to spot local discrepancies.
Key Results
- Code Efficiency: When reproducing 27 canonical model checks, VMC required an average of 30% fewer lines of code than
ggplot2. - Expressiveness: VMC successfully reproduced a wide range of complex plots, including raincloud plots, Q-Q plots, and animated Hypothetical Outcome Plots (HOPs).
- Expert Validation: In the interview study, Ph.D.-level modelers found the grammar's abstractions (like
mc_drawandmc_observation_transformation) aligned closely with their mental models of how statistics should work. They noted it made "the data versus model" contrast much clearer than existing tools.
Limitations and Future Work
- Position Encodings: VMC currently focuses on standard Cartesian coordinates (x-axis, y-axis, facets). It does not yet support spatial data (maps) or more exotic space-filling visualizations.
- Interactivity: While VMC supports animation (HOPs), it lacks interactive features like brushing and linking, which are useful for identifying specific outliers across multiple plots.
- Model Compatibility: The current implementation relies on specific R libraries (like
tidybayes) to extract data from models. Expanding this to support a wider variety of machine learning and frequentist model objects is a goal for future development.
Summary updated