Quantitative Text Analysis Using R: A Half-Day Tutorial
Version: 15 November 2017
This repository contains the workshop materials for a half-day tutorial Quantitative to Text Analysis Using R. This project was supported through European Research Council grant ERC-2011-StG 283794-QUANTESS.
Instructions for using this resource
You have three options for downloading the course material found on this page:
You can download the materials by clicking on each link.
You can "clone" this repository, using the buttons found to the right side of your browser window as you view this repository. This is the button labelled "Clone in Desktop". If you do not have a git client installed on your system, you will need to get one here and also to make sure that git is installed. This is preferred, since you can refresh your clone as new content gets pushed to the course repository. (And new material will get actively pushed to the course repository at least once per day as this course takes place.)
Statically, you can choose the button on the right marked "Download zip" which will download the entire repository as a zip file.
You can also subscribe to the repository if you have a GitHub account, which will send you updates each time new changes are pushed to the repository.
This workshop covers how to perform common text analysis and natural language processing tasks using R. When used properly, R is a fast and powerful tool for managing even very large text analysis tasks.
The course consists of instructor presentations in three sets, followed by interactive exercises that students are meant to work through during the workshop.
We will cover how to format and input source texts, how to structure their metadata, and how to prepare them for analysis. This includes common tasks such as tokenisation, including constructing ngrams and "skip-grams", removing stopwords, stemming words, and other forms of feature selection. We show how to: get summary statistics from text, search for and analyse keywords and phrases, analyse text for lexical diversity and readability, detect collocations, apply dictionaries, and measure term and document associations using distance measures. Our analysis covers basic text-related data processing in the R base language, but most relies on the quanteda package for the quantitative analysis of textual data. We also discuss (briefly) how to pass the structured objects from quanteda into other text analytic packages for doing topic modelling, latent semantic analysis, regression models, and other forms of machine learning.
While it is designed for those who have used R in some form previously, expertise in R is not required, and even those with no previous knowledge of R are welcome.
Part 1: Getting Started and Basic Text Analysis
- An overview of the quanteda package
- Getting started, text import, and basic analysis
- Some basic quanteda workflow guidelines
Setting up RStudio and quanteda:
- CRAN for downloading and installing R
- Configuration test: Try running this RMarkdown file: test_setup.Rmd. If it builds without error and looks like this, then you have successfully configured your system.
Step through a simple analysis:
- Step through execution of the 1_getting_started/1_getting_started.Rmd file. (This requires that you use RStudio and have installed the knitr and rmarkdown packages, but if you try to click the "Knit" button and have not yet installed these, the program will prompt you to do so.)
- Sample data files:
Part 2: Basic text analysis using collocation, keyness and dictionary
Part 3: Advanced analysis and working with other text packages
- Advanced analysis and working with other packages
- as slides
- Twitter analysis example, and the instructions for setting up your own Twitter app, in Twitter.Rmd.
- spacyr: part-of-speech tagging and dependency parsing using the spaCy engine.
- LIWCalike: replicate the Linguistic Inquiry and Word Count program's functionality.
- readtext: read texts into R (replaces the
textfile()function from quanteda).
- preText: Diagnostics to assess the effects of text "pre-processing" decisions.
Additional leadning resources
Designed to be done before the course or after, to augment what is presented during the course. These are just suggestions -- no reading for the course is required.
- [Sanchez, G. 2013. Handling and Processing Strings in R Trowchez Editions. Berkeley, 2013.](http://www.gastonsanchez.com/Handling and Processing Strings in R.pdf)
- stringi package page, which also includes a good discussion of the ICU library
- Some guides to regular expressions: Zytrax.com's User Guide or the comprehensive resources from http://www.regular-expressions.info
- See the
quantedatag on Stack Overflow, where you can pose questions and see some brilliant answers by our development team.