Learn R Programming

s20x

3.2.2

A small number of the datasets have been slightly altered, and their associated documentation accordingly. The changes consist of adding some useful extra variables to the three time series datasets airpass.df, beer.df and larain.df. These variables are t which is just a time index to save the user creating it if they want to fit a lag response model, and either month and year or both. These are factor variables giving the year the observation recorded, and if relevant the month. These extra variables can be used for time series analysis or plots.

In addition we have made an attempt to use SI units rather than imperial units where sensible. Some examples of where it is sensible: converting inches to millimetres, pounds to kilograms, and acre-feet/gallons to litres (or megalitres). Some examples of where it is not sensible are carats (industry standard) and converting blood pressue to kiloPascals instead of millimetres of mecury (mm Hg), which again is the health profession standard. If these conversions have been made, then they have been done as extra variables added to the dataset, rather than replacing the original measurements. The logic for this is to preserve the datasets as is to avoid lecture notes mismatches - at least for the time being.

A repository for the University of Auckland s20x R library. This library is used in our large undergrad classes STATS 201, STATS 208 and BIOSCI 209

Diagnostic plotting engines

Recent modernisation work has preserved the original base graphics teaching output while adding optional reusable plot objects for selected diagnostic helpers. The default behaviour remains unchanged: 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 modern plotting engine. The optional engine is intended for workflows where a plot object is useful for saving, arranging, or further customisation. It requires the optional plotting packages documented by each help page, while the base engine remains available without those optional packages.

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")Requires ggplot2; returns reusable Q-Q and histogram plot objects.
Save or arrange an equality-of-variance diagnosticeovcheck(fit, engine = "ggplot2")Requires ggplot2; returns a reusable residual-versus-fitted plot object.
Save or arrange model-checking diagnosticsmodelcheck(fit, engine = "ggplot2")Requires 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")Requires both ggplot2 and GGally; returns a reusable plot matrix.

Examples:

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

