[MAP Logo]

Materials Algorithms Project
Program Library



Subroutine MAP_UTIL_ANALY

  1. Provenance of code.
  2. Purpose of code.
  3. Specification.
  4. Description of subroutine's operation.
  5. References.
  6. Parameter descriptions.
  7. Error indicators.
  8. Accuracy estimate.
  9. Any additional information.
  10. Example of code
  11. Auxiliary subroutines required.
  12. Keywords.
  13. Download source code.
  14. Links.

Provenance of Source Code

H.K.D.H. Bhadeshia,
Phase Transformations Group,
Department of Materials Science and Metallurgy,
University of Cambridge,
Cambridge, U.K.

Top | Next

Purpose

MAP_UTIL_ANALY is a linear regression subroutine which determines the intercept and gradient of the best fit line between two variables, together with the correlation coefficient.

Top | Next | Prev

Specification

Language:FORTRAN
Product form:Source code

SUBROUTINE MAP_UTIL_ANALY(J8,J9,CONST,SLOPE,CORR,X,Y)

DOUBLE PRECISION CONST,SLOPE,CORR,X(100),Y(100)

INTEGER J8,J9

Top | Next | Prev

Description

The best fit line for a set containing N(x,y) pairs of data is found by minimising the root mean square error, for the equation:

y = mx + c

where m=SLOPE and c=CONST.

m = {{N sum xy - sum x sum y}/{N sum x2 - sum x sum x}}

c = {{sum y sum x2 - sum x sum xy}/{(N sum x2 - sum x sum x)}}

The correlation coefficient R is given by:

R = {{N sum xy - sum x sum y}/{(N sum x2 - sum x sum x){0.5} (N sum y2 - sum y sum y){0.5}}}

Top | Next | Prev

References

None supplied.

Top | Next | Prev

Parameters

Input parameters

J8 - integer
J8 is the number of x,y pairs, with J8 <= 100.

J9 - integer
The number of x,y pairs not included in the analysis. Only the first J8 - J9 pairs are included in the regression.

X - real array
X has a dimension of 100, and contains values of the independent variable on the x-axis.

Y - real array
Y has dimension 100, and contains values of the dependent variable on the y-axis.

Output parameters

CONST - real
CONST is the intercept on the y-axis of the best-fit line.

SLOPE - real
SLOPE is the gradient of the best-fit line.

CORR - real
CORR is the correlation coefficient.

Top | Next | Prev

Error Indicators

The number of x,y pairs cannot exceed 100, the dimension of the arrays X and Y.

Top | Next | Prev

Accuracy

No informatin supplied.

Top | Next | Prev

Further Comments

Uses same method as NAG Library routine G02CAF

G02CAF(N, X, Y, RESULT, IFAIL)

where N is the number of (x,y) pairs, and RESULT is an array of dimension 20 containing details of the mean and standard deviation, and standard error, as well as CONST, SLOPE, and CORR.

Top | Next | Prev

Example

To calculate the best fit line.

1. Program text

       DOUBLE PRECISION CONST,SLOPE,CORR,X(100),Y(100)
       INTEGER J8,J9,JP
       J8=5
       J9=0
       JP=1
       DO 10 I=1,J8
        READ(*,*) X(I),Y(I)
10     CONTINUE
       CALL MAP_UTIL_ANALY(J8,J9,CONST,SLOPE,CORR,X,Y)
       WRITE(6,20) CONST,SLOPE,CORR
20     FORMAT('INTERCEPT=',D12.4,' SLOPE=',D10.3,' CORRELATION=',F8.4)
       STOP
       END

2. Program data

1.0    2.0
3.0    5.5
5.0   11.0
8.0   14.0
9.0   18.0

3. Program results

INTERCEPT=0.2455D+00  SLOPE=0.1895D+01  CORRELATION=0.9869

Top | Next | Prev

Auxiliary Routines

None.

Top | Next | Prev

Keywords

linear regression

Top | Next | Prev

Download

Download source code

Top | Prev


MAP originated from a joint project of the National Physical Laboratory and the University of Cambridge.

MAP Website administration / map@msm.cam.ac.uk

Top | Index | MAP Homepage

Valid HTML 3.2!