LEGACY CONTENT. If you are looking for Voteview.com, PLEASE CLICK HERE

This site is an archived version of Voteview.com archived from University of Georgia on May 23, 2017. This point-in-time capture includes all files publicly linked on Voteview.com at that time. We provide access to this content as a service to ensure that past users of Voteview.com have access to historical files. This content will remain online until at least January 1st, 2018. UCLA provides no warranty or guarantee of access to these files.

POLI 279 MEASUREMENT THEORY
Seventh Assignment
Due 30 May 2007


  1. In this problem we are going to use the classic W-NOMINATE program to analyze the 104th House and Senates. Download the program, control card files, and data files and place them in the same directory.

    WNOM9707 -- W-NOMINATE Program
    W-NOMINATE is discussed in detail with several examples on the W-NOMINATE Page.

    1. Run W-NOMINATE on the 104th House. Turn in the NOM21.DAT output file.

    2. The legislator coordinates are in the output file NOM31.DAT. The first few lines should look similar to this:
          11049990999 0USA     100  CLINTON       55  17   6  99  0.733 -0.587  0.065
          21041509041 1ALABAMA 20000CALLAHAN     563  58  15 503  0.853  0.729  0.043
          31042930041 2ALABAMA 20000EVERETT      571  70  21 502  0.825  0.746  0.041
          41041563241 3ALABAMA 10000BROWDER      459  89 120 462  0.664 -0.037  0.015
          51041100041 4ALABAMA 10000BEVILL       438 121 108 462  0.660 -0.081  0.015
          61042910041 5ALABAMA 10000CRAMER       470  97 116 480  0.662 -0.023  0.014
          71042930141 6ALABAMA 20000BACHUS       602  32  34 488  0.856  0.689  0.036
          81042930241 7ALABAMA 10000HILLIARD     457 121  34 504  0.726 -0.643  0.023
          91041406681 1ALASKA  20000YOUNG, DON   519  49  31 466  0.814  0.592  0.031
         101042950061 1ARIZONA 20000SALMON       615  37  45 468  0.840  0.816  0.045
                                  etc etc etc
                                  etc etc etc
      The legislator coordinates are in the next to the last column (shown in red). For example, former President Clinton's coordinate is -0.587. Use R to make a smoothed histogram of the Republicans and Democrats in the 104th House using the estimated coordinates above (the party code is shown in blue). Use arrows to show the locations of former President Clinton and former Speaker of the House Newt Gingrich.

    3. Use Epsilon to change the number of dimensions to "2" in NOMSTART.DAT and run the program again (be sure to save NOM31.DAT from the one dimensional run as it will be overwritten). NOMSTART.DAT (NOMSTART.H104) looks like this:
      HOU104KH.ORD                Name of Data File
      NOMINAL MULTIDIMENSIONAL UNFOLDING   Title of Run
       1321    1    5             Number RCs, Left on 1st, Up on 2nd
          1   36                  Number Dimensions, Number Characters to Read From Header
       15.0000  0.5000            Starting Values for BETA and WEIGHT
        0.0250   20               RC Min. Cutoff, Number RCs for Legislator
      (36A1,3600I1)               Format for Roll Call File
      (1x,I4,36A1,1X,4i4,51f7.3)  Format for Legislator Coordinate File -- NOM31.DAT
      (1x,I4,36A1,1X,51f7.3)      Format for H-S Coordinate File -- FORT.34
      The red "1" in the fourth line is the number of dimensions. This is the number you should change to "2". Leave everything else in the file the same! Run W-NOMINATE on the 104th House in two dimensions. Turn in the NOM21.DAT output file.

    4. The two-dimensional coordinate file looks like this:
          11049990999 0USA     100  CLINTON       54  17   7  99  0.729 -0.594 -0.116  0.066  0.129
          21041509041 1ALABAMA 20000CALLAHAN     561  36  17 525  0.880  0.758  0.653  0.042  0.132
          31042930041 2ALABAMA 20000EVERETT      569  50  23 522  0.852  0.774  0.634  0.040  0.132
          41041563241 3ALABAMA 10000BROWDER      473  35 106 516  0.733 -0.034  0.842  0.015  0.083
          51041100041 4ALABAMA 10000BEVILL       448  57  98 526  0.723 -0.079  0.759  0.015  0.075
          61042910041 5ALABAMA 10000CRAMER       474  46 112 531  0.710 -0.018  0.688  0.015  0.064
          71042930141 6ALABAMA 20000BACHUS       597  25  39 495  0.861  0.695  0.232  0.035  0.078
          81042930241 7ALABAMA 10000HILLIARD     445 117  46 508  0.748 -0.642  0.417  0.023  0.046
          91041406681 1ALASKA  20000YOUNG, DON   517  34  33 481  0.839  0.600  0.583  0.031  0.122
         101042950061 1ARIZONA 20000SALMON       623  35  37 470  0.842  0.826 -0.119  0.045  0.075
                                  etc etc etc
                                  etc etc etc
      The legislator coordinates are are the third and fourth columns from the end (shown in red). For example, former President Clinton's coordinates are -0.594 and -0.116. Use R to plot the legislators in two dimensions. Use "D" for Non-Southern Democrats, "S" for Southern Democrats, "R" for Republicans, and "P" for President Clinton. This graph should be in the same format as the one you did for question 2.f of Homework 5.

    5. Run W-NOMINATE on the 104th Senate. Turn in the NOM21.DAT output file.

    6. Use R to make a smoothed histogram of the Republicans and Democrats in the 104th Senate using the estimated coordinates from the NOM31.DAT file. Use arrows to show the locations of former President Clinton, and Senators Kennedy and Helms.

    7. Use Epsilon to change the number of dimensions to "2" in NOMSTART.DAT and run the program again (be sure to save NOM31.DAT from the one dimensional run as it will be overwritten). Use R to plot the legislators in two dimensions. Use "D" for Non-Southern Democrats, "S" for Southern Democrats, "R" for Republicans, and "P" for President Clinton. This graph should be in the same format as the one you did for question 1.f of Homework 5.

  2. In this problem we are going to use the Parametric Bootstrap version of W-NOMINATE to generate standard errors for the 104th Senate. Download the program, control card file, and data file and place them in the same directory.

    WNOMJLEWIS_REALLY_BIG -- W-NOMINATE Parametric Bootstrap Program
    W-NOMINATE is discussed in detail with several examples on the W-NOMINATE Page and the bootstrap file output is discussed in detail on the Parametric Bootstrap Output page and the the Parametric Bootstrap Program page.

    NOMSTART_JLEWIS.DAT looks like this:
    SEN104KH.ORD
     NOMINAL MULTIDIMENSIONAL UNFOLDING OF 104TH SENATE
      919    1   22
        2   36   11               Number Dimensions, Number Characters to Read from Header, Number of Bootstrap Trials
     15.0000  0.5000
      0.0250   20
    (36A1,15000I1)
    (1x,I4,36A1,1X,4i4,51f7.3)
    (I4,1X,36A1,80F10.4)
    It is identical to the NOMSTART.DAT used in question 1 above except for the "11" (colored red) in the fourth line of the file. This is the number of bootstrap trials. Normally it is set to 1001 but we will use 101 in this problem.

    Put the files in the same directory and run WNOMJLEWIS. You will get 7 output files -- fort.26, fort.56, NOM21.DAT, NOM23.DAT, NOM31.DAT, NOM33.DAT, and NOM36.DAT. The NOM21.DAT - NOM36.DAT files are explained on the W-NOMINATE Page.

    FORT.26 are the parametric bootsrapped legislator coordinates. The file will look something like this:
    
       1 1049990999 0USA     10000CLINTON       -0.9160   -0.3336   -0.8668   -0.2853    0.1039    0.2095    1.0000    0.1436    0.1436    1.0000
       2 1041470541 0ALABAMA 10000HEFLIN        -0.3923   -0.2917   -0.3546   -0.4203    0.0510    0.1876    1.0000    0.7794    0.7794    1.0000
       3 1049465941 0ALABAMA 20000SHELBY         0.5858   -0.3131    0.6871   -0.3176    0.1162    0.0603    1.0000    0.2238    0.2238    1.0000
       4 1041490781 0ALASKA  20000MURKOWSKI      0.6600   -0.1009    0.7623   -0.0338    0.1138    0.1090    1.0000    0.0790    0.0790    1.0000
       5 1041210981 0ALASKA  20000STEVENS        0.4199   -0.3162    0.5695   -0.3110    0.1645    0.1222    1.0000    0.1487    0.1487    1.0000
              etc etc etc
      98 1044930873 0WASHING 10000MURRAY        -0.9235   -0.1667   -0.8936   -0.1832    0.0555    0.0916    1.0000   -0.1436   -0.1436    1.0000
      99 104 136656 0WEST VI 10000BYRD, ROBER   -0.6504   -0.5292   -0.6249   -0.6165    0.0465    0.1304    1.0000    0.1703    0.1703    1.0000
     100 1041492256 0WEST VI 10000ROCKEFELLER   -0.8080   -0.0714   -0.7819   -0.0967    0.0416    0.1585    1.0000    0.6202    0.6202    1.0000
     101 1044930925 0WISCONS 10000FEINGOLD      -0.8300    0.5577   -0.7844    0.6024    0.0546    0.0564    1.0000    0.6076    0.6076    1.0000
     102 1041570325 0WISCONS 10000KOHL          -0.6772    0.5656   -0.6449    0.7452    0.0395    0.1934    1.0000    0.5894    0.5894    1.0000
     103 1041471068 0WYOMING 20000SIMPSON        0.3605   -0.4309    0.5124   -0.4402    0.1725    0.1322    1.0000    0.4797    0.4797    1.0000
     104 1041563368 0WYOMING 20000THOMAS         0.7165    0.3480    0.7850    0.3535    0.0824    0.1281    1.0000    0.5629    0.5629    1.0000
    The legislator coordinates are are the first two columns after the name of the legislator (shown in red). For example, former President Clinton's coordinates are -0.9160 and -0.3336.

    1. Run 101 bootstrap trials using WNOMJLEWIS (change 011 to 101 in the NOMSTART_JLEWIS.DAT file and run the program). E-Mail me the NOM21.DAT file from the run.

    2. Use R to plot the legislators in two dimensions from the FORT.26 file. Use "D" for Non-Southern Democrats, "S" for Southern Democrats, "R" for Republicans, and "P" for President Clinton. This graph should be in the same format as the one you did for question 1.f of Homework 5.

    3. The sixth and seventh columns of numbers (shown in blue) are the bootstrapped standard errors for the first and second dimensions, respectively. The last four columns are the Pearson correlations between the bootstrapped first and second dimension coordinates computed across the bootstrap trials. Because we are only working with two dimensions just the correlation between the first and second dimension estimates is relevant (shown in Purple).

    4. We are going to make a graph like the ones shown in Figures 4.4 and 4.5 of my book. Download the following R program:

      Plot_Bootstrap_New.r -- R Program to Plot Parametric Bootstrap Output, FORT.26

      Here is what Plot_Bootstrap_New.r looks like:
      #
      #  Plot_Bootstrap_New.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(stats)
      library(ellipse)   You Will Need to Download and Install this Library
      #
      #  Set up to read Parametric Bootstrap File
      #
      rc.file <- "c:/ucsd_homework_7/fort.26"
      #
      # 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","r11","r12","r21","r22") 
      #
      #  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,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[,18]
      #
      nrow <- length(TT[,1])
      ncol <- length(TT[1,])
      #
      plot(TT[,11],TT[,12],type="n",asp=1,
             main="",
             xlab="",
             ylab="",
             xlim=c(-1.0,1.0),ylim=c(-1.0,1.0),font=2)
      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")
      # Main title
      mtext("104th Senate From W-NOMINATE\nWith Bootstrapped Standard Errors",side=3,line=1.50,cex=1.2,font=2)
      # x-axis title
      mtext("Liberal - Conservative",side=1,line=2.75,cex=1.2)
      # y-axis title
      mtext("Social/Lifestyle Issues",side=2,line=2.5,cex=1.2)
      #
      #
      #  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")
        }
      }
      #
      Run this program and turn in the plot. It should look similar to this:



    5. FORT.56 are the average Optimal Classification coordinates generated by running the Optimal Classification Program on every bootstrap draw. The file will look something like this:
      
         1 1049990999 0USA     10000CLINTON       -0.3160   -0.7979   -0.8467   -0.2906    0.5711    0.5775    0.1089    0.2070    1.0000   -0.8322   -0.8322    1.0000
         2 1041470541 0ALABAMA 10000HEFLIN        -0.2219    0.0278    0.0011   -0.2066    0.3139    0.3403    0.1975    0.2220    1.0000   -0.9512   -0.9512    1.0000
         3 1049465941 0ALABAMA 20000SHELBY         0.6878   -0.0150    0.7162   -0.1751    0.0633    0.1796    0.0529    0.0582    1.0000   -0.3841   -0.3841    1.0000
         4 1041490781 0ALASKA  20000MURKOWSKI      0.7285   -0.0996    0.7283   -0.0236    0.0781    0.0929    0.0741    0.0445    1.0000   -0.5790   -0.5790    1.0000
         5 1041210981 0ALASKA  20000STEVENS        0.6308   -0.1836    0.6209   -0.2080    0.0682    0.0844    0.0639    0.0763    1.0000   -0.4706   -0.4706    1.0000
                     etc   etc   etc
        98 1044930873 0WASHING 10000MURRAY        -0.8772   -0.0015   -0.9068   -0.1126    0.0506    0.1520    0.0378    0.0919    1.0000    0.0408    0.0408    1.0000
        99 104 136656 0WEST VI 10000BYRD, ROBER   -0.6919   -0.5972   -0.6128   -0.3697    0.0959    0.2762    0.0448    0.1300    1.0000   -0.7018   -0.7018    1.0000
       100 1041492256 0WEST VI 10000ROCKEFELLER   -0.7673   -0.0990   -0.7713   -0.1318    0.0585    0.0952    0.0554    0.0842    1.0000    0.2288    0.2288    1.0000
       101 1044930925 0WISCONS 10000FEINGOLD      -0.9161    0.3985   -0.8439    0.3498    0.0901    0.1056    0.0457    0.0875    1.0000    0.7287    0.7287    1.0000
       102 1041570325 0WISCONS 10000KOHL          -0.6915    0.2468   -0.7519    0.4653    0.1107    0.2343    0.0859    0.0404    1.0000   -0.2221   -0.2221    1.0000
       103 1041471068 0WYOMING 20000SIMPSON        0.5253   -0.1192    0.5113   -0.0559    0.0463    0.1029    0.0417    0.0743    1.0000   -0.3008   -0.3008    1.0000
       104 1041563368 0WYOMING 20000THOMAS         0.7193    0.1231    0.7215    0.1730    0.0458    0.1302    0.0434    0.1130    1.0000   -0.4295   -0.4295    1.0000
      The average legislator coordinates are are the third and fourth columns after the name of the legislator (shown in red). For example, former President Clinton's coordinates are -0.8467 and -0.2906.

      Use R to plot the legislators in two dimensions from the FORT.56 file. Use "D" for Non-Southern Democrats, "S" for Southern Democrats, "R" for Republicans, and "P" for President Clinton. This graph should be in the same format as the one you did for question 1.f of Homework 5.

    6. Write an Epsilon keyboard macro as a text file that combines the legislator coordinates from FORT.26 with those from FORT.56. Assume that the macro begins with FORT.26 in the top window, FORT.56 in the second window, and the combined file in the third window (see question 1.a of Homework 5). Leave the header on each record. Turn in a listing of the macro and a neatly formatted listing of the file.

    7. Let A be the matrix of legislator coordinates from FORT.26 after subtracting off the column means, and let B be the matrix of legislator coordinates from FORT.56 after subtracting off the column means. Note that subtracting off the column means of both matrices centers both at the origin, (0.0, 0.0). Solve for the orthogonal procrustes rotation matrix, T, for B. Namely, we want to minimize:

      L(T) = tr(A - BT)(A - BT)'

      The solution is:

      T = VU' where

      A'B = ULV'

      where ULV' is the Singular Value Decomposition of A'B (see Borg and Groenen, pp. 430-432).

      In R you can perform the decompostion with the svd command. For example:

      C <- t(A)%*%B
      svddecomp <- svd(C)


      svddecomp$u has the matrix U
      svddecomp$v has the matrix V
      svddecomp$d has the diagonal of L

      Note that you can check your work as we discussed in class by doing the following:

      D <- diag(svddecomp$d)
      U <- svddecomp$u
      V <- svddecomp$v
      ABCHECK <- U%*%D%*%t(V)
      errorcheck <- sum((C-ABCHECK)^2)


      Solve for T and turn in a neatly formatted listing. Compute the Pearson r-squares between the corresponding columns of A and B before and after rotating B.

  3. In this problem we are going to use the R version of W-NOMINATE that is in the wnominate package. Download the R program:

    wnominate_in_R.r -- R Program to run W-NOMINATE

    Here is what the program looks like:
    
    #
    #  wnominate_in_R.r
    #
    #  Program to Run R Version of W-NOMINATE
    #
    #
    #  Remove all objects just to be safe
    #
    rm(list=ls(all=TRUE))
    #
    library(pscl)
    library(wnominate)
    #
    #
    sen88 <- readKH("https://legacy.voteview.com/k7ftp/sen88kh.ord",
           dtl=NULL,
           yea=c(1,2,3),
           nay=c(4,5,6),
           missing=c(7,8,9),
           notInLegis=0,
           desc="88th U.S. Senate",
           debug=FALSE)
    #
    result <- wnominate(sen88, polarity=c(7,3))
    #
    write.table(result$legislators,"c:/ucsd_homework_7/wnomkeith_88x.txt")
    #
    1. Write an Epsilon macro that nicely formats the wnomkeith_88x.txt file and turn in a printout of the formatted file and the macro.

    2. Use R to plot the legislators in two dimensions from the wnomkeith_88x.txt file. Use "D" for Non-Southern Democrats, "S" for Southern Democrats, "R" for Republicans, and "P" for Presidents Kennedy and Johnson. This graph should be in the same format as the one you did for question 1.f of Homework 5.

  4. In this problem we are going to use Simon Jackman's Bayesian MCMC Quadratic-Normal scaling program IDEAL which is part of the pscl package in R (see above, be sure you have installed the latest version!).

    Download the R program below:

    idealKeith_2007.r -- Program to run IDEAL on the 104th Senate.

    idealKeith_2007.r looks like this:
    #
    #  idealKeith_2007.r -- Implements Simon's IDEAL in R
    #
    rm(list=ls(all=TRUE))
    #
    library(pscl)
    #
    s104 <- 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 U.S. Senate",
                     debug=FALSE)
    class(s104)
    csts <- constrain.legis(s104,x=list("KERRY (D MA)"=-1, "HELMS (R NC)"=1),d=1)
    kpideal <- ideal(s104, priors=csts, startvals=csts, store.item=TRUE)
    sumkpideal <- summary(kpideal,include.beta=TRUE)
    #
    write.table(sumkpideal$x,"c:/ucsd_homework_7/tab_simon_104x.txt")
    write.table(sumkpideal$bResults,"c:/ucsd_homework_7/tab_simon_104z.txt")
    #
    The tab_simon2_104x.txt file has the esimated legislator ideal points in a format similar to those from MCMCPack that you estimated for question 1 of Homework 6. The file should look something like this:



    1. Write a macro similar to the one you used in question 1.a. and 1.b. of Homework 6 to make a nicely formatted file of the legislator coordinates. Turn in a copy of this macro.

    2. Replicate question 1.c. of Homework 6. Write an R program that graphs the rank ordering from Optimal Classification (horizontal axis) against the IDEAL medians (vertical axis). Label the axes appropriately and label a few of the Senators including Campbell (D-CO) and Campbell (R-CO).

    3. Report the correlation between the OC rank ordering and the IDEAL medians.

    4. Use Epsilon to combine the file you created in (a) with that from question 1.a. and 1.b. of Homework 6 and include in that file the 2.5% and 97.5% quantiles corresponding to the medians of both procedures. Report the Pearson correlation between the lengths of the "confidence intervals" for the two Bayesian procedures and also report the Pearson correlation between the IDEAL medians and MCMCPack medians.