Alan Miller's Fortran Software repository (original) (raw)

[Subset Selection | Random Number Generation | Quad Precision | Applied Statistics Algorithms | Logistic Regression |TOMS Algorithms | Naval Surface Warfare Center Code | Miscellaneous | 10-Byte Reals for NAS FortranPlus | F code | Linear Least Squares | Links ]

N.B. Most of this software is compatible with Lahey's ELF90 compiler, and hence should be compatible with any full Fortran 90 or 95 compiler.


Subset Selection in Regression

The 2nd edition of my book on this subject was published by CRC Press (Chapman & Hall) in April 2002 (ISBN 1-58488-171-2). Dr. David Smith from the Medical College of Georgia, USA, has notified me of certain missing references. Here they are in postscript and pdf formats.

lsq.f90 is the latest version of my uncontrained weighted least-squares module. It is an upgraded version of Applied Statistics algorithm AS 274. It uses planar rotations to produce an upper-triangular factorization. The routine INCLUD is called once for each case in the data set. It is suitable for situations in which the least-squares calculations have to be updated each time more observations become available. It has routines for automatically setting up tolerances and testing for singularities. It uses a version of rank-revealing QR decomposition for this. This code is now compatible with ELF90.

If results for a subset of predictor variables are required, those variables are moved to the first positions, and variables to be excluded are ordered after them. Routine VMOVE moves one variable; routine REORDR re-orders the variables so that those listed are in the first positions, though not necessarily in the order specified.

For further details on how to use the module and on methods of least-squares calculation refer to the document

There is a DEMO program which uses a simple data set fuelcons.dat, and a nasty test program test1.f90.
If you want to see more tests then download the zip file tests.zip and the set of data files used by these tests in testdata.

For subset selection using the L1-norm, that is minimizing the sum of absolute residuals, here is toms615.f90 which is a translation of TOMS algorithm 615 to make it ELF90 compatible. There is also a driver program test615.f90, some test data test615.dat, and the expected output test615.out.

For linear regression, but when the regression coefficients must be positive or zero, there is the Lawson & Hanson non-negative least-squares routine nnls.f90 N.B. Two call arguments have been removed from the Fortran 77 version. This routine is ELF90-compatible.
I have also added my own nonnegls.f90 routine which is called after a QR-factorization has been formed using module LSQ. The file t_nnls.f90 uses both of these routines.


Random Numbers

For code for random number generation from the uniform distribution, and others, including normal, exponential, Poisson, binomial, gamma and others,Click here


Quadruple precision

For code for quadruple precision arithmetic, using pairs of double precision numbers,Click here


Some Applied Statistics Algorithms

For many years, the Royal Statistical Society published algorithms in its journal `Applied Statistics'. I have translated a few of these to F90,Click here


Logistic Regression


I have received several requests for Fortran code to perform logistic regression, that is to fit:

p = F/(1 + F)
where
p = the probability that a case is in one of two categories
F = exp(b0 + b1.X1 + b2.X2 + ... + bk.Xk)
X1, X2, ..., Xk is a set of k predictors, and
b0, b1, b2, ..., bk is a set of coefficients to be fitted.


Miscellaneous TOMS (and CACM) algorithms

N.B. I have been asked to provide a link to the copyright policy of the ACM. Loosely paraphrased, this allows use, and modification, of the TOMS algorithms for most non-commercial purposes. It also emphasizes that the ACM accepts no responsibility for the accuracy of the code.


I have updated some of the Transactions on Mathematical Software (TOMS) algorithms to Fortran 90.Click here


Code converted from the



Miscellaneous code



NAS FortranPlus

Software for NAS FortranPlus This exploits the 10-byte REAL data type which is supported by this compiler. At the moment, it only contains a special version of my quadruple precision package which gives about 38 decimal digit representation of quadruple precision numbers. N.B. It is extremely unlikely that this will give correct answers with any other compiler (e.g. Salford) which supports 10-byte REALs.


Code for Imagine1's free F compiler

Windows version ONLY

Click here


Some linear least-squares examples and tests


fit_poly.f90 Fit a polynomial to a set of (x,y) data.

quadsurf.f90 Fit a quadratic surface to a set of (x,y,z) data, i.e. fit:
Z = b0 + b10.X + b01.Y + b20.X^2 + b11.X.Y + b02.Y^2
There is a module ridge.f90 for ridge regression / regularization. It uses the output from the module lsq to form the singular value decomposition (SVD) and offers a choice of 4 different methods of regularization, or the user can input their own vector to add to the diagonal of the X'X-matrix.

wtd_quin.f90 This is a program to fit a quintic polynomial with exponential weighting of past values. It was developed for someone who had reason to believe that his process was well approximated locally by a quintic, but wanted to give progressively less weight to old observations. The slope and 2nd derivative (acceleration) of the smoothing polynomial are output after each new case is read. This is suitable for real time applications. It demonstrates the use of the least-squares package's updating algorithm.

spline5.f90 This program fits quintic splines with user-chosen but evenly-spaced knots. The slope and 2nd derivative (acceleration) of the smoothing polynomial are output, but only after all of the data have been read. The smoothed fit and derivatives at any point are based upon the data from both before and after the point.


Some other useful web sites: