Getting the Book’s Data

Every chapter in this book shows its analysis in four languages. The R tab runs live on this page, so R readers never have to think about where the data came from. If you are working in SPSS, Julia, or Python, you need the data first - and this page is how you get it.

The problem, stated honestly

Most of the book’s datasets are simulated. The obvious thing would be to hand you the simulation code in your language and let you run it. That does not work, and it is worth knowing why.

Random number generators are not portable. set.seed(5) followed by rnorm(100) in R, Random.seed!(5) and rand(Normal(), 100) in Julia, and default_rng(5).normal(size=100) in NumPy produce three completely different sets of numbers. Same distribution, different draws. If you regenerated the data in your own language, every correlation, slope, and p-value you computed would be a little off from the ones printed here - and you would reasonably assume you had made a mistake.

So we do the only thing that actually works: we generated the data once, in R, and we ship it. All four languages read the same files, so all four print the same numbers.

Download it here

One file, everything in it, no account and no software needed to get it:

⬇ Download gradstats-data.zip

About 700 KB. Contains the data folder, a loader for each of the four languages, and a README.txt.

Unzip it wherever you like - the Desktop is fine. You get a folder called GradStats-data holding the data folder and one loader per language, plus a README.txt repeating the steps below. That is the whole setup; you never need the rest of the book’s source.

Working in SPSS? Take the kit instead

If SPSS is your working environment, there is a second download that saves you copying blocks out of the chapters one at a time:

⬇ Download gradstats-spss.zip

About 750 KB. Every SPSS block in the book, pulled into one syntax file per chapter, with the data alongside.

It contains the same data folder plus a spss folder holding one .sps per chapter, in book order, with all 106 blocks labelled by the chapter and line they came from. Run spss/00-START-HERE.sps once at the start of a session to set the working directory, and every chapter file will then find its data. You do not need the data zip as well; this one has it.

Two labels in those files are worth knowing. [NO CODE] marks a block that is all comment, used where base SPSS genuinely cannot do something and we name the tool that can - empty output there is correct. [NEVER EXECUTED] marks valid SPSS that PSPP cannot run, so the book prints it without ever having run it. If one of those works for you, we would like to hear about it.

The book is developed openly, so the same files live in the GitHub repository if you use git: git clone https://github.com/pem725/GradStats-Book.git. The zip above is built from exactly those files on every render, so the two cannot disagree. You do not need this to follow the book.

Four files, one per language

The loader for your language is in the folder you just unzipped. Run it once.

Language File Use it like this
R setup/load_data.R source("setup/load_data.R"); d <- book_data("ch06-study")
SPSS setup/load_data.sps Run the file, then !bookdata name = "ch06-study".
Julia setup/load_data.jl include("setup/load_data.jl"); d = book_data("ch06-study")
Python setup/load_data.py from setup.load_data import book_data; d = book_data("ch06-study")

Each chapter tells you which dataset it uses, in a note near the top.

NoteSPSS: point it at the book first

SPSS will not find the data until its working directory is the unzipped folder, and on Windows it never is by default. load_data.sps has one line near the top for this - delete the asterisk at the start and put your own path between the quotes:

CD 'C:/Users/jeff/Desktop/GradStats-data'.

Use forward slashes, even on Windows. Point it at the folder that contains data, not at data itself. Running the file then prints the folder back to you, so you can see straight away whether it took.

That one line is the whole fix, and it has to be that line. Changing a path anywhere else will not work: !bookdata inserts a small loader from data/sim/, and that loader reads its own .csv with its own relative path, so both only resolve once the working directory is right.

Every dataset ships with that small .sps loader beside the .csv because GET DATA /TYPE=TXT will not infer columns from a header row - it needs an explicit /VARIABLES list naming every column and its format. They are generated by setup/make_data.R, so they cannot drift from the data they load.

No SPSS licence? PSPP is a free, open-source program that runs SPSS syntax, from a GUI or the command line. Every SPSS block in this book has been executed through it.

The recipes are still there

Reading the data rather than simulating it does not mean the simulation is hidden. Each loader carries a one-line recipe for every dataset - ch06-study, for instance, is recorded as:

set.seed(5); study ~ N(5,2); grade = 60 + 4*study + N(0,5)

and the full generating code, exactly as the chapters run it, lives in setup/make_data.R. If you want to rebuild everything from scratch in R, that one file does it:

source("setup/make_data.R")   # rewrites every file in data/sim/

One trap worth knowing about

A CSV file does not record the order of a categorical variable. Left alone, every language sorts categories alphabetically - so the four pets in the coding chapters come back as cat, dog, fish, pig instead of cat, fish, pig, dog, and the fertilizer doses in the ANOVA chapter come back as high, low, none instead of none, low, high.

That is not a cosmetic problem. It silently reorders every coefficient in the model, so your output would have the right numbers attached to the wrong labels. Each loader fixes this for you: the ones that matter are listed in a LEVELS table at the top of each file, and book_data() applies them on the way in. If you load a CSV by hand instead, set the category order yourself.

The real datasets

A few chapters use genuine data rather than simulated: high-school and college GPAs (data/gpa.csv), a 10-item scale from the graduate GLM course (data/moddat2.csv), a four-group dataset (data/mod3data.csv), Ben Wright’s Knox Cube Test responses (data/knox.dat), and some baseball and football tables. Those need no setup at all - read them directly in any language, exactly as the code tabs show.