if (requireNamespace("ggplot2", quietly = TRUE)) {
  normPlots = normcheck(peruFit, engine = "ggplot2")
  normPlots
}
if (requireNamespace("ggplot2", quietly = TRUE) &&
    requireNamespace("GGally", quietly = TRUE)) {
  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.

The optional engines are deliberately guarded with requireNamespace() in examples. That keeps package checks and student installations working even when optional plotting packages are not installed.

Build Notes

We will attempt to add information about the changes in each new release (whether it makes it to CRAN or not) here, from version 3.1-21 onwards

3.1-21

Ben Stevenson added some code to summary2way so the attribute information from TukeyHSD is preserved. That is so you see this

> summary2way(fit, page = "interaction")
  Tukey multiple comparisons of means
    95% family-wise confidence level

Fit: aov(formula = fit)

$`store:crust`

instead of this

> summary2way(fit, page = "interaction")
$`store:crust`

3.1-24

A new function called modcheck has been added. This allows all four standard 20x model checking plots -- residuals versus fitted values, a normal Q-Q plot, a histogram of residuals, and a Cook's distance plot -- to be drawn on the same plot at once. This function needed a much more flexible version of normcheck, and needed modifications to eovcheck and cooks20x. I have not put it on CRAN yet because of the chance that it will fail for our current students. We really need some unit testing in this package so that this process can be sped up.

Copy Link

Version

Install

install.packages('s20x')

Monthly Downloads

1,032

Version

3.3.0

License

GPL-2 | file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

James Curran

Last Published

July 1st, 2026

Functions in s20x (3.3.0)

eovcheck

Testing for equality of variance plot
crosstabs

Crosstabulation of two variables
estimateContrasts1

Estimate one-factor contrasts
fruitfly.df

Fruitfly Data
estimateContrasts2

Estimate two-factor contrasts
getModelResidualFittedData

Get model residual and fitted-value data
getTslmCoefficientTable

Get a tslm coefficient table
getTslmResidualDf

Get tslm residual degrees of freedom
diamonds.df

Prices and Weights of Diamonds
getTslmErrorTerms

Get tslm error terms
extractTslmFit

Extract the underlying tslm fit
getTslmDiagnosticData

Get tslm diagnostic data
estimateContrasts

Contrast Estimates
extractTslmErrorSpec

Extract a tslm error specification
matchTslmResidualType

Match a tslm residual type
larain.df

Los Angeles Rainfall
mazda.df

Year and Price of Mazda Cars
house.df

Sale and Advertised Prices of Houses
matchPlottingEngine

Match a plotting engine argument
makeTslmModelData

Make tslm model data
getTslmTimeValues

Get tslm time values
getTslmArParameters

Get tslm autoregressive parameters
getVersion

s20x package version number
crossFactors

Crossed Factors
course2way.df

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

Format a tslm residual type label
freq1way

Analysis of 1-dimensional frequency tables
incomes.df

Mean Family Incomes
layout20x

Layout
mergers.df

Merger Days
mening.df

Monthly Notifications of Meningococcal Disease
interactionPlots

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

Monthly Arrivals to New Zealand
multipleComp

Multiple Comparisons
mozart.df

Length of Mozart's Movements
nzalc.df

Quarterly Alcohol Available for Consumption in New Zealand
fire.df

Fire Damage and Distance from the Fire Station
displayPairs

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

Draw row-distribution comparison plots
chalk.df

Chalk Data
formatTslmAnovaTable

Format a tslm ANOVA table
modelcheck

Model checking plots
predict20x

Deprecated Teaching Predictions for a Linear Model
predictCount

Predicted Counts for a Log-Link Generalised Linear Model
modcheck

Deprecated model checking plots
listCaseStudies

List available case studies
prepCrosstabList

Prepare row-distribution table summaries
predictGLM

Prediction Intervals for Log-Link and Logit-Link Generalised Linear Models
levene.test

Levene test for the ANOVA Assumption
lakemary.df

Ages and Lengths of Lake Mary Bluegills
isTslmErrorTerm

Check a tslm error term
requireSuggestedPackage

Require a suggested package
nail.df

Nail Polish Data
normcheck

Testing for normality plot
peru.df

Peruvian Indians
resolveCaseStudyOutputArgs

Resolve case-study output arguments
parseTslmFormula

Parse a tslm formula
resolveCaseStudyDestinationDir

Resolve case-study destination directory
residPlot

Fitted values versus residuals plot
requirePlottingPackage

Require an optional plotting package
rowdistr

Row distributions from a cross-tabulation of two variables
s20x_ggplot2_base_theme

Build a base-like ggplot2 theme
plotTslmResiduals

Plot tslm residuals against fitted values
print.s20xModelcheck_ggplot2

Print ggplot2 modelcheck plots
sheep.df

Sheep Data
print.s20xNormcheck_ggplot2

Print ggplot2 normcheck plots
soyabean.df

Soya Bean Yields
openCaseStudy

Open a case study source file in the editor
onewayPlot

One-way Analysis of Variance Plot
plotTslmTimeResiduals

Plot tslm residuals over time
technitron.df

Technitron Salary Information
sentenceCase

Convert text to sentence case
thyroid.df

Effect of a New Drug on Thyroid Weights
seeds.df

Seeds Data
printOutput

Print row-distribution summaries
propslsd.new

LSD-Display Intervals
skewness

Skewness Statistic
stripqq

Deprecated strip charts and normal quantile-quantile plots
trendscatter

Trend and scatter plot
toothpaste.df

Crest Toothpaste
zoo.df

Zoo Attendance during an Advertising Campaign
tslm

Fit a linear model with optional autoregressive errors
teach.df

Comparison of Three Teaching Methods
summaryStats

Summary Statistics
removeTslmErrorTerms

Remove tslm error terms
rain.df

Cloud Seeding and Levels of Rainfall
oysters.df

Oyster Abundances over Different Sites
rr

Read Data
pairs20x

Pairwise Scatter Plots with Histograms and Correlations
saveGraphicsParameters

Save graphics parameters for later restoration
summary2way

Two-way Analysis of Variance Summary
summary1way

One-way Analysis of Variance Summary
s20x-package

s20x: Functions for University of Auckland Course STATS 201/208 Data Analysis
skulls.df

Skulls Data
snapper.df

Snapper Weight Data
apples.df

Apples Data
anova.tslm

ANOVA tables for time series linear models
autocor.plot

Deprecated autocorrelation plot alias
autocorPlot

Autocorrelation Plot
body.df

Body Image and Ethnicity Data
books.df

Books Data
beer.df

US Beer Production
arousal.df

Changes in Pupil Size with Emotional Arousal
airpass.df

International Airline Passengers
boxqq

Deprecated box plots and normal quantile-quantile plots
camplake.df

Age and Length of Camp Lake Bluegills
captureOptionalName

Capture an optional column name
ciReg

Confidence Intervals for Regression models
computer.df

Computer Questionnaire
course.df

Stats 20x Summer School Data
cooks20x

Cook's distance plot
bursary.df

Bursary Results for Auckland Secondary Schools
butterfat.df

Butterfat Data
casestudy

Render a case study to HTML