Modifications by: Alex Lancaster and Diogo Meyer
$Date$

Modified version of Montgomery Slatkin's "enumeration.c" and
"monte-carlo.c" code as found on 2002-08-16 at the following URL:

 http://ib.berkeley.edu/labs/slatkin/monty/Ewens_exact.program

To generate the executables for the Monte-Carlo program, simply type
"make" (this assumes that you are using GNU make and GCC).  This will
generate two executables:

 1. The regular Monte-Carlo program: "monte-carlo".

 2. The Monte-Carlo distribution output enabled version:
    "monte-carlo_distribution"

The unedited original README for these programs now follows:
---------------------------------------------------------------------------

This file contains the C code the performs the Ewens exact and homozygosity
tests as described in two papers in Genetical Research (1994, 64: 71-74) and
(1996, 68: 259-260).

There are two programs, the ENUMERATION and the MONTE CARLO.  ENUMERATION
provides exact results for relatively small data sets by enumerating
all possible configurations of the data for given value of n, the sample
size, and k, the number of allele.  MONTE CARLO performs a Monte Carlo simulation
to provide approximate results and works on samples of any size.
For a given data set, the results from MONTE CARLO should converge on those
from ENUMERATE as the number of replicates increases.

Both programs take the arguments from the command line as parameters.  On a
Unix machine, you just type the name of the program followed by the parameters.
On most PC C compilers, there is a window or some other way to enter command
line arguments.  You will have to check you manual to find out how to do it.

The input for the two programs is different.

For the ENUMERATE, the arguments are the elements of the configuration in
nonincreasing order.  You do not need to enter n and k.  If you enter
9 2 1 1 1 1 1 as parameters, ENUMERATE should respond

n = 16, k = 7, theta = 4.184877, F = 0.351563
(9,2,1,1,1,1,1):  P_E = 0.989348, P_H = 0.989348

where theta is the estimate of 4Nu using the method in Ewens' (1972) paper and
F is the computed homozygosity.  As it is written, the testing program will
not work for samples containing more than 170 copies or 40 allelic.  It could
be modified to accomodate larger n, primarily by using logarithms
of factorials to avoid overflow, but I doubt whether it would be worth the
trouble.  With such large samples, the program would never finish and
MONTE CARLO should be used instead.  See the comment at the beginning of
that program for its input format and use.

On a Sun, you may have problems unless you have a gcc compiler, which is what
I have used.

Montgomery Slatkin
September 29, 1997
