POLI 279: C by the Beach




August 17 to September 18
(Optional) Fall Quarter, AY 2009-10
Department of Political Science
University of California, San Diego
La Jolla, CA 92093-0521

  • August 17 to September 18
    Classroom: SSB 104
    Time: 12:00 - 2:00PM MWF
  • Fall Quarter
    Classroom: SSB 104
    Time: 4:00 - 6:00PM Every 2nd Friday

Instructor: Keith T. Poole

Office: SSB 368
E-Mail: kpoole@ucsd.edu
WebSite: Voteview Home Page


Recommended Reference Texts:
  • Jones, Bradley L. and Peter Aitken (2003). Sams Teach Yourself C in 21 Days
  • Kernighan, Brian W. and Dennis M. Ritchie (1988). The C Programming Language (2nd Edition)


C


R


Outline of Topics
  1. Origins and Basic Structure of the C Programming Language

    Suggested Readings

    Introductory Programs (Courtesy of James Lo and Keith Poole):

  2. Reading Data Matrices in C With Comparisons to R

    Suggested Readings

    Introductory Programs (Courtesy of James Lo and Keith Poole):

  3. Working With Pointers, Vectors, Matrices, and Strings

    Suggested Readings

  4. Working With Data Structures

    Suggested Readings

    • Teach Yourself C, pp. 249 - 304
    • The C Programming Language, pp. 127 - 150

      Handout for Topics 3 and 4 (Part 2)
      Handout for Topics 3 and 4 (Part 3)

      Introductory Programs:

      sort_structure_1.c -- Simple structure sort using the built-in function qsort.
      sort_structure_2.c -- Simple structure sort using the built-in function qsort (alternative code).
      read_sen110.c -- Program that reads records of file as strings and then converts them to integers, reals, and character strings. We will use it for more advanced sorting (courtesy of Jeff Lewis).
      read_sen110_2.c -- Program that reads records of file as strings and then converts them to integers, reals, and character strings. We will use it for more advanced sorting (courtesy of Jeff Lewis and Keith Poole).
      read_dwnom.c -- Program that reads records of DW-NOMINATE legislator file as strings and then converts them to integers, reals, and character strings. We will use it for more advanced sorting (courtesy of Jeff Lewis and Keith Poole).
        hl01111b21.dat DW-NOMINATE legislator Coordinate File read by read_dwnom.c.

      Day_Eight_Sept_9_2009.mp3 (MP3 file for eighth two hours -- 156meg)
      Day_Nine_Sept_11_2009.mp3 (MP3 file for ninth two hours -- 148meg)

  5. Writing Research Programs

      Handout for Topic 5 (Part 1)
      Handout for Topic 5 (Part 2)
      Handout for Topic 5 (Part 3)
      Handout for Topic 5 (Part 4)
      Handout for Topic 5 (Part 5)

      Introductory Programs:

      read_dwnom_2.c -- Program that reads records of DW-NOMINATE legislator file as strings and then converts them to integers, reals, and character strings. This version features some nested sorting (courtesy of Jeff Lewis and Keith Poole).
      read_dwnom_3.c -- Program that reads records of DW-NOMINATE legislator file as strings and then converts them to integers, reals, and character strings. This version features some nested sorting (courtesy of Jeff Lewis and Keith Poole).
      read_dwnom_3A.c -- Same as above only slightly different code that produces a Compiler warning.
        hl01111b21.dat DW-NOMINATE legislator Coordinate File read by read_dwnom.c programs above.

      xamoeba_double.c -- Program that implements the Nelder-Mead method of minimizing an objective function in a multidimensional space. Solves Bessel Function of type J0.
      xamoeba_general_a.c -- Program that implements the Nelder-Mead method of minimizing an objective function in a multidimensional space. This version set up to solve OLS problem. Program reads data_ols.txt -- 1000 by 25 X matrix and Y vector -- created by writedata_ols_erf.c.
      xamoeba_test.c -- Program that implements the Nelder-Mead method of minimizing an objective function in a multidimensional space. This version set up to solve OLS problem. Program reads data_ols.txt -- 1000 by 25 X matrix and Y vector -- created by writedata_ols_erf.c. This is a simpler implementation than xamoeba_general.c.
      xamoeba_general_bush.c -- Amoeba program that implements the Nelder-Mead minimization method set up to solve an OLS problem. Reads Bush2000.txt.
      xamoeba_general_gore.c -- Amoeba program that implements the Nelder-Mead minimization method set up to solve an OLS problem. Reads Gore2000.txt.

      xamoeba_test_bush_probit.c -- Amoeba program that implements the Nelder-Mead minimization method set up to solve a PROBIT problem. Reads Bush2000.txt and sets the dependent variable = 1 if the Bush vote is >= 50%.
      xamoeba_test_gore_probit.c -- Amoeba program that implements the Nelder-Mead minimization method set up to solve a PROBIT problem. Reads Gore2000.txt and sets the dependent variable =1 if the Gore vote is >= 50%.

      xpowell_test.c -- Program that uses Powell's Quadratically Convergent Method of minimizing an objective function in a multidimensional space. This version set up to solve OLS problem. Program reads data_ols.txt -- 1000 by 25 X matrix and Y vector -- created by writedata_ols_erf.c.
      xpowell_test_bush.c -- Program that uses Powell's Quadratically Convergent Method of minimizing an objective function in a multidimensional space. This version set up to solve OLS problem. Reads Bush2000.txt.
      xpowell_test_gore.c -- Program that uses Powell's Quadratically Convergent Method of minimizing an objective function in a multidimensional space. This version set up to solve OLS problem. Reads Gore2000.txt.

      xamoeba_xpowell_probit.c -- Program that uses both Amoeba and Powell's Quadratically Convergent Method of minimizing an objective function in a multidimensional space. It also finds best solution using both algorithms and computes numerical first and second derivatives. This version set up to solve Probit problem. Reads Bush2000.txt.

      optimization_machine_probit_bush106.c -- Program that uses both Amoeba and Powell's Quadratically Convergent Method of minimizing an objective function in a multidimensional space. It also finds best solution using both algorithms and computes numerical first and second derivatives. It also calculates t-statistics and p-values for the estimated parameters. This version set up to solve Probit problem. Reads h106_example_2.raw.
      optimization_machine_logit_bush106.c -- Program that uses both Amoeba and Powell's Quadratically Convergent Method of minimizing an objective function in a multidimensional space. It also finds best solution using both algorithms and computes numerical first and second derivatives. It also calculates t-statistics and p-values for the estimated parameters. This version set up to solve Logit problem. Reads h106_example_2.raw.
      junk_probit_2.c -- Preliminary test of Ordered Probit (Cut Points Fixed!!)
        1968nesparty.txt -- 1968 NES Party ID and Demographic Variables. Party ID is 0,1,2,3,4,5,6 and is used as the dependent variable

      junk_oprobit_test_2.c -- Uses Indicator Variables to Pick up Cut Points (Not final solution to the problem!)
        oprobit_big_3.srt -- 1968 NES Party ID and Demographic Variables. Data is stacked to create dichotomous dependent variable with indicators to pick up the cut points.

      optimization_machine_MDS.c -- Does classical Metric Multidimensional Scaling (Illustrated with famous Color Circle Data)
        color_circle_2.txt -- Similarities Data from Ekman (1954) color experiments.
        color_circle.r -- R program to plot estimate points from optimization_machine_MDS.c.
          data_optim_3.txt -- Subset of output from optimization_machine_MDS.c -- all the solutions as rows that are contained in output file data_optim_2.txt

      optimization_machine_king.c -- Analyzes King's English Votes and Seat Share Data for England
      arms_test.c -- Program by Wally Gilks that does Adaptive Rejection Metropolis Sampling -- Simple setup to sample from a Normal Distribution
        arms_output_normal.r -- R program to plot sample drawn from Normal Distribution by arms_test.c.
          arms.out01 -- 100,000 draws from Normal Distribution from arms_test.c

      arms_test_ols.c -- Program by Wally Gilks that does Adaptive Rejection Metropolis Sampling -- Reads data_ols.txt and does arms on the 25 Betas and writes the chains to disk in the file data_arms_chains.txt
        arms_ols_chains_3.r -- R program that uses coda package to produce history graphs of the three sets of chains and computes the Gelman-Rubin statistic for convergence of multiple chains. Reads the output files from multiple runs (renamed data_arms_chains.txt files
          data_arms_chains_1.txt -- 10,000 draws from 25-dimensional parameter space (25 Betas of Regression) from arms_test_ols.c
          data_arms_chains_2.txt -- 10,000 draws from 25-dimensional parameter space (25 Betas of Regression) from arms_test_ols.c
          data_arms_chains_3.txt -- 10,000 draws from 25-dimensional parameter space (25 Betas of Regression) from arms_test_ols.c

      arms_test_king.c -- Program by Wally Gilks that does Adaptive Rejection Metropolis Sampling -- Reads king_data_2.txt and does arms on the 2 Bias Parameters and the Responsiveness parameter and writes the chains to disk in the file data_arms_chains_king.txt. Note that I have placed priors in the keithrules() plug-in routine so this is a true Bayesian Posterior. I used an Exponential Prior for the Responsiveness Parameter and Normal vague priors for the two bias parameters.
        arms_king_chains_3.r -- R program that uses coda package to produce history graphs of the three sets of chains and computes the Gelman-Rubin statistic for convergence of multiple chains. Reads the output files from multiple runs (renamed data_arms_chains_king_Bayes_*.txt files
      arms_test_probit.c -- Program by Wally Gilks that does Adaptive Rejection Metropolis Sampling -- Reads h106_example_2.raw and does probit on the 7 congressional district level variables for the 2000 election. The dependent variable = 1 if Bush won the district. Note that I have placed priors in the keithrules() plug-in routine so this is a true Bayesian Posterior. I used Normal vague priors for the eight beta coefficients in the probit (intercept term plus the seven variables).
        arms_probit_chains_3.r -- R program that uses coda package to produce history graphs of the three sets of chains and computes the Gelman-Rubin statistic for convergence of multiple chains. Reads the output files from multiple runs (renamed data_arms_chains_probit_*.txt files
      arms_test_logit.c -- Program by Wally Gilks that does Adaptive Rejection Metropolis Sampling -- Reads h106_example_2.raw and does logit on the 7 congressional district level variables for the 2000 election. The dependent variable = 1 if Bush won the district. Note that I have placed priors in the keithrules() plug-in routine so this is a true Bayesian Posterior. I used Normal vague priors for the eight beta coefficients in the probit (intercept term plus the seven variables).
        arms_logit_chains_3.r -- R program that uses coda package to produce history graphs of the three sets of chains and computes the Gelman-Rubin statistic for convergence of multiple chains. Reads the output files from multiple runs (renamed data_arms_chains_logit_*.txt files
    Day_Ten_Sept_25_2009.mp3 (MP3 file for tenth two hours -- 128meg)
    Day_Eleven_Oct_9_2009.mp3 (MP3 file for eleventh two hours -- 136meg)
    Day_Twelve_Oct_23_2009.mp3 (MP3 file for twelfth two hours -- 111meg)
    Day_Thirteen_Dec_4_2009.mp3 (MP3 file for thirteenth two hours -- 108meg)


  6. Additional Research Programs (updated 25 April 2012)

    normaltable.c -- Program that computes normal distribution look-up table from -5.0 to +5.0 in steps of 0.0001. Table is written out in normaltable.dat. The table has 5 columns, a counter, the axis value, F(x), ln(F(x)), and f(x)/F(x) (the inverse of the Mills Ratio).

    qrmethod_2.c -- Program that performs QR Decomposition using the LAPACK and BLAS packages -- Reads experiment_qr_3.txt and does QR Decomposition.



Site Links

VOTEVIEW Blog
NOMINATE Data, Roll Call Data, and Software
Course Web Pages: University of Georgia (2010 - )
Course Web Pages: UC San Diego (2004 - 2010)
University of San Diego Law School (2005)
Course Web Pages: University of Houston (2000 - 2005)
Course Web Pages: Carnegie-Mellon University (1997 - 2000)
Analyzing Spatial Models of Choice and Judgment with R
Spatial Models of Parliamentary Voting
Recent Working Papers
Analyses of Recent Politics
About This Website
K7MOA Log Books: 1960 - 2017
Bio of Keith T. Poole
Related Links