Did you know: the aye-aye, a lemur from Madagascar, finds insect larvae by tapping on wood
with its long, thin middle finger and listening for hollow tunnels. Then
it gnaws a hole and hooks the larvae out with the same finger.
Source: Duke Lemur Center
Dr Massimiliano Canzi, Max for short.
R
All three needed the tools of this course: experiments with many participants and items, and regression models to make sense of them.
Tell us, briefly:
R: none, some,
lotsDid you know: aye-ayes have incisors
that never stop growing, like a rodent’s. No other primate has
them.
Source: Duke Lemur Center
| When | What happens | |
|---|---|---|
| Lecture | Fridays, 11:45 | New concepts, and the code that goes with them |
| Tutorial | Wednesdays, 13:30 | You practise, with help at hand |
| Office hours | Fridays, 10:00–11:30, by appointment | Questions about the course or your own data |
Announcements, homework and submissions are on Ilias.
| Component | Weight |
|---|---|
| Final assignment | 90% |
| Homework: four of the five exercises count | 10% |
The homework exercises are short, a few questions each, and practise what we covered in class.
You analyse a set of linguistic data and write it up as a scientific report of about 3000 words, in the style of an experimental paper.
You hand in one file that contains the text of your paper alongside the code of your analysis. Anyone who opens it can rerun your analysis and get the same numbers.
As The Smiths warn in Cemetry Gates (1986): plagiarism tends to get noticed.
I can supervise up to two dissertations per semester as first supervisor, and up to two as second supervisor.
If you would like to write a quantitative dissertation, get in touch early.
The slides are written in R Markdown and shown with
reveal.js. Each week you get:
Open the .Rmd in RStudio and run it yourself: every number, table and
plot on the slides comes from that code. Slides and code are also
online, at github.com/mcanzi/ws26_statistics.
Winter, B. (2019). Statistics for linguists: An introduction using R. Routledge.
R and the tidyverse, like
this courseEach lecture follows one or more chapters of Winter (2019).
| Lecture | Chapter | |
|---|---|---|
| 1 | Course introduction | 1 |
| 2 | Data wrangling | 2 |
| 3 | Descriptive statistics | 3 |
| 4 | Linear models | 4 |
| 5 | Transformations | 5 |
| 6 | Multiple regression | 6 |
| 7 | Categorical predictors | 7 |
| Lecture | Chapter | |
|---|---|---|
| 8 | Interactions | 8 |
| 9 | Significance testing | 9 |
| 10 | Mixed models 1 | 14 |
| 11 | Mixed models 2 | 15 |
| 12 | Mixed logistic regression | 12, 15.8 |
| 13 | Power and model building | 10, 11, 16 |
Did you know: the aye-aye is the world’s largest nocturnal primate, at 2.5 to 2.8 kg. In parts of
Madagascar many people see it as a bad omen (fady) that must be
killed on sight.
Source: Duke Lemur Center
You need two free programs:
R, the language itself. Download it
from CRANRStudio, the program you write and run
R code in. Download it from PositRStudio needs R to work, so install R first.
.Rmd files.
Code here is saved.
Type this in the RStudio Console:
Check that everything worked:
You install a package once. You load it with library() in every
session.
Did you know: the aye-aye’s thin middle finger sits on a
ball-and-socket joint, like a human shoulder, so
it can swivel in almost any direction while it probes for larvae.
Source: Duke Lemur Center
[1] "Hello, world!"
Brackets work as in maths: without them, 3 + 2 * 4 gives
11.
Code typed in the Console is gone once you close
RStudio. Write it in a script instead: File
> New File > R Script.
Run the current line with Ctrl + Enter
(Cmd + Enter on a Mac). Save the script, and you can rerun
the whole analysis tomorrow.
<- stores a value in an object (read it as “gets”):
[1] 6
[1] 7
Environmentx and X are two different objectsword_freq works, word freq does notc() combines values into a vector.
Arithmetic works on every element at once:
[1] 276 372 228 540
[1] 29.5
Square brackets pick out elements by position:
[1] 4
[1] 8 15 16
[1] 8 15 16 23 42
A comparison returns TRUE or FALSE for each
element:
[1] FALSE FALSE FALSE TRUE TRUE TRUE
TRUE counts as 1 and FALSE as 0, so you can
count and take proportions:
[1] 3
[1] 0.5
Comparisons: == equal, != not equal,
>, <, >=,
<=
Text goes in "quotes": a character
vector.
words
bird cat dog
1 3 1
A factor stores categories, with a fixed set of
levels:
[1] "bird" "cat" "dog"
Levels are sorted alphabetically by default: this matters later.
A data frame is a table whose columns are vectors of equal length:
word freq
1 cat 120
2 dog 95
3 bird 30
A function takes arguments inside its brackets. Name them to make code readable:
[1] 3.14
?mean opens the help page for
mean(): read the Arguments, and run the Examples at the
bottomswirlswirl teaches you R, inside R. Its interactive lessons
range from the basics to modelling, and some of your homework will use
them (swirlstats.com).
You installed it already. To start a lesson:
The first time, swirl asks you to choose and install a
course.
Inside a lesson: bye() quits and saves your progress,
skip() skips a question, main() goes back to
the menu.
tidyverseThe tidyverse is a collection of R packages, created by
Hadley Wickham and colleagues, for
importing, reshaping and plotting data.
It replaces many base R functions with alternatives that are easier to read and write. Think of it as a dialect of R, with base R as the standard variety.
We start using it next week. It builds on everything you saw today: vectors, data frames and functions.
Did you know: aye-ayes have a sixth finger. Next to each
thumb is a small pseudothumb, with its own
fingerprint, that helps them grip branches.
Source: Hartstone-Rose et al. (2019), American Journal of Physical Anthropology
Two researchers receive the same recordings and the same research question, and analyse them independently.
Coretta et al. (2023) gave one speech production data set and one research question to 46 teams of analysts.
Every analysis involves choices like these. Statistics makes them explicit, so others can check them.
By the end of the course you will be able to:
Open RStudio, start a new script, and run the code from
today’s slides line by line.
Then change things: other numbers, other words, a missing value. Seeing what breaks is the quickest way to learn what each piece does.
These slides
mcanzi.de/ws26_statistics/
Code, data and all lectures
github.com/mcanzi/ws26_statistics