Wordscores in R

A while ago I wrote a step by step guide for using Wordscores in R. I did this as part of the FP7 project SOM, but ended up doing the analyses myself. I have recently posted some code on running Wordscores in R:

# #################################
# WORDSCORES AND WORDFISH ANALYSIS
# #################################

# setup
library(austin)

############################
# GETTING DOCUMENTS IN
############################
a <- wfm("SHORT.1995-2011.csv")
a[0,] # check the party order (header only)

############################
# A. WORDFISH
############################
wordfish(a, dir=c(23, 20), control=list(tol=1e-06, sigma=3, startparams=NULL), verbose=FALSE)
# identification strategy:
# GPS 2003 and SVP 2003
# these are the extremes in the expert survey (moving average or alternative count)
# also they are nicely the Benoit & Laver texts, for which we have some confidence

############################
# B. WORDSCORES
############################

# SET REFERENCES
ref <- c(10,11,15,20,23) # reference texts
vir <- 1:24 # SPS 2011 (short) is empty, thus not included
vir <- vir[-ref] # everything minus the reference texts

r <- getdocs (a, ref)
ws <- classic.wordscores(r, scores=c(5.971929825,1.252631579,4.665789474,9.206140351,0.935087719))
summary(ws)

# PREDICT
v <- getdocs (a, vir)
predict(ws,newdata=v)

I use Will Lowe’s JFreq to get the word frequencies.

One thought on “Wordscores in R

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s