(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 2^{nd}Friday

Instructor:

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)*

MINGW -- Minimalist GNU for Windows

In addition to the instructions below, in order to install the GCC compiler on Macs, there is an additional step that you will need to do to get Fink Commander to install GCC properly. You will need to download the Xcode developer tools as well. To do this, do the following.

C Standard Library Description in Wikipedia

LAPACK (Linear Algebra PACKage) Description in Wikipedia

In addition to the instructions below, in order to install the GCC compiler on Macs, there is an additional step that you will need to do to get Fink Commander to install GCC properly. You will need to download the Xcode developer tools as well. To do this, do the following.

- Go to , the Apple Developer tool website. Click on Â“Not a MemberÂ”, and register yourself with Apple.
- After you have registered, log in to the same site under the username you just created.
- Now download Xcode 3.1.3

C Standard Library Description in Wikipedia

LAPACK (Linear Algebra PACKage) Description in Wikipedia

LAPACK Netlib Home Page

BLAS (Basic Linear Algebra Subprograms) Description in WikipediaListing of the Key LAPACK Subroutines

Lapack.h file used by RComputes eigenvalues and eigenvectors of a real symmetric matrix. Very useful for Many Empirical Applications.

Matrix Inversion Routine.

Computes the singular value decomposition (SVD) of a general rectangular matrix. Used in a host of important empirical applications.

Matrix Inversion Routine.

Computes the singular value decomposition (SVD) of a general rectangular matrix. Used in a host of important empirical applications.

BLAS Netlib Home Page

C Programs From Jones and Aitkendgemm.f -- Used in OLS.C -- Computes the matrix operation: alpha*(A_transpose*B) + beta*C,
where A, B, and C are matrices and alpha and beta are scalers. Note that if A=B, alpha=1,
and beta=0, then this routine returns A_transpose*A.

dgesv.f -- LAPACK Routine Used in OLS.C -- Solves the linear equation problem of A * X = B. Note that if B is set equal to the identity matrix, then the routine returns A_inverse.

dgesv.f -- LAPACK Routine Used in OLS.C -- Solves the linear equation problem of A * X = B. Note that if B is set equal to the identity matrix, then the routine returns A_inverse.

The Comprehensive R Archive Network (CRAN) (Download **R** from this Site)

Rtools for Development of Stat Packages for R (Download**Rtools** from this Site)

An Introduction to R. (**R-intro.pdf** -- Reference Work by **R** Development Core Team)

*Using ***R** for Data Analysis and Graphics: An Introduction. (**usingR.pdf** -- Reference Work by J. H. Maindonald on R Graphics)

Rtools for Development of Stat Packages for R (Download

An Introduction to R. (

**Origins and Basic Structure of the C Programming Language****Suggested Readings***Teach Yourself C*, pp. 1 - 90*The C Programming Language*, pp. 1 - 66

Handout for Topic 1 (Updated, 25 August 2009)

KPCourse.ppt (PowerPoint presentation written by James Lo -- Illustrates some basic facts about C)

**Introductory Programs (Courtesy of James Lo and Keith Poole):**Hello.c

fahrenheit.c

fahrenheit_real.c

Vector.c

random_test.cuniform_histogram.r (R program to plot pseudo-random uniform numbers from C program)Array.c

function_example_10000.txt (data read by R program)

Pointer_simple.c

Pointer_declaring.c

Control.c

Day_One_Aug_17_2009.mp3 (MP3 file for first two hours -- 163meg)

Day_Two_Aug_19_2009.mp3 (MP3 file for second two hours -- 160meg)**Reading Data Matrices in C With Comparisons to R****Suggested Readings***Teach Yourself C*, pp. 97 - 217, 337 - 376, 439 - 474*The C Programming Language*, pp. 67 - 126, 151 - 168

Handout for Topic 2 (Part 1)

Handout for Topic 2 (Part 2)

Handout for Topic 2 (Part 3)

Handout for Topic 2 (Part 4)

Handout for Topic 2 (Part 5)

**Introductory Programs (Courtesy of James Lo and Keith Poole):**Pointer_temperature.c

Function_example.c

writedata.c -- Produces**Data.txt**which is read in by**readdata.c**and**Data2.txt**which is read in by**readdata_matrix.c**

readdata.c -- Reads**Data.txt**

readdata_eof.c -- Reads**Data.txt**and illustrates how to use the end of file command and break

readdata_matrix.c -- Reads**Data2.txt**

ols.c -- Illustrates the use of the LAPACK and BLAS matrix/vector libraries.

writedata_ols.c Writes Out Matrix for ols_read.c

ols_read.c General OLS program

ols_read_svd.c General OLS program -- does a Singular Value Decomposition on the Input X matrix to check for colinearity

binary.c binary.c (**Courtesy of Chris Fariss**)

Documentation of Binary.c

writedata_ols_erf.c Writes Out Matrix with Normal Error for for ols_read_svd.c. Also writes data_normal.txt.normal_histogram.r (R program to plot pseudo-random normal distribution numbers from C program)ols_read_svd_general.c General OLS program that computes standard Regression Statistics -- it also does a Singular Value Decomposition on the Input X matrix to check for colinearity (updated, 30 August 2009)

data_normal.txt (data read by R program)

ols_read_svd_general_bush.c General OLS program set up for the Bush 2000 Election data

ols_read_svd_general_gore.c General OLS program set up for the Gore 2000 Election databush2000.txt Bush 2000 election data -- 432 Congressional Districts with 8 variables

gore2000.txt Gore 2000 election data -- 432 Congressional Districts with 8 variables

106_House_Example.log STATA log file for Bush and Gore Regressions

Day_Three_Aug_21_2009.mp3 (MP3 file for third two hours -- 164meg)

Day_Four_Aug_24_2009.mp3 (MP3 file for fourth two hours -- 171meg)

Day_Five_Aug_26_2009.mp3 (MP3 file for fifth two hours -- 174meg)

Day_Six_Aug_28_2009_001.mp3 (MP3 file for sixth two hours (Part 1) -- 16meg)

Day_Six_Aug_28_2009_002.mp3 (MP3 file for sixth two hours (Part 2) -- 129meg)**Working With Pointers, Vectors, Matrices, and Strings****Suggested Readings***Teach Yourself C*, pp. 217 - 246

Handout for Topics 3 and 4 (Part 1)**Introductory Programs:**

sort_integer.c -- Simple integer sort using the built-in function qsort.

sort_integer_2.c -- Simple integer sort using the built-in function qsort (simplified).

sort_double.c -- Simple double sort using the built-in function qsort.

Day_Seven_Aug_31_2009.mp3 (MP3 file for seventh two hours -- 136meg)

**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)**.sen110_names.txt File read by read_sen110.c.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)**.sen110_names_coord.txt File read by read_sen110_2.c.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)

