##############################################
######    R-Commands - Sociolinguistics   ####
######             Paris 2023             ####
##############################################

If you make the Cross-Tabulation in excel or google docs
# Step one - Create cross tabulation in excel or google docs
# Step two - Copy data from Excel into “bloc notes” (not Word Pad)
# Step three - Load data into R from txt file

xtab <- read.table(file.choose(), header=T, sep="\t", row.names= 1)

# Check your cross-tabulation
xtab

To make the Cross-Tabulation in R

df <- read.table(file.choose(), header=T, sep="\t", stringsAsFactors = T)
xtab <- table(df)

# Check your cross-tabulation
xtab

######################
###  SIGNIFICANCE  ###
######################

######################
#  Chi-Squared Test  #
######################

# This is the most common test in corpus linguistics / sociology
# It tests to see if the variation / differences could be chance.
# It gives you a p-value

CHI = chisq.test(xtab)
CHI

# Pearson residuals and (anti-)correlation
# These show which cells are responsible for differences between the sets
RES= CHI$res
RES