Learn R Programming

s20x

s20x supports data analysis teaching at the University of Auckland, in STATS 201, STATS 208 and BIOSCI 209. It provides model-checking plots, teaching summaries, predictions with intervals, datasets and worked case studies.

The package website has the function reference and all the case studies.

Installation

# From CRAN
install.packages("s20x")

# Development version
remotes::install_github("STATS-UOA/s20x")

A quick example

library(s20x)

peruFit = lm(BP ~ weight + age, data = peru.df)

# Check the model
modelcheck(peruFit)

# Predict, with confidence and prediction intervals
predict20x(peruFit, data.frame(weight = 70, age = 30))

What is in the package

TaskFunctions
Explore the datapairs20x(), trendscatter(), interactionPlots(), summaryStats()
Check a modelmodelcheck(), normcheck(), eovcheck(), cooks20x()
Summarise an analysissummary1way(), summary2way(), multipleComp(), displayPairs(), rowdistr()
Predictpredict20x() for lm, glm and tslm fits
Time seriestslm() for linear models with AR(p) errors
Case studieslistCaseStudies(), casestudy(), openCaseStudy()

Plotting engines

The diagnostic functions draw the familiar base graphics teaching plots by default. They can also return reusable plot objects: functions such as normcheck(), eovcheck(), modelcheck(), and pairs20x() continue to draw the familiar base graphics plots unless another engine is requested.

Where supported, use engine = "ggplot2" to request the ggplot2 plotting engine. It is intended for workflows where a plot object is useful for saving, arranging, or further customisation.

Use the plotting engines this way:

TaskRecommended callNotes
Teaching, labs, and lecture notesnormcheck(fit) or modelcheck(fit)Uses the original base graphics output.
Save or arrange a normality diagnosticnormcheck(fit, engine = "ggplot2")Returns reusable Q-Q and histogram plot objects.
Save or arrange an equality-of-variance diagnosticeovcheck(fit, engine = "ggplot2")Returns a reusable residual-versus-fitted plot object.
Save or arrange model-checking diagnosticsmodelcheck(fit, engine = "ggplot2")Returns a reusable named list for multiple diagnostics, or a single plot object when which selects one diagnostic.
Save or arrange a pairs plotpairs20x(data, engine = "ggplot2")Returns a reusable plot matrix.

Examples:

peruFit = lm(BP ~ Age + Weight + Years, data = peru.df)
normcheck(peruFit)

normPlots = normcheck(peruFit, engine = "ggplot2")
normPlots
pairsPlot = pairs20x(peru.df, engine = "ggplot2")
pairsPlot

The base engine draws directly on the active graphics device and usually returns no reusable object. The ggplot2 engine is for users who need to keep, print, save, or combine the result later. When a helper creates more than one ggplot2 diagnostic, the return value is a named list so individual plots can be selected by name, for example diagnosticPlots$residuals or normPlots$qq. This distinction is intentional so existing course material keeps the familiar plots while newer workflows can opt into object-based graphics.

Changes

See NEWS.md for the release history.

Copy Link

Version

Install

install.packages('s20x')

Monthly Downloads

2,188

Version

3.4.0

License

GPL-2 | file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

James Curran

Last Published

November 5th, 2026

Functions in s20x (3.4.0)

eovcheck

Testing for equality of variance plot
cooks20x

Cook's distance plot
estimateContrasts

Contrast Estimates
fruitfly.df

Fruitfly Data
getModelResidualFittedData

Get model residual and fitted-value data
crosstabs

Crosstabulation of two variables
formatTslmResidualTypeLabel

Format a tslm residual type label
crossFactors

Crossed Factors
getTslmArParameters

Get tslm autoregressive parameters
freq1way

Analysis of 1-dimensional frequency tables
incomes.df

Mean Family Incomes
extractTslmErrorSpec

Extract a tslm error specification
estimateContrasts2

Estimate two-factor contrasts
estimateContrasts1

Estimate one-factor contrasts
course.df

Stats 20x Summer School Data
drawPlot

Draw row-distribution comparison plots
interactionPlots

Interactions Plot for Two-way Analysis of Variance
course2way.df

Exam Mark, Gender and Attendance for Stats 20x Summer School Students
getTslmResidualDf

Get tslm residual degrees of freedom
getTslmCoefficientTable

Get a tslm coefficient table
diamonds.df

Prices and Weights of Diamonds
getTslmDiagnosticData

Get tslm diagnostic data
matchTslmResidualType

Match a tslm residual type
getTslmErrorTerms

Get tslm error terms
parseTslmFormula

Parse a tslm formula
pairs20x

Pairwise Scatter Plots with Histograms and Correlations
mergers.df

