Stylometry Step-by-Step

For our experiments with stylometry, we will be using the stylo package for R developed by Maciej Eder, Jan Rybicki, and Mike Kestemont. This page is a cleaned-up version of their installation guidelines from the package’s home page as well as their “how-to.”

Things to install

  1. R
  2. RStudio
  3. Mac users only: XQuartz. You will need to restart your computer after installing this.

Prep your corpus

  1. Create a working folder for the project you’re tackling (e.g., bom-stylo).
  2. Within that working folder, create a folder called “corpus” and place your texts in there. It will work best if the files are plain text.
  3. Make sure that each text is named with the feature that you’re testing for, followed by an underscore and then whatever you want. For example, authorname_title.txt or gender_title.txt.

In RStudio

  1. Install Stylo by typing install.packages("stylo"). You’ll only need to do this once. Note the need for quotation marks.
  2. Activate Stylo by typing library(stylo). You’ll need to do this each time you start an RStudio session.
  3. Move to your working folder (not the corpus folder) with the command setwd(filepath). Alternatively, you can use RStudio’s menus: Session > Set Working Directory > Choose Directory...
  4. Type stylo() to start up the function with the GUI working.
  5. Click OK when you’ve got all the options set.

GUI options to tweak

Features

  1. Change MFW (most frequent word) count. Keep Minimum and Maximum set to identical values.
  2. Change Features from words to chars if wanted.

Statistics

  1. Cluster Analysis will produce a dendrogram.
  2. PCA (corr.) will produce a principal component analysis, which is easier to read.

Output

  1. Click “png” to save a copy of the outputted image file
  2. CPA flavour
    • Classic will be a simple graph with just the label of the text.
    • Loadings will provide the MFW superimposed along with the labels of the text.