Statistics for Corpus Linguists
  • Overview
  • Introduction to R
    • 1.1 First steps
    • 1.2 Exploring R Studio
    • 1.3 Vectors
    • 1.4 Data frames
    • 1.5 Libraries
    • 1.6 Importing/Exporting
  • NLP
    • 2.1 Concordancing
    • 2.2 Regular expressions
    • 2.3 The CQP interface
    • 2.4 Data annotation
  • Statistics
    • 3.1 Data, variables, samples
    • 3.2 Probability theory
    • 3.3 Descriptive statistics
    • 3.4 Hypothesis testing
    • 3.5 Chi-squared test
    • 3.6 t-test
    • 3.7 ANOVA
    • 3.8 Case study
  • Models
    • 4.1 Linear regression
    • 4.2 Logistic regression
    • 4.3 Poisson regression
  • Machine Learning
    • 5.1 Tree-based methods
    • 5.2 Gradient boosting
  1. 3. Introduction to Statistics
  2. 3.8 Case study
  • 3. Introduction to Statistics
    • 3.1 Data, variables, samples
    • 3.2 Probability theory
    • 3.3 Descriptive statistics
    • 3.4 Hypothesis testing
    • 3.5 Chi-squared test
    • 3.6 t-test
    • 3.7 ANOVA
    • 3.8 Case study

On this page

  • Overview
  • Research question and hypotheses
  • Preparation
  • Descriptive analysis
    • Object realisation and medium
    • Object realisation and text category
  • Inferential analysis
    • Object realisation and medium
    • Object realisation and text category
  • Post-hoc analyses
    • Residuals
    • Configural Frequency Analysis
  • Reporting the results
  • Exercises

Other Formats

  • PDF
  1. 3. Introduction to Statistics
  2. 3.8 Case study

3.8 Case study: Object realisation of EAT

Author
Affiliation

Vladimir Buskin

Catholic University of Eichstätt-Ingolstadt

Abstract
This handout presents a complete analysis of categorical corpus data, from the research question to the write-up. Using annotated concordance lines of the verb EAT from ICE-GB, it combines descriptive statistics, the chi-squared test, Fisher’s exact test, effect sizes, residuals and configural frequency analysis.

Overview

This unit shows what a simple, but complete corpus-linguistic analysis can look like. It brings together the steps covered in the previous units:

  • obtaining and annotating the data (see 2.4 Data annotation),
  • describing the data with frequency tables and plots (see 3.3 Descriptive statistics), and
  • testing hypotheses about the relationship between two categorical variables (see 3.4 Hypothesis testing and 3.5 Chi-squared test).

Research question and hypotheses

In 2.4 Data annotation, we asked whether grammatical aspect influences whether the direct object of eat is realised or omitted. Before examining aspect (see the exercises), it is worth checking whether object realisation also varies across registers. If, for instance, objects were omitted much more often in conversation than in writing, register would have to be taken into account when interpreting any other effect.

We will therefore test the following hypotheses for the variables object_realisation (yes/no) and medium (spoken/written):

  • \(H_0:\) Object realisation and medium are independent of each other.
  • \(H_1:\) Object realisation and medium are not independent of each other.

The same hypotheses will be tested for the more fine-grained text_category (S1A, S1B, …, W2F).

Preparation

library(tidyverse)
library(readxl)
library(confintr) # for Cramér's V
library(cfa) # for configural frequency analysis

We use the annotated dataset from 2.4 Data annotation, which you can download here. If you have annotated data of your own, you may use it instead.

# Load data
data_eat <- read_xlsx("eat_obj_aspect.xlsx")

The dataset follows the default kwic() structure with the document name and the immediate context before and after the keyword. The columns object_realisation (dependent variable) and verb_aspect (independent variable) are the result of manual annotation in MS Excel.

head(data_eat)
# A tibble: 6 × 9
  docname  from    to pre   keyword post  pattern object_realisation verb_aspect
  <chr>   <dbl> <dbl> <chr> <chr>   <chr> <chr>   <chr>              <chr>      
