# Combinatorics Module

scott chasalow (Scott.Chasalow@USERS.PV.WAU.NL)
Mon, 26 Jan 1998 19:19:39 +0100 (CET)

I have assembled a small group of S-PLUS functions to generate or count
various types of combinatoric objects. For example, to generate all
combinations, all permutations, all points on a simplex lattice, or all
points on a hypercuboid lattice.

A Windows zip archive of these functions is now available at:

A gzipped tar archive is available at

All the functions are native S-PLUS. Thus, some of them might be a bit slow
if you want to generate a very large set of combinatoric objects. On the
other hand, no compilation is necessary.

Below you will find a brief description of each function.

Cheers,
Scott

-----------------------------------------------------------------------------
-

********************************
S-PLUS Combinatorics Version 0.1
********************************

----------------------------------------------------------------------------
Functions written by Scott D. Chasalow, with special thanks to John Wallace
(rmultinomial code) and Alan Zaslavsky (rmultz2 code).

-----------------------------------------------------------------------------

FUNCTION BRIEF DESCRIPTION

combn Generates all combinations of n things taken m at a time.

combn2 Generates all combinations of n things taken 2 at a time.

dmnom Multinomial density function.

fact Factorial function.

hcube Generates all points on a hypercuboid lattice.

logfact Log-factorial function, i.e. logfact(x) == log(fact(x)).

nCm Number of combinations of n things taken m at a time.
More generally, binomial coefficient, for any integer m
and
any real number n. Accepts vector arguments.

nsimplex Number of points on a {p, n}-simplex lattice; that is, the
number of points in a p-part composition of n.

permn Generates all permutations of a vector, in a minimal-change
order.

rmultinomial Generates random samples from a multinomial(n, p) distn:
varying n, varying p case. Adapted from function by John
Wallace.

rmultz2 Generate random samples from a multinomial(n, p) distn:
varying n, fixed p case. Adapted from function by Alan
Zaslavsky. More efficient than rmultinomial for this
special case.

x2u Converts an x-encoded simplex-lattice point to a u-encoded
simplex-lattice point.

xsimplex Generates simplex-lattice points (p-part compositions of n).
Fast, robust, non-recursive algorithm. Translation
of C function in Chasalow and Brand, Applied Statistics
(1995).
-----------------------------------------------------------------------------
-

*==================================*
Scott.Chasalow@users.pv.wau.nl

Wageningen Agricultural University
Department of Plant Breeding
P.O. Box 386
6700 AJ Wageningen
THE NETHERLANDS
*==================================*