visStatistics: The right test, visualised.
Purpose
visStatistics is an R package for automated statistical test selection
and visualisation. It selects appropriate hypothesis tests for pairs of
variables (integer, numeric, or factor), runs the analysis, and produces
annotated, publication-ready plots.
The package was originally developed for researchers who could not directly access sensitive data but needed to perform visualisations and statistical analyses of selected groups via a web interface connected to a protected database — a setting that required a fully automated workflow. The same automation makes it useful in time-constrained contexts such as statistical consulting, where it reduces effort spent on test selection and leaves more room for interpretation. The package covers most hypothesis tests taught in undergraduate statistics.
Installation of latest stable version from CRAN
1. Install the package
install.packages("visStatistics")2. Load the package
library(visStatistics)Installation of the development version from GitHub
1.Install devtools from CRAN if not already installed:
install.packages("devtools")2. Load the devtools package:
library(devtools)3. Install the visStatistics package from GitHub:
pak::pak("shhschilling/visStatistics")
4. Load the visStatistics package:
library(visStatistics)5. View help for the main function:
? visstat6. Study all the details in the packages’ vignette:
vignette("visStatistics")Getting Started
The function visstat() accepts input in three ways:
# Standardised form: visstat(x, y) # Formula interface: visstat(y ~ x, data = df) # Backward-compatible form: visstat(dataframe, "namey", "namex")
In the standardised form, x and y must be vectors of class
"numeric", "integer", or "factor".
In the formula interface, the formula y ~ x specifies the response y
and predictor x variables, and data is a data frame containing these
variables.
In the backward-compatible form, "namex" and "namey" must be
character strings naming columns in a data.frame named dataframe.
These column must be of class "numeric", "integer", or "factor".
This is equivalent to writing:
visstat(dataframe[["namex"]], dataframe[["namey"]])
To simplify the notation, throughout the remainder, data of class
numeric or integer are both referred to by their common mode
numeric, while data of class factor are referred to as
categorical.
The interpretation of x and y depends on their classes:
-
If one is numeric and the other is a factor, the numeric must be passed as response
yand the factor as predictorx. This supports tests for central tendencies. -
If both are numeric, a simple linear regression model is fitted with
yas the response andxas the predictor. -
If both are factors (and not both ordered), a test of association is performed (Chi-squared or Fisher’s exact). The test is symmetric, but the plot layout depends on which variable is supplied as
x. -
If both are factors and
yis additionally of classordered, a non parametric test is performed: a Wilcoxon test in the case of two factor levels inx, a Kruskal-Wallis-Test for more than two factor levels inx. -
If both
xandyare of classordered, the order of the levels carries information that Chi-squared / Fisher would discard.visstat()instead tests for a monotone association via Kendall’s