wordfish_comparison: Wordfish Comparison.

Description Usage Arguments Value Examples

View source: R/wordfish_comparison.R

Description

Calculated Wordfish scores for a list of dfm objects with temporal filtering.

Usage

1
2
3
4
5
6
7
wordfish_comparison(
  dfm_list,
  years,
  anchors = c(1, 24),
  proportion_threshold = 1,
  document_inidices = NULL
)

Arguments

dfm_list

A list of quanteda dfm objects generated by the 'factorial_preprocessing()' and returned in the '$dfm_list' field

years

A numeric vector giving the year for each document.

anchors

A numeric vector of length two used to anchor the Wordfish estimates. Defaults to c(1,24) which should work for the UK parliament docs.

proportion_threshold

proportion of years a term must be included in to be included in the Wordfish analysis.

document_inidices

An option vector of row indices to be used. Useful for using a subset of the data for analysis.

Value

A result list object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
## Not run: 
# replicates wordfish aanalysis from Denny and Spirling (2016)
# load the package
library(preText)
# load in the data
data("UK_Manifestos")
# preprocess data
preprocessed_documents <- factorial_preprocessing(
    UK_Manifestos,
    use_ngrams = TRUE,
    infrequent_term_threshold = 0.02,
    verbose = TRUE)
# get the years each document was written and store them as a numeric vector
dfm <- preprocessed_documents$dfm_list[[1]]
rl <- function(str) {
    stringr::str_replace_all(str,"[A-Za-z]+","")
}
years <- as.numeric(sapply(rownames(dfm),rl))

# use the wordfish_comparison function to compare all dfms. We are using
# conservative and labour manifestos from 1983, 1987, 1992, and 1997 for a total
# of 8 manifestos. These are indicated by the document_inidices = c(19:22,42:45)
# argument. You can see the document names by entering rownames(dfm) into the
# console. We need to set the anchors to 5,1 because anchoring is applied in the
# reduced dfm. We are also only including terms that appear atleast once in a
# manifesto from each of the 4 years, to deal with the strong temporal effects.
wordfish_results <- wordfish_comparison(
    preprocessed_documents$dfm_list,
    years,
    anchors = c(1,5),
    proportion_threshold = 1,
    document_inidices = c(19:22,42:45))

## End(Not run)

matthewjdenny/preText documentation built on July 27, 2021, 1:18 a.m.