**Writing Research Programs**Handout for Topic 5 (Part 1)Day_Ten_Sept_25_2009.mp3 (MP3 file for tenth two hours -- 128meg)

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 J_{0}.

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**.h106_example_2.raw.dat File With Dichotomous Dependent Variable and 7 Independent Variables read by the Probit and Logit Programs above.junk_probit_2.c -- Preliminary test of Ordered Probit (Cut Points Fixed!!)

Logit Probability Derivation (PDF)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 variablejunk_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.optimization_machine_king.c -- Analyzes King's English Votes and Seat Share Data for England

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**king_data_2.txt -- King's Votes and Seat Share Data for Englandarms_test.c -- Program by Wally Gilks that does-- Simple setup to sample from a Normal Distribution**Adaptive Rejection Metropolis Sampling**

arms_test_ols.c -- Program by Wally Gilks that does-- Reads**Adaptive Rejection Metropolis Sampling****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 --arms_test_king.c -- Program by Wally Gilks that does**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**filesdata_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**-- Reads**Adaptive Rejection Metropolis Sampling****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 --arms_test_probit.c -- Program by Wally Gilks that does**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**filesdata_arms_chains_King_Bayes_1.txt -- 10,000 draws from 3-dimensional parameter space (two bias parameters and a responsiveness parameter) from**arms_test_king.c**

data_arms_chains_King_Bayes_2.txt -- 10,000 draws from 3-dimensional parameter space (two bias parameters and a responsiveness parameter) from**arms_test_king.c**

data_arms_chains_King_Bayes_3.txt -- 10,000 draws from 3-dimensional parameter space (two bias parameters and a responsiveness parameter) from**arms_test_king.c**-- Reads**Adaptive Rejection Metropolis Sampling****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 --arms_test_logit.c -- Program by Wally Gilks that does**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**filesdata_arms_chains_probit_1.txt -- 10,000 draws from 8-dimensional parameter space (eight betas) from**arms_test_probit.c**

data_arms_chains_probit_2.txt -- 10,000 draws from 8-dimensional parameter space (eight betas) from**arms_test_probit.c**

data_arms_chains_probit_3.txt -- 10,000 draws from 8-dimensional parameter space (eight betas) from**arms_test_probit.c**-- Reads**Adaptive Rejection Metropolis Sampling****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**filesdata_arms_chains_logit_1.txt -- 10,000 draws from 8-dimensional parameter space (eight betas) from**arms_test_probit.c**

data_arms_chains_logit_2.txt -- 10,000 draws from 8-dimensional parameter space (eight betas) from**arms_test_probit.c**

data_arms_chains_logit_3.txt -- 10,000 draws from 8-dimensional parameter space (eight betas) from**arms_test_probit.c**

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)- 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.

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)

Recent Working Papers

Analyses of Recent Politics

About This Website

K7MOA Log Books: 1960 - 2015

Bio of Keith T. Poole

Related Links