PROGRAM $ ********************************************************************** $ $ L I N R E G $ $ Program: LINREG $ $ Programmer: Dr. David G. Simpson $ Department of Physical Science $ Prince George's Community College $ Largo, Maryland 20774 $ $ Date: January 27, 2002 $ $ Language: Speakeasy $ $ Description: This program performs a linear regression analysis for $ a set of data given as (x,y) pairs. The output from $ the program is the slope and y-intercept of the least- $ squares best fit straight line through the data points. $ $ ********************************************************************** $ $ Print introductory message $ " LINREG - Perform linear regression" " (Enter X=-9999 to stop data entry and compute linear regression.)" $ $ Initialize sums $ N = 0.0 SUMX = 0.0 SUMX2 = 0.0 SUMXY = 0.0 SUMY = 0.0 SUMY2 = 0.0 $ $ Start of data entry loop $ L10: SPACE(1) ASK ("Enter X: ", "X=") IF (X .EQ. -9999) GOTO L20 ASK ("Enter Y: ", "Y=") $ $ Compute sums $ N = N + 1.0 SUMX = SUMX + X SUMX2 = SUMX2 + X * X SUMXY = SUMXY + X * Y SUMY = SUMY + Y SUMY2 = SUMY2 + Y * Y GOTO L10 L20: $ $ Compute slope (M), y-intercept (B), and correlation coefficient (R) $ M = (N * SUMXY - SUMX * SUMY) / (N * SUMX2 - SUMX**2) B = (SUMY * SUMX2 - SUMX * SUMXY) / (N * SUMX2 - SUMX**2) R = (SUMXY - SUMX * SUMY / N) / SQRT((SUMX2 - SUMX**2/N) * & (SUMY2 - SUMY**2/N)) $ $ Print results $ "Slope ", M "y-intercept ", B "Correlation ", R RETURN END