GitHub

CRAN_Status R_Universe Last Commit downloads Lifecycle: stable License Follow on Bluesky

Version 0.9.8; documentation built for pkgdown 2026-08-17

This package provides additional data sets, documentation, and many functions designed to extend the vcd package for Visualizing Categorical Data and the gnm package for Generalized Nonlinear Models. In particular, vcdExtra extends mosaic, assoc and sieve plots from vcd to handle glm() and gnm() models and adds a 3D version in mosaic3d().

The functions here use the “strucplot” framework (Meyer et-al., 2006), which is a lovely, natural conceptual system for implementing visualization and other displays for n-way frequency tables which have a nested, hierarchical structure in vcd. [This can be compared to the “productplots” framework in producplots, and the defunct ggmosaic package]

vcdExtra also adds extensions to modeling functions for models fit using glm() and MASS::loglm(), using the construct glmlist() to construct a list of related models which can be summarized (via LRstats()) and graphed (via mosaic.glmlist())

vcdExtra is a support package for the book Discrete Data Analysis with R (DDAR) by Michael Friendly and David Meyer. There is also a web site for DDAR with all figures and code samples from the book. It is also used in my graduate course, Psy 6136: Categorical Data Analysis.

A more general goal of vcdExtra is to contribute to the wider topics of thinking about, analyzing and visualizing categorical data, extending this beyond the scope of our book. In this sense, it continues to be a love letter 💌 to CDA.

📂 Installation

Get the released version (0.9.7) from CRAN:

 install.packages("vcdExtra")