1 ICE_GB…   458   458 had … eaten   anyw… "\\b(e… no                 perfective 
2 ICE_GB…   478   478 : 1 … eating  will… "\\b(e… no                 progressive
3 ICE_GB…   785   785 > Ye… eat     befo… "\\b(e… no                 neutral    
4 ICE_GB…  1198  1198 the … eat     them… "\\b(e… yes                neutral    
5 ICE_GB…  4529  4529 > Ye… ate     in t… "\\b(e… no                 neutral    
6 ICE_GB…   958   958 know… eat     it f… "\\b(e… yes                neutral    

First, we remove the false hits, which were coded as NA during annotation, and add the register information as shown in 2.4 Data annotation:

data_eat <- data_eat %>%
  # Keep only rows without NA in object_realisation
  filter(!is.na(object_realisation)) %>%
  # Extract text category and medium from the file names
  mutate(
    text_category = str_extract(docname, "[SW][12][A-F]"),
    medium = if_else(str_starts(text_category, "S"), "spoken", "written")
  )

nrow(data_eat)
[1] 102

Descriptive analysis

Object realisation and medium

We first compute the absolute frequencies of each combination of values in a contingency table:

obj_sw_freq <- xtabs(~ object_realisation + medium, data = data_eat)

obj_sw_freq
                  medium
object_realisation spoken written
               no      41      16
               yes     27      18

Since the spoken and written subsets differ in size, absolute frequencies are hard to compare. We therefore compute the percentages of realised and omitted objects within each medium, i.e., per column (margin = 2):

obj_sw_prop <- prop.table(obj_sw_freq, margin = 2) * 100

round(obj_sw_prop, 2)
                  medium
object_realisation spoken written
               no   60.29   47.06
               yes  39.71   52.94
# Convert the percentage table to a data frame for plotting
obj_sw_prop_df <- as.data.frame(obj_sw_prop)
colnames(obj_sw_prop_df) <- c("object_realisation", "medium", "pct")

ggplot(obj_sw_prop_df, aes(x = medium, y = pct, fill = object_realisation)) +
  geom_col(position = "dodge") +
  labs(x = "Medium", y = "Percentage", fill = "Object realised?") +
  theme_minimal()

Object realisation and text category

obj_reg_freq <- xtabs(~ object_realisation + text_category, data = data_eat)

obj_reg_freq
                  text_category
object_realisation S1A S1B S2A S2B W1B W2B W2C W2D W2E W2F
               no   30   6   3   2   9   0   3   2   1   1
               yes  19   4   3   1   1  14   0   2   0   1
obj_reg_prop <- prop.table(obj_reg_freq, margin = 2) * 100

round(obj_reg_prop, 2)
                  text_category
object_realisation    S1A    S1B    S2A    S2B    W1B    W2B    W2C    W2D
               no   61.22  60.00  50.00  66.67  90.00   0.00 100.00  50.00
               yes  38.78  40.00  50.00  33.33  10.00 100.00   0.00  50.00
                  text_category
object_realisation    W2E    W2F
               no  100.00  50.00
               yes   0.00  50.00
obj_reg_prop_df <- as.data.frame(obj_reg_prop)
colnames(obj_reg_prop_df) <- c("object_realisation", "text_category", "pct")

ggplot(obj_reg_prop_df, aes(x = object_realisation, y = pct)) +
  geom_col() +
  facet_wrap(~ text_category) +
  labs(x = "Object realised?", y = "Percentage") +
  theme_minimal()

Note that some text categories contain only a handful of hits, so their percentages are based on very few observations. Text categories without any hits do not appear at all.

Inferential analysis

Object realisation and medium

For a 2 \(\times\) 2 table with sufficiently large expected frequencies, we can use the \(\chi^2\) test. By default, chisq.test() applies Yates’ continuity correction to 2 \(\times\) 2 tables (see 3.5 Chi-squared test).

sw_test <- chisq.test(obj_sw_freq)

sw_test

    Pearson's Chi-squared test with Yates' continuity correction

data:  obj_sw_freq
X-squared = 1.1184, df = 1, p-value = 0.2903
# Check the expected frequencies
sw_test$expected
                  medium
