## Linear Regression Analysis

 X Y-OBS Y-CALC DIFFERENCE 1 . 011 1.118404E-02 1.84 0368E-04 5 .049 5.096154E-02 1.96154E-03 10 . 102 .1006834 -1.316577E-03 20 .199 .2001272 1.127169E-03 30 .304 .2995709 -4.429072E-03 40 .398 .3990147 1.01468E-03 50 .497 .4984585 1.458436E-03 SLOPE = 9.944376E-03

STANDARD DEVIATION OF SLOPE = 5.379905E-05 INTERCEPT = 1.239661E-03

STANDARD DEVIATION OF INTERCEPT = 1.51158E-03 STANDARD DEVIATION OF REGRESSION = 2.438353E-03 COEFFICIENT OF CORRELATION = .9999269

10 REM linear regression with sample calculations - linreg2.bas

20 REM *********************** SEPTEMBER 20,1984 ****************************

105 REM INPUT DATA STARTING L 2000 AS # DATA PAIRS, x, y 110 REM **** S = SLOPE OF THE BEST FITTED LINE 120 REM **** B = INTERCEPT OF THE LINE 130 PRINT" LINEAR REGRESSION"

140 PRINT"******************************************************************"

180 NEXT J

190 GOSUB 210

200 STOP

210 REM ******************************************************************** 220 REM ***** THIS SUBROUTINE CALCULATES THE LINEAR REGRESSION *****

24 0 REM ********************************************************************

370 NEXT J

380 S = ( N * X3 - XI * Y1 ) / ( N * X2 - Xl*2 ) 390 B = ( Y1 * X2 - XI * X3 ) / ( N * X2 - Xl*2 ) 4 00 X4 = XI / N 410 Y4 = Y1 / N

420 X9 = X2 - N * X4"2 430 FOR J = 1 TO N 440 Y5(J) = S * X(J) + B 450 D(J) = Y5(J) - Y(J) 460 Q1 = Q1 + Y(J)"2 470 NEXT J

520 NEXT J

570 SI = ( SQR ( N / (N * X2 - Xl"2 ) ) ) * ( SQR ( Q / ( N - 2 ) ) ) 580 S2 = ( SQR ( X2 / ( N « X2 - XI"2 ) ) ) * ( SQR ( Q / ( N - 2 ) ) ) 590 NEXT J

600 UR = ( QX - S~2 * X9 ) / (N - 2 ) 610 SR = SQR ( UR )

620 PRINT "TYPE 1 FOR LEAST SQUARE FIT ONLY, OR TYPE 0 FOR SAMPLE CALC."

630 INPUT K

660 PRINT "HOW MANY SAMPLES ?"

670 INPUT P

680 PRINT "ENTER AVERAGE RESPONSE AND NUMBER OF MEASUREMENTS FOR EACH"

690 PRINT "INDIVIDUAL SAMPLE."

730 PRINT

750 SX(I) = SQR ((UR/S"2)*((1/MN(I)+1/N)+(A(I)-Y4)"2/((S"2)*X9))) 760 NEXT I

770 PRINT " LINEAR REGRESSION ANALYSIS."

790 PRINT "X","Y-OBS","Y-CALC","'DIFFERENCE"

800 PRINT "-",»-----","------","----------"

830 NEXT J

8 50 PRINT " SAMPLE CALCULATION FROM STANDARD CURVE"

860 PRINT " --------------------------------------"

870 PRINT "SAMPLE NUMBER","Y-OBS","X-CALC","STD. DEV."

880 PRINT "-------------" ,»-----" ,"------","---------"

910 NEXT I

930 PRINT "HIT ANY KEY FOR SUMMARY" 94 0 V\$=INKEY\$: IF V\$="" THEN 94 0 950 PRINT " " 960 PRINT "SLOPE = ";S

970 PRINT "STANDARD DEVIATION OF SLOPE = ";S1 980 PRINT "INTERCEPT - ";B

1000 PRINT "STANDARD DEVIATION OF INTERCEPT = ";S2 1010 PRINT "STANDARD DEVIATION OF REGRESSION = ";SR 1020 PRINT "COEFFICIENT OF CORRELATION = ";R 1025 PRINT "FOR HARD COPY, TYPE GOTO 1100"

1030 RETURN

1100 LPRINT » LINEAR REGRESSION ANALYSIS."

1110 LPRINT " ---------------------------"

1120 LPRINT "X","Y-OBS","Y-CALC","DIFFERENCE"

1130 LPRINT "-»,»-----»,"------","----------"

1180 NEXT J

1200 LPRINT " SAMPLE CALCULATION FROM STANDARD CURVE"

1210 LPRINT " --------------------------------------"

1220 LPRINT "SAMPLE NUMBER","Y-OBS","X-CALC","STD. DEV."

1230 LPRINT »-------------","-----» ,"---------------"

1260 NEXT I

1290 LPRINT " ":LPRINT " " 1300 LPRINT "SLOPE = ";S

1310 LPRINT "STANDARD DEVIATION OF SLOPE = ";S1 1320 LPRINT "INTERCEPT = ";B

1340 LPRINT "STANDARD DEVIATION OF INTERCEPT = ";S2 1350 LPRINT "STANDARD DEVIATION OF REGRESSION = ";SR 1360 LPRINT "COEFFICIENT OF CORRELATION « ";R 2000 DATA 7

2010 DATA 1,0.011,5,0.049,10,0.102,20,0.199,30,0.304,40,.398,50,0.497 2020 DATA .8,23.7192,1,28.779 2030 DATA 1.5,40.4789