Statistics for Psychology & Neuroscience
A code-first introduction — with R, Python and MATLAB
Introduction
Welcome to my statistics book — subtitled “Stats Book for People who want to do stats good and other stuff good too.” This is a set of interactive info sheets. Each sheet is self-contained and consists of: a short explanation in plain language, a hands-on interactive demo, and runnable R/Python code (with a MATLAB reference - ’cause MATLAB costs money).
Why did I put this book together?
Because I had the time.
Because that seems to be the done thing for anyone who teaches statistics for any length of time. Maybe it comes from a desire to get more value out of all the effort that goes into understanding and preparing this stuff (probably). Maybe it comes from the frustration of never finding the perfect pre-existing textbook — one that covers all the material you want, in the way you want to cover it. Maybe it comes from a genuine belief that statistics and programming are genuinely cool — and cooler than ever, given the variety of tools we now have.
The World certainly doesn’t need another self-published web-book on statistics (seriously — there are dozens of them; Google it sometime).
So why did I really do it?
Because I thought it would be fun.
And it was.
Mostly.
For me, it was all of those things (some more than others) — but perhaps the most significant reason (see what I did there?) is because teaching statistics has, without a doubt, been the most rewarding teaching experience of my 25+ year career. At university I was… not a good stats student (STAT263). It wasn’t until my Masters and PhD that I began to learn and understand the basics. And then when I started my first lectureship, I was given the opportunity to teach statistics — and that’s when the love really started.
I found that most psychology students anticipated hating statistics (and, to be fair, many did). But because their expectations for enjoyment were so low, the expectations were easy to exceed.
But it goes deeper than that: even a basic understanding of statistics can be incredibly empowering. You feel less intimidated by papers full of mathematical symbols. You feel more confident raising legitimate concerns about experimental design. And finally — learning a new statistical tool is like learning a new magic trick: you look really clever to your friends. It’s also a bit like learning a new joke — you want to use it far more often than is appropriate or appreciated.
Either way. Here it is. Here is my book.
A comment on AI
This book is based on my ~15 years teaching statistics to undergraduate psychology students. Nearly all the material within it was, at one time, a lecture, tutorial, workshop, conversation, or handout in one of my classes. Many of the examples will be familiar to some of my students, including the Kaggle datasets and the occasional unconventional — or borderline inappropriate (I’m thinking of you, Ashley Madison dataset) — example.
All of the dad jokes are mine.
That said, I relied heavily on Claude.ai to migrate and refine my content into this format. Claude helped develop the interactive demonstrations, clean and unify the text, and build the example scripts. As my wife can attest, this book was a long-running project on which I made very little progress until I started using AI to speed up the process.
This is not a wholesale endorsement of AI. To the students who may end up consulting this text: I used AI to complement existing knowledge, not to replace it. Another feature of this book that will be familiar to some of my students, past and present, is that it points out places where AI is not merely unhelpful but misleading — or just plain wrong. AI cannot, and never will, replace the complexities of human understanding.
In this book I have tried to make statistics accessible, understandable, relatable, and — dare I say — enjoyable. To do that, I drew on years of interacting with real, live students in real, live settings, recalling their faces lighting up or drooping in response to some new bit of stats information I’d fed them.
AI doesn’t understand confusion, doubt, frustration, anxiety, or fear. Nor can it appreciate the joy of witnessing that remarkable moment when, after hours (or days, or years) of struggle, a student finally gets it — a sense of achievement that brightens the day of everyone lucky enough to witness it.
So: use AI to help you understand, not to replace understanding.
(And by the way — there are much better texts available on the (in)appropriate uses of AI in statistics and programming.)
Finding your way around
Use the sidebar to browse by topic, or follow the Related topics links at the foot of any sheet to jump between connected ideas. The search box (top of the sidebar) finds anything by keyword.
New here? Good places to start: Ordinary Least Squares (how a model finds the best line), One-Way ANOVA & the F-ratio (signal vs noise), or Fixed vs Random Effects (the doorway to mixed models), or The Normal Distribution & the Central Limit Theorem (because understanding CLT is pretty useful, in an abstract sort of way - and there’s a really helpful demo there), or Family-Wise Error (a really cool demo)
How to read a sheet
Every sheet follows the same shape, so you always know where to look:
- What you’ll get — the objectives, up top.
- Key idea — the one thing to remember, in a blue box.
- An interactive — drag a slider or pick an option and watch the statistics respond.
- See it in code — the same idea in R, Python, and MATLAB; the R and Python tabs run live in the page.
- Check your understanding — a collapsible self-test.
- Common pitfall — the mistake to avoid, in an orange box.
- Related topics — where to go next.
Build status
Sheets are at different stages of completion — some are fully built with interactives and live code, others are still text drafts being brought up to the same standard. I’ve kinda run short on time so things have slowed a bit. I’ll get to it.