object_realisation spoken written
               no      38      19
               yes     30      15

The effect size Cramér’s \(V\) indicates how strongly the two variables are associated (0 = no association, 1 = perfect association). Note that cramersv() is based on the uncorrected \(\chi^2\) statistic.

cramersv(obj_sw_freq)
[1] 0.1256562

Object realisation and text category

With 10 text categories and only 102 observations, many expected frequencies are very small. The assumptions of the \(\chi^2\) test are therefore violated, and we use Fisher’s exact test instead:

# Expected frequencies under H0
round(chisq.test(obj_reg_freq)$expected, 2)
Warning in chisq.test(obj_reg_freq): Chi-squared approximation may be incorrect
                  text_category
object_realisation   S1A  S1B  S2A  S2B  W1B  W2B  W2C  W2D  W2E  W2F
               no  27.38 5.59 3.35 1.68 5.59 7.82 1.68 2.24 0.56 1.12
               yes 21.62 4.41 2.65 1.32 4.41 6.18 1.32 1.76 0.44 0.88
reg_test <- fisher.test(obj_reg_freq)

reg_test

    Fisher's Exact Test for Count Data

data:  obj_reg_freq
p-value = 5.15e-05
alternative hypothesis: two.sided

Post-hoc analyses

A significant test result tells us that the variables are associated, but not where the association comes from. Two approaches can help to identify the relevant cells.

Residuals

The Pearson residuals \((O - E)/\sqrt{E}\) show which cells deviate most from the expected frequencies. In an association plot, bars above the line indicate cells with more observations than expected, bars below the line cells with fewer observations than expected. The area of each bar is proportional to the difference between observed and expected frequencies.

# Pearson residuals
round(chisq.test(obj_reg_freq)$residuals, 2)
Warning in chisq.test(obj_reg_freq): Chi-squared approximation may be incorrect
                  text_category
object_realisation   S1A   S1B   S2A   S2B   W1B   W2B   W2C   W2D   W2E   W2F
               no   0.50  0.17 -0.19  0.25  1.44 -2.80  1.02 -0.16  0.59 -0.11
               yes -0.56 -0.20  0.22 -0.28 -1.62  3.15 -1.15  0.18 -0.66  0.13
assocplot(t(obj_reg_freq), col = c("black", "lightgrey"))

Configural Frequency Analysis

Configural Frequency Analysis (CFA) tests each combination of values (a configuration) for whether it occurs significantly more often (type) or less often (antitype) than expected. Since every configuration is tested separately, the \(p\)-values have to be corrected for multiple testing, e.g., with the Bonferroni correction.

# Convert the contingency table to a data frame with one row per configuration
reg_config_df <- as.data.frame(obj_reg_freq)

# The first two columns contain the configurations, the Freq column the corresponding counts
reg_configs <- as.matrix(reg_config_df[, 1:2])
reg_counts <- reg_config_df$Freq

# Perform CFA with Bonferroni correction
reg_cfa_output <- cfa(reg_configs, reg_counts, bonferroni = TRUE)

# Print the full output with reg_cfa_output, or only the most relevant columns:
reg_cfa_output$table[, c("label", "n", "expected", "z", "p.z", "sig.z")]
     label  n   expected         z          p.z sig.z
