C ********************************************************************** C C L I N R E G C C PROGRAM: LINREG C C PROGRAMMER: DR. DAVID G. SIMPSON C DEPARTMENT OF PHYSICAL SCIENCE C PRINCE GEORGE'S COMMUNITY COLLEGE C LARGO, MARYLAND 20774 C C DATE: JANUARY 21, 2002 C C LANGUAGE: FORTRAN-66 C C DESCRIPTION: THIS PROGRAM PERFORMS A LINEAR REGRESSION ANALYSIS FOR C A SET OF DATA GIVEN AS (X,Y) PAIRS. THE OUTPUT FROM C THE PROGRAM IS THE SLOPE AND Y-INTERCEPT OF THE LEAST- C SQUARES BEST FIT STRAIGHT LINE THROUGH THE DATA POINTS. C C ********************************************************************** C ********************************************************************** C MAIN PROGRAM C ********************************************************************** C ********************************************************************** C VARIABLE DECLARATIONS C C B Y-INTERCEPT OF LEAST-SQUARES BEST FIT LINE C M SLOPE OF LEAST-SQUARES BEST FIT LINE C N NUMBER OF DATA POINTS C R CORRELATION COEFFICIENT C STR INPUT STRING C SUMX SUM OF X C SUMX2 SUM OF X**2 C SUMXY SUM OF X * Y C SUMY SUM OF Y C SUMY2 SUM OF Y**2 C X INPUT X DATA C Y INPUT Y DATA C ********************************************************************** C C PRINT INTRODUCTORY MESSAGE C WRITE (6,10) 10 FORMAT (1X,34HLINREG - PERFORM LINEAR REGRESSION) WRITE (6,20) 20 FORMAT (1X,63H(ENTER -9999 TO STOP DATA ENTRY AND COMPUTE LINEAR R 1EGRESSION.)) C C INITIALIZE SUMS C AN = 0.0 SUMX = 0.0 SUMX2 = 0.0 SUMXY = 0.0 SUMY = 0.0 SUMY2 = 0.0 C C START OF DATA ENTRY LOOP C 30 CONTINUE WRITE (6,40) 40 FORMAT (1X,10HENTER X: ) READ (5,50) X 50 FORMAT (F15.6) IF (X .EQ. -9999.0) GO TO 80 WRITE (6,60) 60 FORMAT (1X,10HENTER Y: ) READ (5,70) Y 70 FORMAT (F15.6) C C COMPUTE SUMS C AN = AN + 1.0 SUMX = SUMX + X SUMX2 = SUMX2 + X * X SUMXY = SUMXY + X * Y SUMY = SUMY + Y SUMY2 = SUMY2 + Y * Y GO TO 30 80 CONTINUE C C COMPUTE SLOPE (AM), Y-INTERCEPT (B), AND CORRELATION COEFFICIENT (R) C AM = (AN * SUMXY - SUMX * SUMY) / (AN * SUMX2 - SUMX**2) B = (SUMY * SUMX2 - SUMX * SUMXY) / (AN * SUMX2 - SUMX**2) R = (SUMXY - SUMX * SUMY / AN) / 1 SQRT((SUMX2 - SUMX**2/AN) * (SUMY2 - SUMY**2/AN)) C C PRINT RESULTS C WRITE (6,90) AM 90 FORMAT (1X,17HSLOPE M = ,E15.6) WRITE (6,100) B 100 FORMAT (1X,17HY-INTERCEPT B = ,E15.6) WRITE (6,110) R 110 FORMAT (1X,17HCORRELATION R = ,E15.6) END