1. Getting used to dictionaries

a. Creating a simple dictionary. (15 pts)

Dictionaries are named lists, consisting of a “key” and a set of entries defining the equivalence class for the given key. To create a simple dictionary of parts of speech, for instance we could define a dictionary consisting of articles and conjunctions, using the dictionary() constructor

posDict <- dictionary(list(articles = c("the", "a", "an"),
                           conjunctions = c("and", "but", "or", "nor", "for", "yet", "so")))

You can examine this dictionary by invoking its print method, simply by typing the name of the object and pressing Enter. Try that now.

What is the structure of this object? (Hint: use str().)

To let this define a set of features, we can use this dictionary when we create a dfm, for instance:

posDfm <- dfm(data_corpus_inaugural, dictionary = posDict)
head(posDfm)
## Document-feature matrix of: 6 documents, 2 features (0% sparse).
## 6 x 2 sparse Matrix of class "dfm"
##                  features
## docs              articles conjunctions
##   1789-Washington      140           73
##   1793-Washington       14            4
##   1797-Adams           232          192
##   1801-Jefferson       154          109
##   1805-Jefferson       168          126
##   1809-Madison         128           63

Weight the posDfm by relative term frequency, and plot the values of articles and conjunctions (actually, here just the coordinating conjunctions) across the speeches. (Hint: you can use docvars(data_corpus_inaugural, "Year")) for the x-axis.)

Is the distribution of normalized articles and conjunctions relatively constant across years, as you would expect?

b. Hierarchical dictionaries. (10 pts)

Dictionaries may also be hierarchical, where a top-level key can consist of subordinate keys, each a list of its own. For instance, list(articles = list(definite="the", indefinite=c("a", "and")) defines a valid list for articles. Make a dictionary of articles and conjunctions where you define two levels, one for definite and indefinite articles, and one for coordinating and subordinating conjunctions. (A sufficient list for your purposes of subordinating conjuctions is “although”, “because”, “since”, “unless”.)

Now apply this to the data_corpus_inaugural object, and examine the resulting features. What happened to the hierarchies, to make them into “features”? Do the subcategories sum to the two categories from the previous question?

2. Getting used to thesauruses (10 pts)

A “thesaurus” is a list of feature equivalencies specified in the same list format as a dictionary, but which—unlike a dictionary—returns all the features not specified as entries in the thesaurus.

If we wanted to count pronouns as equivalent, for instance, we could use the thesaurus argument to dfm in order to group all listed prounouns into a single feature labelled “PRONOUN”.

mytexts <- c("We are not schizophrenic, but I am.", "I bought myself a new car.")
myThes <- dictionary(list(pronouns = list(firstp=c("I", "me", "my", "mine", "myself", "we", "us", "our", "ours"))))
myDfm <- dfm(mytexts, thesaurus = myThes)
myDfm
## Document-feature matrix of: 2 documents, 12 features (41.7% sparse).
## 2 x 12 sparse Matrix of class "dfm"
##        features
## docs    PRONOUNS.FIRSTP are not schizophrenic , but am . bought a new car
##   text1               2   1   1             1 1   1  1 1      0 0   0   0
##   text2               2   0   0             0 0   0  0 1      1 1   1   1

Notice how the thesaurus key has been made into uppercase — this is to identify it as a key, as opposed to a word feature from the original text.

Try running the articles and conjunctions dictionary from the previous exercise on as a thesaurus, and compare the results.

3. Other ways to achieve the same outcomes. (10 pts)

When you call dfm() with a dictionary = or thesaurus = argument, then what dfm() does internally is actually to first constructing the entire dfm, and then select features using a call to dfm_lookup().

Try creating a dfm object using the first five inaugural speeches, with no dictionary applied. Then apply the posDict from the first question to select features a) in a way that replicates the dictionary argument to dfm(), and b) in a way that replicates the thesaurus argument to dfm().

4. Populism dictionary (25 pts)

Here we will create and implement the populism dictionary from Rooduijn, Matthijs, and Teun Pauwels (2011) “Measuring Populism: Comparing Two Methods of Content Analysis.” West European Politics 34(6): 1272–83. Appendix B of that paper provides the term entries for a dictionary key for the concept populism. Implement this as a dictionary, and apply it to the same UK manifestos as in the article.

Hint: You can get a corpus of the UK manifestos from their article using the following:

data(data_corpus_ukmanifestos, package = "quanteda.corpora")
ukPopCorpus <- corpus_subset(data_corpus_ukmanifestos,
                             (Year %in% c(1992, 2001, 2005) &
                                  (Party %in% c("Lab", "LD", "Con", "BNP", "UKIP"))))
summary(ukPopCorpus)
## Corpus consisting of 11 documents:
##
##                  Text Types Tokens Sentences Country Type Year Language
##   UK_natl_1992_en_Con  4671  33124      1588      UK natl 1992       en
##   UK_natl_1992_en_Lab  2374  12565       619      UK natl 1992       en
##    UK_natl_1992_en_LD  3148  19466       885      UK natl 1992       en
##   UK_natl_2001_en_Con  2840  14567       675      UK natl 2001       en
##   UK_natl_2001_en_Lab  4200  32368      1518      UK natl 2001       en
##    UK_natl_2001_en_LD  3924  23643      1223      UK natl 2001       en
##   UK_natl_2005_en_BNP  5027  28854      1031      UK natl 2005       en
##   UK_natl_2005_en_Con  2096   8493       389      UK natl 2005       en
##   UK_natl_2005_en_Lab  4112  26697      1099      UK natl 2005       en
##    UK_natl_2005_en_LD  3294  18044       816      UK natl 2005       en
##  UK_natl_2005_en_UKIP  2495  10275       408      UK natl 2005       en
##  Party
##    Con
##    Lab
##     LD
##    Con
##    Lab
##     LD
##    BNP
##    Con
##    Lab
##     LD
##   UKIP
##
## Source: /Users/kbenoit/Dropbox/QUANTESS/quantedaData_kenlocal_gh/* on x86_64 by kbenoit
## Created: Sat Nov 15 18:43:36 2014
## Notes:

Create a dfm of the populism dictionary on the UK manifestos. Use this dfm to reproduce the x-axis for the UK-based parties from Figure 1 in the article. Suggestion: Use dotchart(). You will need to normalize the values first by term frequency within document. Hint: Use dfm_weight(youDfmName, "prop") on the dfm.

You can explore some of these terms within the corpus to see whether you think they are appropriate measures of populism. How can you search the corpus for the regular expression politici* as a “keyword in context”?

5. Laver and Garry (2000) ideology dictionary (15 pts)

Here, we will apply the dictionary of Laver, Michael, and John Garry. 2000. “Estimating Policy Positions From Political Texts.” American Journal of Political Science 44(3): 619–34. Using the pre-built Laver and Garry (2000) dictionary file, which is distributed by Provalis Research for use with its Wordstat software package from Provalis, we will apply this to the same manifestos from the UK manifesto set.
To do this, you will need to:

6. Fun with the Regressive Imagery Dictionary (15 pts)

Try analyzing the inaugural speeches from 1980 onward using the Regressive Imagery Dictionary, from Martindale, C. (1975) Romantic progression: The psychology of literary history. Washington, D.C.: Hemisphere. You can download the dictionary from http://www.provalisresearch.com/Download/RID.ZIP, formatted for WordStat. Compare the Presidents based on the level of “Icarian Imagery.”

Which president is the most Icarian?