compstatslib

R-CMD-check

compstatslib is a collection of interactive gadgets and plotting functions for visualizing data sets and statistical concepts in two and three dimensions.

Some of it works on your own data: explore any data frame as a rotatable 3D point cloud, or fit a moderated (interaction) regression and rotate its fitted surface to see how the interaction twists it away from a plane. The rest simulates a concept rather than plotting your data — sampling distributions, confidence intervals, t-statistics, matrix inversion — and is built for in-class demonstration, homework, and self-study.

Every interactive gadget prints the plot_*() call that reproduces its final view, viewing angle included. Exploration in the viewer pane becomes one line you can paste into a script, an Rmd, or a figure-generating file.

The 3D visualizations are the part of the package meant to grow beyond the classroom, toward figures good enough for textbooks and manuscripts. They are not there yet — see docs/future-work.md for the specific gaps.

How the functions are organized

Three kinds of function are provided:

They are grouped below by what they are for, since that varies more than the interaction style does.

Visualizing Data Sets in 3D

These accept arbitrary data frames and model formulas, with control over axes, color mapping, aspect ratio, and viewing angle.

3D Scatterplots

Moderation (Interaction Effects)

Fitting and Visualizing 2D Relationships

These plot a dataframe of x / y points that you supply, together with a fitted model. They are sized for small data — points you click in by hand or a modest dataframe — rather than for arbitrary data: plot_regression() draws in a fixed −5 to 50 window, and plot_pca() expects exactly two columns named x and y.

Linear Regression

Logistic Regression

Principal Components Analysis

Simulations and Concept Demonstrations

These do not plot your data. They simulate a process, or draw a geometric object, so that a concept can be watched rather than described.

Statistical Tests

Statistical Sampling

Linear Algebra

Precision

Reproducing an Interactive Session

Every interactive_*() gadget hands its final state back when you click Done, and prints the plot_*() call that reproduces what was on screen. Assign the result and you can either paste that call into a script or feed the object straight back:

result <- interactive_moderation_3d()
#> plot_moderation_3d(formula = y ~ x * z, data = moderation_data, z_rot = 125)

do.call(plot_moderation_3d, result)   # same surface, same viewing angle

Gadgets whose state is a set of points return a dataframe you can use as one (nrow(), [, passing it to the plot function). Gadgets whose state is a set of settings return a plain named list suitable for do.call(). Derived results a user would not retype — the prcomp() fit from interactive_pca(), the accumulated draws from interactive_sampling() — ride along as attributes.

Installation

You can install the current development version from GitHub using the devtools package:

# install.packages("devtools")
devtools::install_github("compstatslib/compstatslib")

Feel free to send open issues or send pull requests. Happy hacking!

Contributors

compstatslib is maintained by Soumya Ray.

Daniele Melotti is a co-author of the package. Several of the plotting and interactive functions grew out of work he did as a student under Soumya Ray’s supervision, and were then folded back into the package.