# # dwnominate_polarization.r # # ANALYZING SPATIAL MODELS OF CHOICE AND JUDGMENT WITH R # Dave Armstrong, Ryan Bakker, Royce Carroll, Christopher Hare, Keith T. Poole, and Howard Rosenthal # http://voteview.com/asmcjr.asp # # # Remove all objects just to be safe. rm(list=ls(all=TRUE)) # library(lattice) # rcx.file <- url("ftp://voteview.com/junkord/HL01111E21_PRES.DAT") rcx.fields <- c("cong","id","state","dist","lstate","party","name", "dwnom1","dwnom2","dwnom1bse","dwnom2bse","corrbse","LogL", "nchoice","nerror","gmp") rcx.fieldWidths <- c(4,6,3,2,9,4,12,7,7,7,7,7,12,5,6,6) TT <- read.fwf(file=rcx.file,widths=rcx.fieldWidths,as.is=TRUE, col.names=rcx.fields) attach(TT) # ncong1 <- 90 ncong2 <- 100 ncong3 <- 110 X1 <- cbind(dwnom1[cong==ncong1 & dist!=0],party[cong==ncong1 & dist!=0], paste("House",ncong1)) X2 <- cbind(dwnom1[cong==ncong2 & dist!=0],party[cong==ncong2 & dist!=0], paste("House",ncong2)) X3 <- cbind(dwnom1[cong==ncong3 & dist!=0],party[cong==ncong3 & dist!=0], paste("House",ncong3)) polarization <- rbind(X1,X2,X3) # bwtheme <- standard.theme("pdf", color=FALSE) densityplot(~polarization[,1] | polarization[,3], groups=polarization[,2], index.cond=list(c(2,1,3)), as.table=FALSE, ref=TRUE, layout=c(1,3), plot.points=FALSE, main="First Dimension DW-NOMINATE Scores by Party", xlab="Solid = Democrats, Dotted = Republicans", par.settings=bwtheme) #