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: UCSD 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
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.
- 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
How to Install GCC for MAC OS 10.5
C Standard Library Description in Wikipedia
LAPACK (Linear Algebra PACKage) Description in Wikipedia
BLAS (Basic Linear Algebra
Subprograms) Description in Wikipedia
BLAS Netlib Home Page
dgemm.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.
C Programs, Day 1 J&A
C Programs, Day 2 J&A
C Programs, Day 3 J&A
C Programs, Day 4 J&A
C Programs, Day 5 J&A
C Programs, Day 6 J&A
C Programs, Day 7 J&A
C Programs, Day 8 J&A
C Programs, Day 9 J&A
C Programs, Day 10 J&A
C Programs, Day 11 J&A
C Programs, Day 12 J&A
C Programs, Day 13 J&A
C Programs, Day 14 J&A
C Programs, Day 15 J&A
C Programs, Day 16 J&A
C Programs, Day 17 J&A
C Programs, Day 18 J&A
C Programs, Day 19 J&A
C Programs, Day 20 J&A
C Programs, Day 21 J&A
C Programs, Type and Run, J&A
R
Outline of Topics
- Origins and Basic Structure of the C Programming Language
Suggested Readings
Introductory Programs (Courtesy of James Lo and Keith Poole):
- Reading Data Matrices in C With Comparisons to R
Suggested Readings
Introductory Programs (Courtesy of James Lo and Keith Poole):
- Working With Pointers, Vectors, Matrices, and Strings
Suggested Readings
- 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)
- 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.r --
R program that uses
coda package to produce history graphs of the
chains and computes the Gelman-Rubin statistic for convergence of multiple chains. Reads
the output files from multiple runs (renamed data_arms_chaints.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
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)