Merger Days
modcheck

Deprecated model checking plots
extractTslmFit

Extract the underlying tslm fit
getTslmTimeValues

Get tslm time values
house.df

Sale and Advertised Prices of Houses
formatTslmAnovaTable

Format a tslm ANOVA table
getVersion

s20x package version number
mening.df

Monthly Notifications of Meningococcal Disease
multipleComp

Multiple Comparisons
mazda.df

Year and Price of Mazda Cars
makeTslmModelData

Make tslm model data
fire.df

Fire Damage and Distance from the Fire Station
s20x_ggplot2_base_theme

Build a base-like ggplot2 theme
residPlot

Fitted values versus residuals plot
matchTukeyInteractionLevels

Match Tukey interaction comparisons to factor levels
modelcheck

Model checking plots
resolveCaseStudyDestinationDir

Resolve case-study destination directory
saveGraphicsParameters

Save graphics parameters for later restoration
nzarrivals.df

Monthly Arrivals to New Zealand
matchPlottingEngine

Match a plotting engine argument
openCaseStudy

Open a case study source file in the editor
print.s20xNormcheck_ggplot2

Print ggplot2 normcheck plots
listCaseStudies

List available case studies
mozart.df

Length of Mozart's Movements
predictCount

Predicted Counts for a Log-Link Generalised Linear Model
nail.df

Nail Polish Data
soyabean.df

Soya Bean Yields
levene.test

Levene test for the ANOVA Assumption
oysters.df

Oyster Abundances over Different Sites
isTslmErrorTerm

Check a tslm error term
lakemary.df

Ages and Lengths of Lake Mary Bluegills
s20x-package

s20x: Functions for University of Auckland Course STATS 201/208 Data Analysis
stripqq

Deprecated strip charts and normal quantile-quantile plots
larain.df

Los Angeles Rainfall
onewayPlot

One-way Analysis of Variance Plot
summaryStats

Summary Statistics
layout20x

Layout
teach.df

Comparison of Three Teaching Methods
rain.df

Cloud Seeding and Levels of Rainfall
normcheck

Testing for normality plot
nzalc.df

Quarterly Alcohol Available for Consumption in New Zealand
propslsd.new

LSD-Display Intervals
rr

Read Data
tslm

Fit a linear model with optional autoregressive errors
predictGLM

Prediction Intervals for Log-Link and Logit-Link Generalised Linear Models
removeTslmErrorTerms

Remove tslm error terms
resolveCaseStudyOutputArgs

Resolve case-study output arguments
printOutput

Print row-distribution summaries
requireSuggestedPackage

Require a suggested package
snapper.df

Snapper Weight Data
skulls.df

Skulls Data
print.s20xModelcheck_ggplot2

Print ggplot2 modelcheck plots
plotTslmTimeResiduals

Plot tslm residuals over time
prepCrosstabList

Prepare row-distribution table summaries
predict20x

Teaching Predictions with Confidence and Prediction Intervals
zoo.df

Zoo Attendance during an Advertising Campaign
rowUniformityTests

Calculate row uniformity tests
rowdistr

Row distributions from a cross-tabulation of two variables
technitron.df

Technitron Salary Information
sheep.df

Sheep Data
plotTslmResiduals

Plot tslm residuals against fitted values
seeds.df

Seeds Data
peru.df

Peruvian Indians
skewness

Skewness Statistic
sentenceCase

Convert text to sentence case
toothpaste.df

Crest Toothpaste
resolvePlotColour

Resolve a plotting colour argument
thyroid.df

Effect of a New Drug on Thyroid Weights
summary2way

Two-way Analysis of Variance Summary
summary1way

One-way Analysis of Variance Summary
trendscatter

Trend and scatter plot
airpass.df

International Airline Passengers
anova.tslm

ANOVA tables for time series linear models
ciReg

Confidence Intervals for Regression models
bursary.df

Bursary Results for Auckland Secondary Schools
butterfat.df

Butterfat Data
beer.df

US Beer Production
computer.df

Computer Questionnaire
body.df

Body Image and Ethnicity Data
apples.df

Apples Data
arousal.df

Changes in Pupil Size with Emotional Arousal
camplake.df

Age and Length of Camp Lake Bluegills
captureOptionalName

Capture an optional column name
casestudy

Render a case study to HTML
autocorPlot

Autocorrelation Plot
autocor.plot

Deprecated autocorrelation plot alias
chalk.df

Chalk Data
books.df

Books Data
displayPairs

Display within-level pairwise comparisons for saturated two-way ANOVA model.
boxqq

Deprecated box plots and normal quantile-quantile plots