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.
In this problem we are going to use blackbox transpose from the
basicspace package in
R.
Download the R programs:
basicspace_big_blackbox_transpose_1968_Therms.r --
R program that performs a basicspace transpose scaling on the 12 Candidate Feeling Thermometers From the 1968 National
Election Study. This version removes the 1500 respondent restriction -- Use with caution!
The program
reads this R program (courtesy of James Lo):
big_blackbox_transpose.R --
R code that creates the function
big_blackbox_transpose which is used in the R program above.
Place the two R programs in the same directory as the first calls the second.
- Run basicspace_big_blackbox_transpose_1968_Therms.r and turn in the plots that it
creates. Adjust the name position vector namepos so that none of the 12
Candidate names overstrike.
- Report summary(result) NEATLY FORMATTED and result$fits NEATLY FORMATTED.
We are now going to try blackbox transpose on the NES 1968 Urban Unrest and Vietnam 7 point scales to test how
unidimensional they are.
Download the R programs:
The programs
read this R program (courtesy of James Lo):
big_blackbox_transpose.R --
R code that creates the function
big_blackbox_transpose which is used in the R program above.
Place the three R programs in the same directory as the first two call the
third.
- Run basicspace_big_blackbox_transpose_Urban_Unrest_1968.r. Report summary(result)
NEATLY FORMATTED and result$fits NEATLY FORMATTED.
- Run basicspace_big_blackbox_transpose_Vietnam_1968.r. Report summary(result)
NEATLY FORMATTED and result$fits NEATLY FORMATTED.
- In your opinion, are these two scales unidimensional? Explain.
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, 102 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)?