Appendix 4: The FIT Programs

(i) Introduction

Press et al. 1992 discusses the question of finding a mathematical model for a set of data points, in particular, an equation y = a+bx to describe a set {xi,yi}. Finding such an a and b by means of a least-squares fit is a technique well-known to physicists. Press et al. go further and discuss the case where the xi's are known exactly but "each yi has a measurement error that is independently random and distributed as a normal (Gaussian) distribution around the 'true' model y(x)." After several pages involving discussion of chi-square fitting (pp.657-666) Press provides C code for a function fit()1 which allows one to obtain not only a and b but also error estimates for these values.

Furthermore, assuming that the errors in the yi's are known, one may also obtain a chi-square value related to the probability of the yi's occurring if the model y = a+bx is true, and a value, denoted by Q, which is a "goodness-of-fit" estimate.

If Q is larger than, say, 0.1, then the goodness-of-fit is believable.  If it is larger than, say, 0.001, then the fit may be acceptable if the errors are nonnormal or have been moderately underestimated.  If Q is less than 0.001 then the model and/or estimation procedure can rightly be called into question.  (Press et al., 1992, p.664)

No Q-value is provided in the case that errors in the yi's are not known.

(ii) The FIT Program

The present author has used the fit() function from Press et al. as the basis for a program called FIT. This program has been used in several places in Chapters 5 and 6 to obtain error estimates, usually where errors in the yi's are known.

FIT.EXE is a console application which takes from one to three command line parameters. There is one required parameter, the name of a text file containing the data points. Each data point is defined by one data line in the file, which has the format:

x-value, y-value[, error-in-y-value]

The third value is optional, but for error estimates for a and b this must be present in all data lines of the input file.

For example, the following input data:

1, 1.13, 0.04
2, 2.05, 0.18
3, 3.15, 0.10
4, 4.15, 0.20

gives rise to the following FIT output:

4 data lines read.
Standard deviations present.
Data fitted to y(x) = a + bx.

a = 0.1222, siga = 0.0700
b = 1.0056, sigb = 0.0432
chi^2 = 0.2305, Q = 0.8911

from which we may conclude that y(0) = a = 0.12(7) and the slope b is 1.01(4).

There are two optional command line parameters:

(a) It is possible to set the number of decimal places in the output to n by including /d=n on the command line.

(b) If /data is included on the command line then the data lines will be output to the screen as they are read from the file.

Comments may be included in the input file if they begin with //. A line in the input file is regarded as a data line if it contains a comma but does not begin with //.

(iii) The 4STPFIT Program

This program was written to do a least-squares fit (using the fit() function described above) to the log-log values of the magnetization, autocorrelation and 2nd moment of the magnetization against time, specifically timepoints 30 - 100, the data having been obtained from the use of the simulation program.

For example, consider the data in Table 6.4.1 in Appendix 5 (the magnetization is plotted in Figure 6.4.1). This is contained in the file BT.OUT on the accompanying disk. Running the 4STPFIT program (with the single command line paramter BT.OUT) gives the following output:

File: BT.OUT
Lattice size: 64
Initial magnetization: 0.020
Fitting over timepoints 30 through 100.

Magnetization
a = -4.1058, siga = 0.0157
b = -0.0490, sigb = 0.0039
chi^2 = 2.5558, Q = 1.0000

Autocorrelation
a = -1.3357, siga = 0.0043
b = -0.9307, sigb = 0.0011
chi^2 = 45.3051, Q = 0.9878

2nd moment of the magnetization
a = -8.8994, siga = 0.0029
b = +0.7030, sigb = 0.0007
chi^2 = 0.0003

A Q-value is not available for the 2nd moment of the magnetization because the standard deviation for this data was not measured.

As a second example, consider the data in Table 6.4.2 in Appendix 5 (the autocorrelaton is plotted in Figure 6.4.2). This is contained in the file DB.OUT on the accompanying disk. Running the 4STPFIT program gives the following output:

File: DB.OUT
Lattice size: 32
Initial magnetization: 0.000
Fitting over timepoints 30 through 100.

Magnetization
a = -4.0481, siga = 0.0021
b = +0.3627, sigb = 0.0005
chi^2 = 14.3136, Q = 1.0000

Autocorrelation
a = -1.2223, siga = 0.0067
b = -0.9705, sigb = 0.0017
chi^2 = 37.9657, Q = 0.9991

2nd moment of the magnetization
a = -7.6281, siga = 0.0022
b = +0.7244, sigb = 0.0005
chi^2 = 0.0002

 Title page Contents Next: Appendix 5