<p>Today is the one year anniversary of the <a href="https://cran.r-project.org/package=janeaustenr">janeaustenr</a> package’s appearance on CRAN, its <a href="https://twitter.com/dataandme/status/847904785890250754">cranniversary</a>, if you will. I think it’s time for more Jane Austen here on my blog.</p>
<p><a href="https://giphy.com/gifs/jane-austen-W4DAivVgfYCeQ">via GIPHY</a></p>
<p>I saw <a href="http://culturalanalytics.org/2016/12/understanding-gender-and-character-agency-in-the-19th-century-novel/">this paper</a> by Matthew Jockers and Gabi Kirilloff a number of months ago and the ideas in it have been knocking around in my head ever since. The authors of that paper used text mining to examine a corpus of 19th century novels and explore how gendered pronouns (he/she/him/her) are associated with different verbs. These authors used the Stanford CoreNLP library to parse dependencies in sentences and find which verbs are connected to which pronouns; I have been thinking about how to apply a different approach to this question using tidy data principles and n-grams. Let’s see what we can do!</p>
<h2>Jane Austen and n-grams</h2>
<p>An n-gram is a contiguous series of words from a text; for example, a bigram is a pair of words, with . If we want to find out which verbs an author is more likely to pair with the pronoun “she” than with “he”, we can analyze bigrams. Let’s use <code>unnest_tokens</code> from the tidytext package to identify all the bigrams in the 6 completed, published novels of Jane Austen and <a href="http://tidytextmining.com/tidytext.html">transform this to a tidy dataset</a>.</p>
<pre><code><span>library</span><span>(</span><span>tidyverse</span><span>)</span><span>
</span><span>library</span><span>(</span><span>tidytext</span><span>)</span><span>
</span><span>library</span><span>(</span><span>janeaustenr</span><span>)</span><span>
</span><span>austen_bigrams</span><span> </span><span>&lt;-</span><span> </span><span>austen_books</span><span>()</span><span> </span><span>%>%</span><span>
</span><span>unnest_tokens</span><span>(</span><span>bigram</span><span>,</span><span> </span><span>text</span><span>,</span><span> </span><span>token</span><span> </span><span>=</span><span> </span><span>&quot;ngrams&quot;</span><span>,</span><span> </span><span>n</span><span> </span><span>=</span><span> </span><span>2</span><span>)</span><span>
</span><span>austen_bigrams</span></code></pre><pre><code>## # A tibble: 725,048 × 2
##                   book          bigram
##                 &lt;fctr>           &lt;chr>
## 1  Sense &amp; Sensibility       sense and
## 2  Sense &amp; Sensibility and sensibility
## 3  Sense &amp; Sensibility  sensibility by
## 4  Sense &amp; Sensibility         by jane
## 5  Sense &amp; Sensibility     jane austen
## 6  Sense &amp; Sensibility     austen 1811
## 7  Sense &amp; Sensibility    1811 chapter
## 8  Sense &amp; Sensibility       chapter 1
## 9  Sense &amp; Sensibility           1 the
## 10 Sense &amp; Sensibility      the family
## # ... with 725,038 more rows</code></pre><p>That is all the bigrams from Jane Austen’s works, but we only want the ones that start with “he” or “she”. Jane Austen wrote in the third person, so this is a good example set of texts for this question. The original paper used dependency parsing of sentences and included other pronouns like “her” and “him”, but let’s just look for bigrams that start with “she” and “he”. We will get some adverbs and modifiers and such as the second word in the bigram, but mostly verbs, the main thing we are interested in.</p>
<pre><code><span>pronouns</span><span> </span><span>&lt;-</span><span> </span><span>c</span><span>(</span><span>&quot;he&quot;</span><span>,</span><span> </span><span>&quot;she&quot;</span><span>)</span><span>
</span><span>bigram_counts</span><span> </span><span>&lt;-</span><span> </span><span>austen_bigrams</span><span> </span><span>%>%</span><span>
</span><span>count</span><span>(</span><span>book</span><span>,</span><span> </span><span>bigram</span><span>,</span><span> </span><span>sort</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>ungroup</span><span>()</span><span> </span><span>%>%</span><span>
</span><span>separate</span><span>(</span><span>bigram</span><span>,</span><span> </span><span>c</span><span>(</span><span>&quot;word1&quot;</span><span>,</span><span> </span><span>&quot;word2&quot;</span><span>),</span><span> </span><span>sep</span><span> </span><span>=</span><span> </span><span>&quot; &quot;</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>word1</span><span> </span><span>%in%</span><span> </span><span>pronouns</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>count</span><span>(</span><span>word1</span><span>,</span><span> </span><span>word2</span><span>,</span><span> </span><span>wt</span><span> </span><span>=</span><span> </span><span>n</span><span>,</span><span> </span><span>sort</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>rename</span><span>(</span><span>total</span><span> </span><span>=</span><span> </span><span>nn</span><span>)</span><span>
</span><span>bigram_counts</span></code></pre><pre><code>## # A tibble: 1,571 × 3
##    word1 word2 total
##    &lt;chr> &lt;chr> &lt;int>
## 1    she   had  1472
## 2    she   was  1377
## 3     he   had  1023
## 4     he   was   889
## 5    she could   817
## 6     he    is   399
## 7    she would   383
## 8    she    is   330
## 9     he could   307
## 10    he would   264
## # ... with 1,561 more rows</code></pre><p>There we go! These are the most common bigrams that start with “he” and “she” in Jane Austen’s works. Notice that there are more mentions of women than men here; this makes sense as Jane Austen’s novels have protagonists who are women. The most common bigrams look pretty similar between the male and female characters in Austen’s works. Let’s calculate a log odds ratio so we can find the words (hopefully mostly verbs) that exhibit the biggest differences between relative use for “she” and “he”.</p>
<pre><code><span>word_ratios</span><span> </span><span>&lt;-</span><span> </span><span>bigram_counts</span><span> </span><span>%>%</span><span>
</span><span>group_by</span><span>(</span><span>word2</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>word_total</span><span> </span><span>=</span><span> </span><span>sum</span><span>(</span><span>total</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>ungroup</span><span>()</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>word_total</span><span> </span><span>></span><span> </span><span>10</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>select</span><span>(</span><span>-</span><span>word_total</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>spread</span><span>(</span><span>word1</span><span>,</span><span> </span><span>total</span><span>,</span><span> </span><span>fill</span><span> </span><span>=</span><span> </span><span>0</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>mutate_if</span><span>(</span><span>is.numeric</span><span>,</span><span> </span><span>funs</span><span>((</span><span>.</span><span> </span><span>+</span><span> </span><span>1</span><span>)</span><span> </span><span>/</span><span> </span><span>sum</span><span>(</span><span>.</span><span> </span><span>+</span><span> </span><span>1</span><span>)))</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>logratio</span><span> </span><span>=</span><span> </span><span>log</span><span>(</span><span>she</span><span> </span><span>/</span><span> </span><span>he</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>arrange</span><span>(</span><span>desc</span><span>(</span><span>logratio</span><span>))</span><span> </span></code></pre><p>Which words have about the same likelihood of following “he” or “she” in Jane Austen’s novels?</p>
<pre><code><span>word_ratios</span><span> </span><span>%>%</span><span> </span><span>arrange</span><span>(</span><span>abs</span><span>(</span><span>logratio</span><span>))</span></code></pre><pre><code>## # A tibble: 164 × 4
##           word2          he          she    logratio
##           &lt;chr>       &lt;dbl>        &lt;dbl>       &lt;dbl>
## 1        always 0.001846438 0.0018956289  0.02629233
## 2         loves 0.000923219 0.0008920607 -0.03433229
## 3           too 0.000923219 0.0008920607 -0.03433229
## 4          when 0.000923219 0.0008920607 -0.03433229
## 5  acknowledged 0.001077089 0.0011150758  0.03466058
## 6      remained 0.001077089 0.0011150758  0.03466058
## 7           had 0.157562702 0.1642506690  0.04157024
## 8        paused 0.001384828 0.0014495986  0.04571041
## 9         would 0.040775504 0.0428189117  0.04889836
## 10       turned 0.003077397 0.0032337199  0.04954919
## # ... with 154 more rows</code></pre><p>These words, like “always” and “loves”, are about as likely to come after the word “she” as the word “he”. Now let’s look at the words that exhibit the largest differences in appearing after “she” compared to “he”.</p>
<pre><code><span>word_ratios</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>abslogratio</span><span> </span><span>=</span><span> </span><span>abs</span><span>(</span><span>logratio</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>group_by</span><span>(</span><span>logratio</span><span> </span><span>&lt;</span><span> </span><span>0</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>top_n</span><span>(</span><span>15</span><span>,</span><span> </span><span>abslogratio</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>ungroup</span><span>()</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>word</span><span> </span><span>=</span><span> </span><span>reorder</span><span>(</span><span>word2</span><span>,</span><span> </span><span>logratio</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>ggplot</span><span>(</span><span>aes</span><span>(</span><span>word</span><span>,</span><span> </span><span>logratio</span><span>,</span><span> </span><span>color</span><span> </span><span>=</span><span> </span><span>logratio</span><span> </span><span>&lt;</span><span> </span><span>0</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_segment</span><span>(</span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>word</span><span>,</span><span> </span><span>xend</span><span> </span><span>=</span><span> </span><span>word</span><span>,</span><span>
</span><span>y</span><span> </span><span>=</span><span> </span><span>0</span><span>,</span><span> </span><span>yend</span><span> </span><span>=</span><span> </span><span>logratio</span><span>),</span><span> </span><span>size</span><span> </span><span>=</span><span> </span><span>1.1</span><span>,</span><span> </span><span>alpha</span><span> </span><span>=</span><span> </span><span>0.6</span><span>)</span><span> </span><span>+</span><span>
</span><span>geom_point</span><span>(</span><span>size</span><span> </span><span>=</span><span> </span><span>3.5</span><span>)</span><span> </span><span>+</span><span>
</span><span>coord_flip</span><span>()</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>NULL</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>&quot;Relative appearance after 'she' compared to 'he'&quot;</span><span>,</span><span>
</span><span>title</span><span> </span><span>=</span><span> </span><span>&quot;Words paired with 'he' and 'she' in Jane Austen's novels&quot;</span><span>,</span><span>
</span><span>subtitle</span><span> </span><span>=</span><span> </span><span>&quot;Women remember, read, and feel while men stop, take, and reply&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>scale_color_discrete</span><span>(</span><span>name</span><span> </span><span>=</span><span> </span><span>&quot;&quot;</span><span>,</span><span> </span><span>labels</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>&quot;More 'she'&quot;</span><span>,</span><span> </span><span>&quot;More 'he'&quot;</span><span>))</span><span> </span><span>+</span><span>
</span><span>scale_y_continuous</span><span>(</span><span>breaks</span><span> </span><span>=</span><span> </span><span>seq</span><span>(</span><span>-1</span><span>,</span><span> </span><span>2</span><span>),</span><span>
</span><span>labels</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>&quot;0.5x&quot;</span><span>,</span><span> </span><span>&quot;Same&quot;</span><span>,</span><span> </span><span>&quot;2x&quot;</span><span>,</span><span> </span><span>&quot;4x&quot;</span><span>))</span></code></pre><p></p>
<p>These words are the ones that are the most different in how Jane Austen used them with the pronouns “he” and “she”. Women in Austen’s novels do things like remember, read, feel, resolve, long, hear, dare, and cry. Men, on the other hand, in these novels do things like stop, take, reply, come, marry, and know. Women in Austen’s world can be funny and smart and unconventional, but she plays with these ideas within a cultural context where they act out gendered roles.</p>
<h2>George Eliot and n-grams</h2>
<p>Let’s look at another set of novels to see some similarities and differences. Let’s take some novels of George Eliot, another English writer (a woman) who lived and wrote several decades after Jane Austen. Let’s take <a href="https://www.gutenberg.org/ebooks/145">Middlemarch</a> (MY FAVE), <a href="https://www.gutenberg.org/ebooks/550">Silas Marner</a>, and <a href="https://www.gutenberg.org/ebooks/6688">The Mill on the Floss</a>.</p>
<pre><code><span>library</span><span>(</span><span>gutenbergr</span><span>)</span><span>
</span><span>eliot</span><span> </span><span>&lt;-</span><span> </span><span>gutenberg_download</span><span>(</span><span>c</span><span>(</span><span>145</span><span>,</span><span> </span><span>550</span><span>,</span><span> </span><span>6688</span><span>),</span><span>
</span><span>mirror</span><span> </span><span>=</span><span> </span><span>&quot;http://mirrors.xmission.com/gutenberg/&quot;</span><span>)</span></code></pre><p>We now have the texts downloaded from Project Gutenberg. We can use the same approach as above and calculate the log odds ratios for each word that comes after “he” and “she” in these novels of George Eliot.</p>
<pre><code><span>eliot_ratios</span><span> </span><span>&lt;-</span><span> </span><span>eliot</span><span> </span><span>%>%</span><span>
</span><span>unnest_tokens</span><span>(</span><span>bigram</span><span>,</span><span> </span><span>text</span><span>,</span><span> </span><span>token</span><span> </span><span>=</span><span> </span><span>&quot;ngrams&quot;</span><span>,</span><span> </span><span>n</span><span> </span><span>=</span><span> </span><span>2</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>count</span><span>(</span><span>bigram</span><span>,</span><span> </span><span>sort</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>ungroup</span><span>()</span><span> </span><span>%>%</span><span>
</span><span>separate</span><span>(</span><span>bigram</span><span>,</span><span> </span><span>c</span><span>(</span><span>&quot;word1&quot;</span><span>,</span><span> </span><span>&quot;word2&quot;</span><span>),</span><span> </span><span>sep</span><span> </span><span>=</span><span> </span><span>&quot; &quot;</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>word1</span><span> </span><span>%in%</span><span> </span><span>pronouns</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>count</span><span>(</span><span>word1</span><span>,</span><span> </span><span>word2</span><span>,</span><span> </span><span>wt</span><span> </span><span>=</span><span> </span><span>n</span><span>,</span><span> </span><span>sort</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>rename</span><span>(</span><span>total</span><span> </span><span>=</span><span> </span><span>nn</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>group_by</span><span>(</span><span>word2</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>word_total</span><span> </span><span>=</span><span> </span><span>sum</span><span>(</span><span>total</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>ungroup</span><span>()</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>word_total</span><span> </span><span>></span><span> </span><span>10</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>select</span><span>(</span><span>-</span><span>word_total</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>spread</span><span>(</span><span>word1</span><span>,</span><span> </span><span>total</span><span>,</span><span> </span><span>fill</span><span> </span><span>=</span><span> </span><span>0</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>mutate_if</span><span>(</span><span>is.numeric</span><span>,</span><span> </span><span>funs</span><span>((</span><span>.</span><span> </span><span>+</span><span> </span><span>1</span><span>)</span><span> </span><span>/</span><span> </span><span>sum</span><span>(</span><span>.</span><span> </span><span>+</span><span> </span><span>1</span><span>)))</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>logratio</span><span> </span><span>=</span><span> </span><span>log</span><span>(</span><span>she</span><span> </span><span>/</span><span> </span><span>he</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>arrange</span><span>(</span><span>desc</span><span>(</span><span>logratio</span><span>))</span></code></pre><p>What words exhibit the largest differences in their appearance after these pronouns in George Eliot’s works?</p>
<pre><code><span>eliot_ratios</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>abslogratio</span><span> </span><span>=</span><span> </span><span>abs</span><span>(</span><span>logratio</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>group_by</span><span>(</span><span>logratio</span><span> </span><span>&lt;</span><span> </span><span>0</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>top_n</span><span>(</span><span>15</span><span>,</span><span> </span><span>abslogratio</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>ungroup</span><span>()</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>word</span><span> </span><span>=</span><span> </span><span>reorder</span><span>(</span><span>word2</span><span>,</span><span> </span><span>logratio</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>ggplot</span><span>(</span><span>aes</span><span>(</span><span>word</span><span>,</span><span> </span><span>logratio</span><span>,</span><span> </span><span>color</span><span> </span><span>=</span><span> </span><span>logratio</span><span> </span><span>&lt;</span><span> </span><span>0</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_segment</span><span>(</span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>word</span><span>,</span><span> </span><span>xend</span><span> </span><span>=</span><span> </span><span>word</span><span>,</span><span>
</span><span>y</span><span> </span><span>=</span><span> </span><span>0</span><span>,</span><span> </span><span>yend</span><span> </span><span>=</span><span> </span><span>logratio</span><span>),</span><span> </span><span>size</span><span> </span><span>=</span><span> </span><span>1.1</span><span>,</span><span> </span><span>alpha</span><span> </span><span>=</span><span> </span><span>0.6</span><span>)</span><span> </span><span>+</span><span>
</span><span>geom_point</span><span>(</span><span>size</span><span> </span><span>=</span><span> </span><span>3.5</span><span>)</span><span> </span><span>+</span><span>
</span><span>coord_flip</span><span>()</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>NULL</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>&quot;Relative appearance after 'she' compared to 'he'&quot;</span><span>,</span><span>
</span><span>title</span><span> </span><span>=</span><span> </span><span>&quot;Words paired with 'he' and 'she' in George Eliot's novels&quot;</span><span>,</span><span>
</span><span>subtitle</span><span> </span><span>=</span><span> </span><span>&quot;Women read, run, and need while men leave, mean, and tell&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>scale_color_discrete</span><span>(</span><span>name</span><span> </span><span>=</span><span> </span><span>&quot;&quot;</span><span>,</span><span> </span><span>labels</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>&quot;More 'she'&quot;</span><span>,</span><span> </span><span>&quot;More 'he'&quot;</span><span>))</span><span> </span><span>+</span><span>
</span><span>scale_y_continuous</span><span>(</span><span>breaks</span><span> </span><span>=</span><span> </span><span>seq</span><span>(</span><span>-3</span><span>,</span><span> </span><span>3</span><span>),</span><span>
</span><span>labels</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>&quot;0.125x&quot;</span><span>,</span><span> </span><span>&quot;0.25x&quot;</span><span>,</span><span> </span><span>&quot;0.5x&quot;</span><span>,</span><span> </span><span>&quot;Same&quot;</span><span>,</span><span> </span><span>&quot;2x&quot;</span><span>,</span><span> </span><span>&quot;4x&quot;</span><span>,</span><span> </span><span>&quot;8x&quot;</span><span>))</span></code></pre><p></p>
<p>We can see some difference in word use and style here, but overall there are quite similar ideas behind the verbs for women and men in Eliot’s works as Austen’s. Women read, run, need, marry, and look while men leave, mean, tell, know, and call. The verbs associated with women are more connected to emotion or feelings while the verbs associated with men are more connected to action or speaking.</p>
<h2>Jane Eyre and n-grams</h2>
<p>Finally, let’s look at one more novel. The original paper found that <a href="https://www.gutenberg.org/ebooks/1260">Jane Eyre by Charlotte Brontë</a> had its verbs switched, in that there were lots of active, non-feelings verbs associated with feminine pronouns. That Jane Eyre!</p>
<pre><code><span>eyre</span><span> </span><span>&lt;-</span><span> </span><span>gutenberg_download</span><span>(</span><span>1260</span><span>,</span><span>
</span><span>mirror</span><span> </span><span>=</span><span> </span><span>&quot;http://mirrors.xmission.com/gutenberg/&quot;</span><span>)</span><span>
</span><span>eyre_ratios</span><span> </span><span>&lt;-</span><span> </span><span>eyre</span><span> </span><span>%>%</span><span>
</span><span>unnest_tokens</span><span>(</span><span>bigram</span><span>,</span><span> </span><span>text</span><span>,</span><span> </span><span>token</span><span> </span><span>=</span><span> </span><span>&quot;ngrams&quot;</span><span>,</span><span> </span><span>n</span><span> </span><span>=</span><span> </span><span>2</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>count</span><span>(</span><span>bigram</span><span>,</span><span> </span><span>sort</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>ungroup</span><span>()</span><span> </span><span>%>%</span><span>
</span><span>separate</span><span>(</span><span>bigram</span><span>,</span><span> </span><span>c</span><span>(</span><span>&quot;word1&quot;</span><span>,</span><span> </span><span>&quot;word2&quot;</span><span>),</span><span> </span><span>sep</span><span> </span><span>=</span><span> </span><span>&quot; &quot;</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>word1</span><span> </span><span>%in%</span><span> </span><span>pronouns</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>count</span><span>(</span><span>word1</span><span>,</span><span> </span><span>word2</span><span>,</span><span> </span><span>wt</span><span> </span><span>=</span><span> </span><span>n</span><span>,</span><span> </span><span>sort</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>rename</span><span>(</span><span>total</span><span> </span><span>=</span><span> </span><span>nn</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>group_by</span><span>(</span><span>word2</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>word_total</span><span> </span><span>=</span><span> </span><span>sum</span><span>(</span><span>total</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>ungroup</span><span>()</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>word_total</span><span> </span><span>></span><span> </span><span>5</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>select</span><span>(</span><span>-</span><span>word_total</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>spread</span><span>(</span><span>word1</span><span>,</span><span> </span><span>total</span><span>,</span><span> </span><span>fill</span><span> </span><span>=</span><span> </span><span>0</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>mutate_if</span><span>(</span><span>is.numeric</span><span>,</span><span> </span><span>funs</span><span>((</span><span>.</span><span> </span><span>+</span><span> </span><span>1</span><span>)</span><span> </span><span>/</span><span> </span><span>sum</span><span>(</span><span>.</span><span> </span><span>+</span><span> </span><span>1</span><span>)))</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>logratio</span><span> </span><span>=</span><span> </span><span>log</span><span>(</span><span>she</span><span> </span><span>/</span><span> </span><span>he</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>arrange</span><span>(</span><span>desc</span><span>(</span><span>logratio</span><span>))</span></code></pre><p>What words exhibit the largest differences in Jane Eyre?</p>
<pre><code><span>eyre_ratios</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>abslogratio</span><span> </span><span>=</span><span> </span><span>abs</span><span>(</span><span>logratio</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>group_by</span><span>(</span><span>logratio</span><span> </span><span>&lt;</span><span> </span><span>0</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>top_n</span><span>(</span><span>15</span><span>,</span><span> </span><span>abslogratio</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>ungroup</span><span>()</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>word</span><span> </span><span>=</span><span> </span><span>reorder</span><span>(</span><span>word2</span><span>,</span><span> </span><span>logratio</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>ggplot</span><span>(</span><span>aes</span><span>(</span><span>word</span><span>,</span><span> </span><span>logratio</span><span>,</span><span> </span><span>color</span><span> </span><span>=</span><span> </span><span>logratio</span><span> </span><span>&lt;</span><span> </span><span>0</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_segment</span><span>(</span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>word</span><span>,</span><span> </span><span>xend</span><span> </span><span>=</span><span> </span><span>word</span><span>,</span><span>
</span><span>y</span><span> </span><span>=</span><span> </span><span>0</span><span>,</span><span> </span><span>yend</span><span> </span><span>=</span><span> </span><span>logratio</span><span>),</span><span> </span><span>size</span><span> </span><span>=</span><span> </span><span>1.1</span><span>,</span><span> </span><span>alpha</span><span> </span><span>=</span><span> </span><span>0.6</span><span>)</span><span> </span><span>+</span><span>
</span><span>geom_point</span><span>(</span><span>size</span><span> </span><span>=</span><span> </span><span>3.5</span><span>)</span><span> </span><span>+</span><span>
</span><span>coord_flip</span><span>()</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>NULL</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>&quot;Relative appearance after 'she' compared to 'he'&quot;</span><span>,</span><span>
</span><span>title</span><span> </span><span>=</span><span> </span><span>&quot;Words paired with 'he' and 'she' in Jane Eyre&quot;</span><span>,</span><span>
</span><span>subtitle</span><span> </span><span>=</span><span> </span><span>&quot;Women look, tell, and open while men stop, smile, and pause&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>scale_color_discrete</span><span>(</span><span>name</span><span> </span><span>=</span><span> </span><span>&quot;&quot;</span><span>,</span><span> </span><span>labels</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>&quot;More 'she'&quot;</span><span>,</span><span> </span><span>&quot;More 'he'&quot;</span><span>))</span><span> </span><span>+</span><span>
</span><span>scale_y_continuous</span><span>(</span><span>breaks</span><span> </span><span>=</span><span> </span><span>seq</span><span>(</span><span>-3</span><span>,</span><span> </span><span>3</span><span>),</span><span>
</span><span>labels</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>&quot;0.125x&quot;</span><span>,</span><span> </span><span>&quot;0.25x&quot;</span><span>,</span><span> </span><span>&quot;0.5x&quot;</span><span>,</span><span> </span><span>&quot;Same&quot;</span><span>,</span><span> </span><span>&quot;2x&quot;</span><span>,</span><span> </span><span>&quot;4x&quot;</span><span>,</span><span> </span><span>&quot;8x&quot;</span><span>))</span></code></pre><p></p>
<p>Indeed, the words that are more likely to appear after “she” are not particularly feelings-oriented; women in this novel do things like look, tell, open, and do. Men in Jane Eyre do things like stop, smile, pause, pursue, and stand.</p>
<h2>The End</h2>
<p>It is so interesting to me how these various authors understand and portray their characters’ roles and gender, and how we can see that through analyzing word choices. The R Markdown file used to make this blog post is available <a href="https://github.com/juliasilge/juliasilge.github.io/blob/master/_R/2017-04-15-Gender-Pronouns.Rmd">here</a>. I am very happy to hear about that or other feedback and questions!</p>