1  yes W2B 14  6.1764706 3.1479841 0.0008220032  TRUE
2   no W2B  0  7.8235294 2.7970573 0.0025785195 FALSE
3  yes W1B  1  4.4117647 1.6243249 0.0521532431 FALSE
4   no W1B  9  5.5882353 1.4432505 0.0744749528 FALSE
5  yes W2C  0  1.3235294 1.1504475 0.1249798063 FALSE
6   no W2C  3  1.6764706 1.0221994 0.1533432642 FALSE
7  yes W2E  0  0.4411765 0.6642112 0.2532775845 FALSE
8   no W2E  1  0.5588235 0.5901671 0.2775393112 FALSE
9  yes S1A 19 21.6176471 0.5629980 0.2867181112 FALSE
10  no S1A 30 27.3823529 0.5002369 0.3084541462 FALSE
11 yes S2B  1  1.3235294 0.2812205 0.3892706426 FALSE
12  no S2B  2  1.6764706 0.2498710 0.4013435678 FALSE
13 yes S2A  3  2.6470588 0.2169305 0.4141312704 FALSE
14 yes S1B  4  4.4117647 0.1960392 0.4222897374 FALSE
15  no S2A  3  3.3529412 0.1927478 0.4235782550 FALSE
16 yes W2D  2  1.7647059 0.1771230 0.4297058971 FALSE
17  no S1B  6  5.5882353 0.1741854 0.4308598754 FALSE
18  no W2D  2  2.2352941 0.1573779 0.4374735168 FALSE
19 yes W2F  1  0.8823529 0.1252449 0.4501648525 FALSE
20  no W2F  1  1.1176471 0.1112830 0.4556959770 FALSE

The relevant columns are the observed frequency n, the expected frequency, the test statistic z1 with its \(p\)-value p.z, and sig.z, which indicates whether a configuration is significant after the Bonferroni correction. Since z is always positive in this output, we have to compare n and expected to determine whether a significant configuration is a type or an antitype.

1 The \(z\)-score corresponds to the absolute value of the Pearson residual, \[ z = \frac{|\text{observed} - \text{expected}|}{\sqrt{\text{expected}}}, \] which approximately follows a standard normal distribution under \(H_0\). The approximation is poor for small expected frequencies, so the results should be interpreted with caution in sparse tables like this one.

In our data, the following configuration(s) are significant after Bonferroni correction: yes W2B (type; observed = 14, expected = 6.18, \(z = 3.15\)).

Reporting the results

In a paper or report, the results could be described as follows. Note that the report contains the test statistic, the degrees of freedom, the \(p\)-value and the effect size, so that readers can evaluate the results themselves.

Object realisation of eat was compared across spoken and written texts in ICE-GB (n = 102). Objects were realised in 39.7% of the spoken and 52.9% of the written attestations. According to a \(\chi^2\) test with Yates’ continuity correction, this difference is not statistically significant (\(\chi^2(1) = 1.12\), \(p = 0.29\), Cramér’s \(V = 0.13\)). A Fisher’s exact test indicates a significant association between object realisation and the more fine-grained text categories (\(p < 0.001\)).

Limitations

This analysis is deliberately simple. A more thorough study would have to address at least the following issues:

  • Non-independence: Several hits may come from the same text or speaker. The tests used here assume that all observations are independent of each other.
  • Sparse data: Many text categories contain very few hits, which makes the fine-grained comparison unreliable.
  • Several variables at once: Register and aspect might both influence object realisation. Testing each variable separately cannot disentangle their effects, which requires a multivariate model such as logistic regression.

Exercises

Exercise 1 The data frame data_eat contains a column verb_aspect with information on the aspect of the verb (perfective, progressive or neutral).

data_eat[, c("keyword", "object_realisation", "verb_aspect")]
# A tibble: 102 × 3
   keyword object_realisation verb_aspect
   <chr>   <chr>              <chr>      
 1 eaten   no                 perfective 
 2 eating  no                 progressive
 3 eat     no                 neutral    
 4 eat     yes                neutral    
 5 ate     no                 neutral    
 6 eat     yes                neutral    
 7 eating  no                 progressive
 8 eaten   no                 perfective 
 9 eaten   no                 perfective 
10 eaten   no                 perfective 
# ℹ 92 more rows

Analyse the relationship between object realisation and verbal aspect. Your analysis should include both a descriptive component (frequency and percentage tables; plots) and an inferential one (hypothesis testing). Check the expected frequencies to decide on an appropriate test.

Exercise 2 Report the results of Exercise 1 in the style of the sample report above.

Exercise 3 Optional: Conduct a configural frequency analysis to examine potential three-way relationships between object realisation, aspect, and medium (spoken/written). Hint: Start with xtabs(~ object_realisation + verb_aspect + medium, data = data_eat).

3.7 ANOVA