R program:
Here is the code block that creates roll calls from Thermometer Comparisons
nrollcall <- (nq*(nq-1))/2
LDATA <- rep(0,np*nrollcall)
dim(LDATA) <- c(np,nrollcall)
for (i in 1:np){
jj <- 0
for (j in 1:(nq-1)){
for (k in (j+1):nq){
jj <- jj + 1
#
if(!is.na(T[i,j])){
if(!is.na(T[i,k])){
#
if(T[i,j] > T[i,k])LDATA[i,jj]=1 If the Thermometers are equal then it is treated as missing data
if(T[i,j] < T[i,k])LDATA[i,jj]=6
}
}
}
}
}
mode(LDATA) <- "double"
#
hr <- rollcall(LDATA,yea=1,nay=6,missing=0,notInLegis=9,
legis.names=NULL, vote.names=NULL, legis.data=NULL, vote.data=NULL,
desc=NULL, source=NULL)
result <- oc(hr, dims=2, polarity=c(1,2))
#
Here is how to select just the cutting lines for Wallace
#
# PLOT JUST THE WALLACE CUTTING LINES
i <- 1
#
while (i <= 11){
#
etc. etc.
Here is how to select just the cutting lines for Humphrey
#
# PLOT THE HUMPHREY CUTTING LINES
#
kkk <- NULL
kkk[1] <- 1
kkk[2:11] <- 12:21 Humphrey's cutting lines are 1, and 12-21
#
for (iii in 1:11){
i <- kkk[iii]
#
- Run the program and turn in the pair of two panel plots that it produces.
- Turn in summary(result) NEATLY FORMATTED and report result$fits.
- Add the code necessary to do a third two panel plot showing the cutting lines for Nixon and LBJ. Turn in the plot
and the short code block (similar to the one above for Humphrey) you used to get the cutting lines for Nixon and
LBJ, respectively.
We are going to explore some nice features of Simon Jackman's
Ideal program for analyzing roll call data.
Ideal is part of the
pscl package that has many nice routines
(see this pdf describing the package, 100 pages ).
Download the R program:
#
rm(list=ls(all=TRUE))
#
library(pscl)
#
#
hr <- readKH("https://legacy.voteview.com/k7ftp/sen104kh.ord",
dtl=NULL,
yea=c(1,2,3),
nay=c(4,5,6),
missing=c(7,8,9),
notInLegis=0,
desc="104th Senate Roll Call Data",
debug=FALSE)
#
# Call IDEAL
#
# parameter "normalize=FALSE" is default setting
#
result <- ideal(hr, d=1, normalize=FALSE, store.item=TRUE)
#
# names(result)
# [1] "n" "m" "d" "codes" "x" "beta" "xbar"
# [8] "betabar" "call"
#
# object "result" is unidentified
#
# "tracex" is a nice function to plot MCMC output for specified legislators:
#
tracex(result,d=1,legis=c("HELMS","KENNEDY"))
#
# postProcess identifies the solution, default method is
# via normalization
#
result_id <- postProcess(result,constraints="normalize")
#
# names(result_id)
# [1] "n" "m" "d" "codes" "x" "beta" "xbar"
# [8] "betabar" "call"
#
windows()
plot(result)
windows()
plot(result_id)
#
# The model is identified but signed incorrectly; we can also
# achieve identification by setting coordinates of k+1 points:
#
result_id2 <- postProcess(result,constraints=list(KENNEDY=c(-1),HELMS=c(1)))
#
windows()
plot(result_id2)
#
- Run Ideal_104_senate.r and turn in all the plots that it makes.
- Turn in summary(result) NEATLY FORMATTED.
- Type the commands:
result_id3 <- postProcess(result,constraints=list(BOXER=c(-1),INHOFE=c(1)))
plot(result_id3)
Turn in this plot. Which Political Party is the most dispersed (i.e., has the bigger variance in ideal points)?
In this problem we are going to try Lewis and Poole's Parametric Bootstrap with
WNOMINATE.
Download the R program:
- Run wnominate_bootstrap.r and turn in the plot that it makes.
- Report result$fits
.
Turn in plot(result).