The current development version (0.9.8) can be installed from R-universe or directly from the GitHub repo via:

 if (!require(remotes)) install.packages("remotes")
 install.packages("vcdExtra", repos = c('https://friendly.r-universe.dev')
 # or
 remotes::install_github("friendly/vcdExtra", build_vignettes = TRUE)

Overview

The original purpose of this package was to serve as a sandbox for introducing extensions of mosaic plots and related graphical methods from the vcd package that apply to loglinear models fitted using MASS::loglm(), generalized linear models using stats::glm() and also to the related, generalized nonlinear models fitted with gnm() in the gnm package.

A related purpose was to fill in some holes in the analysis of categorical data in R, not provided in base R, vcd, or other commonly used packages. I now see vcdExtra as a leading edge of development of statistical and graphic methods for categorical data analysis (CDA) in R.

See also:

           

💡 vcdExtra Highlights

What’s in the box?

Mosaic plot extensions

  • The method mosaic.glm() extends the mosaic.loglm() method in the vcd package to this wider class of models, e.g., models for ordinal factors, which can’t be handled with MASS::loglm(). This method also works for the generalized nonlinear models fit with the gnm package, including models for square tables and models with multiplicative associations (RC models).

  • mosaic3d() introduces a 3D generalization of mosaic displays using the rgl package.

  • A new “labeling” method, labeling_points() for mosaic plots allows you to show the observed or expected frequencies in cells as point symbols, thereby showing the data or model in a dot-density representation. This goes back to an old paper, Friendly(1995), where I describe visual and conceptual models for categorical data with a physical analog of gas molecules in chambers.

Model extensions

  • A new class, glmlist, is introduced for working with collections of glm objects, e.g., Kway() for fitting all K-way models from a basic marginal model, and LRstats() for brief statistical summaries of goodness-of-fit for a collection of models.

  • Similarly, for loglinear models fit using MASS::loglm(), the function seq_loglm() fits a series of sequential models to the 1-, 2-, … n-way marginal tables, corresponding to a variety of types of models for joint, conditional, mutual, … independence. It returns an object of class loglmlist, each of which is a class loglm object. The function seq_mosaic() generates the mosaic plots and other plots in the vcd::strucplot() framework.

  • For square tables with ordered factors, Crossings() supplements the specification of terms in model formulas using gnm::Symm(), gnm::Diag(), gnm::Topo(), etc. in the gnm package.

Statistical tests

The package also includes a variety of improvements / enhancements of common statistical tests for categorical data analysis.

  • vcd::woolf_test() is extended to provide a decomposition of the overall test for homogeneity of odds ratios in 2 x 2 tables when the strata themselves represent an R x C table of two other factors

A few others worth knowing about:

  • breslow_day_test() is a complementary test for homogeneity of odds ratios across strata in 2 x 2 x K tables, with the same decompose option as woolf_test() for R x C strata.

  • HLtest() provides the Hosmer-Lemeshow goodness-of-fit test for a binary glm() model, useful for logistic regression models not otherwise well summarized by deviance alone.

  • zero.test() is a score test for zero-inflation in Poisson count data, testing whether the observed number of zero counts exceeds what a Poisson model would predict.

  • drop1.loglm(), and its wrappers LRanova() and assoc_strength(), give term-level deletion tests for the generating class of a MASS::loglm() model, with partial R^2 and partial Cramer’s V / Cohen’s w effect-size measures for each term.

🗃️ Datasets

Beyond the wide range of **datasets* in the vcd package, this vcdExtra package includes many new data sets, that I’ve found useful for illustrating various ideas, models, methods and visualization. Use datasets("vcdExtra") to see a list with titles and descriptions. The vignette, vignette("datasets", package="vcdExtra") provides a classification of these according to methods of analysis.

vcdExtra::datasets("vcdExtra")[,1]
##  [1] "Abortion"       "Accident"       "AirCrash"       "Alligator"     
##  [5] "Asbestos"       "Bartlett"       "Burt"           "Caesar"        
##  [9] "Cancer"         "Cormorants"     "CrabSatellites" "CyclingDeaths" 
## [13] "DaytonSurvey"   "Depends"        "Detergent"      "Donner"        
## [17] "Draft1970"      "Draft1970table" "Dyke"           "Fungicide"     
## [21] "GSS"            "Geissler"       "Gilby"          "Glass"         
## [25] "HairEyePlace"   "Hauser79"       "Heart"          "Heckman"       
## [29] "HospVisits"     "HouseTasks"     "Hoyt"           "ICU"           
## [33] "JobSat"         "Mammograms"     "Mental"         "Mice"          
## [37] "Mobility"       "PhdPubs"        "Reinis"         "ShakeWords"    
## [41] "TV"             "Titanicp"       "Toxaemia"       "Vietnam"       
## [45] "Vote1980"       "WorkerSat"      "Yamaguchi87"

📖 Vignettes

A collection of tutorial vignettes. In the installed package, they can be viewed using browseVignettes(package = "vcdExtra");

vigns <- as.data.frame(tools::getVignetteInfo("vcdExtra")[,c("File", "Title")])
vigns$Title <- paste0("[", vigns$Title, "](https://friendly.github.io/vcdExtra/articles/",
                      tools::file_path_sans_ext(vigns$File), ".html)")
vigns |> knitr::kable()
File Title
a1-creating.Rmd 1. Creating and manipulating frequency tables
a1a-convert-collapse.Rmd 1a. Steps Toward Tidy Categorical Data Analysis
a2-tests.Rmd 2. Tests of Independence
a3-loglinear.Rmd 3. Loglinear Models
a4-mosaics.Rmd 4. Mosaic plots
a5-demo-housing.Rmd 5. Demo - Housing Data
a6-mobility.Rmd 6. Mobility tables
a7-continuous.Rmd 7. Continuous predictors
datasets.Rmd Datasets for categorical data analysis
tidyCats.Rmd tidyCat: Tidy Methods For Categorical Data Analysis
  • there is also a set of simple demonstration files illustrating analysis of datasets with more detail than provided in their individual help files. Use demo(package = "vcdExtra") to see the list and run demo("occStatus") to run the analysis for this example, ordemo(“mental-glm”)` for another one.

  • a few useful utility functions for manipulating categorical data sets and working with models for categorical data: joint(), conditional(), mutual(), saturated(). These make it easier to specify loglm() and glm() models representing a statistical concept, like conditional association, rather than figuring out a formula like [AC] [BC] for a 3-way table or [AD] [BD] [CD] for a 4-way table.

  • A re-implementation of vcd::woolf_test() extends the analysis of homogeneity of odds ratios in 2 x 2 x R x C tables to provide tests for differences among the R strata rows and C strata columns.

Recent work

Visual tables

A new function, color_table() provides semi-graphic tables of frequency tables or residuals from a loglinear model. The essential idea is to use background shading of cells in the table to show patterns not discernible in purely numeric tables.

Association graphs

I’m now experimenting with using graphical association representations of models in conjunction with the other methods, and ways of specifying models here. assoc_graph() Association graphs represent variables as nodes and their partial associations between pairs of variables as edges. They are useful for understanding If two variables are not connected by an edge, they are conditionally independent given the other variables in the model.

How can we use this in practice, to understand a model, or how well it fits a given dataset?

There is now (rudimentary) a plot() method for association graphs which allows edges to be weighted by a measure of the strength of association between variables: partial

Read the original on github.com ↗