# # Plot_Bootstrap.r -- Program reads parametric bootstrap files posted # at http://voteview.org/Lewis_and_Poole.htm # and plots the legislator ideal points and the # standard errors # # Remove all objects just to be safe # rm(list=ls(all=TRUE)) library(MASS) library(pcurve) library(stats) library(ellipse) # # Set up to read Parametric Bootstrap File # rc.file <- "c:/ucsd_course/s90_bs_1000_2.dat" # # The variable fields and their widths # rc.fields <- c("counter","cong","id","state","dist","lstate","party", "eh1","eh2","name","wnom1","wnom2","wnom1bs","wnom2bs", "se1","se2","r12") # # Note -- For some files the field widths will be (e.g., H108_BS_1000_2.DAT): # (5,3,5,2,2,7,4,1,1,11,8,7,7,7,7,7,7) # rc.fieldWidths <- c(4,4,5,2,2,7,4,1,1,11,10,10,10,10,10,10,10) # # Read the vote data from fwf (FIXED WIDTH FORMAT -- FWF) # TT <- read.fwf(file=rc.file,widths=rc.fieldWidths,as.is=TRUE,col.names=rc.fields) party <- TT[,7] state <- TT[,4] wnom1 <- TT[,11] wnom2 <- TT[,12] std1 <- TT[,15] std2 <- TT[,16] corr12 <- TT[,17] # nrow <- length(TT[,1]) ncol <- length(TT[1,]) # plot(TT[,11],TT[,12],type="n",asp=1, main="90th Senate From W-NOMINATE \nWith Bootstrapped Standard Errors", xlab="Liberal-Conservative", ylab="Civil Rights/Social Issues", xlim=c(-1.0,1.0),ylim=c(-1.0,1.0)) points(wnom1[party == 100 & state >= 40 & state <= 51],wnom2[party == 100 & state >= 40 & state <= 51],pch='S',col="red") points(wnom1[party == 100 & state == 53],wnom2[party == 100 & state == 53],pch='S',col="red") points(wnom1[party == 100 & state == 54],wnom2[party == 100 & state == 54],pch='S',col="red") points(wnom1[party == 100 & (state < 40 | state > 54)],wnom2[party == 100 & (state < 40 | state > 54)],pch='D',col="red") points(wnom1[party == 100 & state == 52],wnom2[party == 100 & state == 52],pch='D',col="red") points(wnom1[party == 200],wnom2[party == 200],pch='R',col="blue") # # This code does the cross-hairs for the standard errors. If the # correlation is greater than .15 between the two dimensions, # the 95% confidence ellipse is shown # for (i in 1:nrow) { # # These two statements do the cross-hairs # lines(c(wnom1[i],wnom1[i]),c(wnom2[i]-1.96*std2[i],wnom2[i]+1.96*std2[i]),col="gray") lines(c(wnom1[i]-1.96*std1[i],wnom1[i]+1.96*std1[i]),c(wnom2[i],wnom2[i]),col="gray") # # This if statement does the ellipse # if (abs(corr12[i]) > .15){ lines(ellipse(x=corr12[i],scale=c(std1[i],std2[i]), centre=c(wnom1[i],wnom2[i])), col="gray") } } #