88 65255 6483518 O1011 54092 33362 94904 31273 04146 18594 29852 71585 85030 5113219 52162 53916 46369 S8586 23216 14513 83149 98736 23495 64350 9473820_ 07056 97628 33787 09998 42698 06691 76988 13602 51851 46104 88916
21 48663 91245 85828 14346 09172 30168 90229 04734 $9193 22178 3042122 54164 58492 22421 74103 47070 25306 76468 26384 58151 06646 2152423 32639 «= 32363. «05597. «24200 »««:13363 «38005. 94342 «28728 «= 35806 )§=— 06912-1701224 29334 27001 87637 87308 58731 00256 45834 15398 46557 41135 1036725 02488 33062 28834 07351 19731 92420 60952 61280 SO00f 67658 32586
26 81525 72295 04839 96423 25878 8265) 66566 14778 76797 14780 1330027° «29676 20591 68086 26432 46901 20849 80768 81536 86645 $2659 9225928- 00742 57392 39064 66432 84673 40027 32832 61362 98947 96067 6476029 05366 04213 25669 26422 44407 44048 37937 63904 45766 66134 7547030 «91921 26418 64117 94305 26766 25940 39972 22209 71500 64568 91402
34 00582-04741 «= 87917-77341 «42206 «= 35126 974087 «99547 81817 42607 = 4380832 00725 69884 62797 56170 86324 88072 76222 36086 84637 93161 7603833 69011 65795 95876 $5293 18988 27354 26575 08625 40801 $9920 2984134 25976 57948 29888 88604 67917 48708 18912 82271 65424 69774 3341135 09763 83473 73577_ 12908 30883 10317 28290 35797 0599841688 += 34952
36 691567 42595 27958 30134 04024 86385 29880 99730 55536 84855 2908037 «17955-56349 90999 49127 20044 «=6§9931 06115 20542 18059 02008 7370838 46503 18584 18845 49618 02304 51038 2065S $8727 28168 15475 5694239° 92157 89634 94824 «78171 84610» 82834 «09922, 25417 44137 «48413-2555540 14577 62765 35605 81263 39667 47358 54873 56307 61607 49518 89565
 
WOUND Haun
 
Source: Francis F Mar cin, Computer Modeling and Simulation (John Wiiey & Sons. 1963, p, 288 (reprinted by permission)).APPENDIX 2P|
Method of Least Squares
The following programs, written in Microsoft FORTRAN for the IBM PC," solve the two-variable regression analysis using the method of least squares. The program allows for theregression of two series against one another, and the regression of one series against time.
OPERATING INSTRUCTIONS
In the following example, the user’s entries are underlined:
LSTSO
Enter data in sets of 2 (Y then X).
If second variable is omitted, sequential numbers will be used for x.Extra <return> ends input.
Enter below:
YYYYYY XXXXXX
L2z 2.43LIQ 2.26110 2,15<BETURN>
Print data (Y/N)? ¥
(Computer prints data and solutions)
Sample results (Y/N) ?¥.
Enter start, end and increments below ~
1.00 7.90 150(Computer prints sample results)Plot results (Y/N)?¥Name for X-scale (9 chars)?SOYBEANS NName for Y-scale (9 chars}?CORNWhich plot?1: Linear2: Logarithmic3: Exponential4: Curvilinear : =Which number? 1(Computer plots)Another plot (Y/N)?¥ .Which plot? -1: Linear .
(and so forth)COMPUTER PROGRAMS
1 STITLE: ‘LSTSQ: LEAST SQUARES' .2 $SUBTETLE: ‘COPYRIGHT 1986 P J KAUFMAN‘ . . -
' BASIC programs for both plotting and teast-squares regression can be found in ER. Ruckdeschel, BASIC Scien-Hific Sisbroutines, Volume I (Byte/McGraw-Hill, Peterborough, NH, 1981).APPENDIX 2 - 635
 
3 $STORAGE:2
4 PROGRAM LSTSO
5 C---+ Least Squares Regression Analysis for 2 variables6
7 CHARACTER*1 ANS
8 DIMENSION X(100),¥(100)
OATA MAX/100/OPEN(6,FILE="PRN")
- Read data in sets of 2 variablesT=1WRITE(*,7000)17 7000 FORMAT(’ Enter data in sets of 2 {Y then X).'/
 
18 + " If second variable is omitted, sequential numbers’19 + ’ will be used for X.'/* Extra <return> ends input.'//20 + * Enter below: '/
21 + " YYYYYY. XXXXXX")
22 10° READ(*,5000)¥(1),X(1)23 5000. FORMAT(BN,F6.2,F7.2)
24 IF(Y(1).£0.0)G0TO 30
25 _ TF(X(1).£Q.0)X(1)=1
26 IF(1T.E0.MAX) THEN '27 WRITE(*, 7001 )MAX
28 7001. FORMAT(' Data input reached max of',I5,’. Processing begins.’29 "GOTO 30
30 ENDIF
31 I =1+1
32 = GOTO 10
33
34 30 N= 1-1
35 WRITE(*,7002)
36 7002 FORMAT(’ Print data (Y/N)?'\)37 READ(*, 5001 )ANS
38 $001 FORMAT(A1)
39 IF(ANS.NE. 'Y")GOTO 50
40 WRITE(6,6000)
41 6000 FORMAT('lLeast-Squares Regression Analysis',20X,’Data Input'\\42 + " Y (dep) X (ind)'\)43 00 40 J = 1,N
44 WRITE(6,6001)¥(J),X(d)
45 6001 FORMAT(2F8.2)46 40 CONTINUE
  
47 —48 50 CALL RA2V(Y,X,N) -4950 CALL EXIT -51 END .1 $TITLE: 'RA2V: Regression for 2 Variables’ ~2 $SUBTITLE: ‘Copypright 1986 PJ Kaufman’ -3 SSTORAGE:24 SUBROUTINE RA2V(Y,X,N) -56 C---+ Regression Analysis for 2 Variables7 With Linear, Power and Log Transformations89 C---+ Y = Dependent variable o10 C---- X = Independent variable11 C---- N= Number of data entriesAPPENDIX 2
~_——
6004
6001
6002
7000
5000
7001
5001
6009
Cee.
CHARACTER*L ANS ~CHARACTER*2 SIGN, SIGNCCHARACTER*9 YNAME, XNAME
DIMENSION X(100),¥(100),2A(4) ,28(4) ,2R(4)DATA MAX/100/
Perform linear regression
ITYPE=1
CALL BSTFIT(Y,X,N,2A(1),28(1),2R(1),SD, I TYPESIGN=" ‘
IF(28(1).GE.0)SIGN=' +°
WRITE(6,6000)ZA(1), SIGN, 28(1),2R(1),SDFORMAT(/54X, 'r2 St dev'//+ ' LINEAR Y=',F8.3,A2,F8.3,'*X",18X,F7.1,F9.3)
CALL LSTSO2(Y,X;N,ZA(4) ,Z2B(4) ,C,S4)
SIGN =" ' .IF(28(4).GE.0)SIGN =" +'SIGNC =" 'IF(C.GE.O)SIGNC’=" +°ITYPE = 4
WRITE(6 ,6004)2A(4) ,SIGN,2B(4),SIGNC,C,S4FORMAT(/* CURVI Y=',F8.3,A2,F8.3,'*X’,A2,F8.3,..*X2',12X,F9.3)
ITYPE=2
CALL BSTFITC(Y,X,N,ZA(2) ,2B(2) ,ZR(2),SD, ITYPE)SIGN="
IF(28(2).GE.0)SIGN=" +°
WRITE(6,6001)2A(2) SIGN, 28(2) ,2R(2) SDFORMAT(/' LOG = Ln(Y¥)=",F8.3,A2,F8.3, **Ln(X}',10X,F7.1,F9.3)
ETYPE=3
CALL BSTFIT(Y,X,N,2A(3) ,28(3),2R(3),SD,ITYPE)SIGN=" '
IF(2B(3).GE.0)SIGN=' +*
WRITE(6,6002)Z2A(3),SIGN,28(3),2R(3),SDFORMAT(/* EXPON Ln(¥)=",F10.3,A2,F10.3,‘*X', 10X,F7.1,F9-3)
WRITE(*,7000)FORMAT( ‘Sample results (Y/N)?‘\)READ(* , 5000) ANS =FORMAT(A1L)TFCANS.NE.'N') THEN , LcWRITE(*, 7001)FORMAT(/‘ Enter start, end and increments below'/+ ‘ssssss eeeeee ijiili')READ(*,5001)P, END, STEPSFORMAT(BN,F6.2,2F7.2)
WRITE(6 , 6009) -FORMAT(//12X, 'X LINEAR CURVI LOG EXPON'/)
Calculate all four fits at the same timeAPPENDIX 2 - 637
 
73° 100 YL = ZAC(L) + 2BC1)*P
74 Y2 = ZA(4) + 28(4)*P + C*P*P75 ¥3 = 2A(2) + 28(2)*ALOG(P)
76 ¥3 = EXP(Y3)
77 Y4 = 2A(3) + 28(3)*P
78 Y4 = EXP(Y4)
79
80 WRITE(6,6010)P,¥1,¥2,¥3,¥4
81 6010 FORMAT (5X ,5F8.2)
82
83 IF(P.LT. END) THEN
84 P = P + STEPS
85 GOTO 100
86 ENOIF
87
88 ENDIF
89
90 WRITE(*, 7002)
91 7002 FORMAT(/' Plot results (Y/N)?'\)92 READ(* ,5000) ANS
93 » TFCANS.NE.‘N')THEN
94 WRITE(*, 7003)
95 7003 FORMAT(' Name for x-scale (9 chars)?")96 ' READ(* , 5002) XNAME
97 5002 FORMAT(A)
98 WRITE(*, 7004)
99 7004 FORMAT(' Name for y-scale (9 chars)?")100 READ(*, 5003) YNAME
101 5003 FORMAT(A9)102 120 WRITE(*, 7005)103 7005 FORMAT(/' Which plot?'/' 1: Linear'/' 2: Logarithmic'/
 
104 + . 3: Exponential'/' 4: Curvilinear'/105 + ‘ Which number?‘\)106 READ(* ,5004)I107 5004 FORMAT(BN, 14)108 T=C109 IF(I.NE.4)TC = 0110 CALL PLOTRA(N;X,Y,ZA(1),28(1),TC,1,XNAME, YNAME) -iy WRITE(*, 7006)112 7006 FORMAT(/’ Another plot (Y¥/N)?'\)113 READ(*,5000)ANS114 IFCANS.NE. 'N')GOTO 120116 ENDIF11617 RETURN118 END -1 $TITLE: 'LSTSQ2: 2nd Order Least Squares’2 $SUBTITLE: 'P.J. Kaufman’3 $STORAGE :2 _4 SUBROUTINE LSTSQ2(Y,%,N,A,8,C,S)56 C---- Second Order (Curvitinear) Regression for 2 variables78 Dependent variable
Independent variable
Number of data entries
Constant term
Coefficient of X ~Coefficient of X**2
Standard deviation of residuals
Heoaow
YVowrzx«
 APPENDIX 2
—— ee
C----
10
°
20
150
DIMENSION X(2), 112)DOUBLE PRECISION SXX,SXY,SYY,SXX2,SX2X2,SYX2
Find the mean of x and yAX = 0AY = 0DO 10 f= 1,NAX = AX + X(T)AY = AY + YC(I)AX = AX/NAY = AY/N
Initialize for summationsSXX = 0
SxY = 0
SYY = 0
SkX2 = 0
SX2X2 = 0
SYX2 = 0
- Sums
00 20 1 =1,N 'XT = X(T)YI = ¥(1)XI - AXYI - ayXM2 = XT*XI - AX*AXSXX = SXX + XM*XMSXY = SXY + XM*YMSYY = SYY + YM*YMSXX2 = SXX2 + XM*XMZSX2X2 = SX2X2 + XM2*XM2ZSYX2 = SYX2 + YM*XMZ
>=to
(SXY*SX2X2_- SYX2*SXX2) / (SXX*SX2K2 - SXX2*SXX2)(SXX*SYX2 - SXX2*SXY) / (SKX*SX2X2 - SXX2*SXX2)AY - B*AX - C*AX*AX
BcA
- Standard deviation of residuals
S= 000 150 J = 1,NTY = Y(J)UW-= X(d)RV = A + BYTX + C*TX*TX -ERR = TY - RVAVGY=AVGY+TY -S = S + ERR*ERR -
S = SQRT(S/(N-1)) -
RETURN -END
STITLE: ‘REGVAL: Get regression vatue’SSUBTITLE: ‘Copyright 1986 PJ KaufmanSSTORAGE :2
FUNCTION REGVAL(X,A,B,ITYPE)APPENDIX 2 -
 
 
 
 
 
 
 
6 C---- Transform data from log form to normal form based upon the7 C---- type of regression fit (transmitted via ITYPE)89 GOTO (110,120,130), ITYPE10ll C---- Linear12 110 TY=AtB*X13 GOTO 140415 C---- Log16 120 TY=A+B*ALOG(X)v7 TY=EXP(TY)18 GOTO 1401920 C---- Exponential21 130 TY=AtB*X22 TY = EXP(TY)2324 = 140 REGVAL=TY25 .26 RETURN27 END119120 SUBROUTINE BSTFIT(Y,X,N,A,B,R,SO,ITYPE)121122 C---- Basic linear regression123 C---- N Number of input items124 C---- X Independent variable125 C Y Dependent variable126 C A Y-intercept127 C---- B Slope128 C R Correlation coefficient129 C---- SD Standard deviation of residuals130 C131 C¢ If [TYPE = 1 then linear (no prior x,y conversion)132 C---- = 2 then log (x=log x,y=log y)133 C---- = 3 then exponential (x=log x)134135 DIMENSION X(2), ¥(2)136137 DOUBLE PRECISION SUMX2,SUMY2, XY138139 SUMX=0.140 SUMX2=0.141 SUMY=0.142 SUMY 2=0.143 XY=0.144145 00 100 I=1,N146 TX=K(1)147 TFCITYPE.EQ.2)TX=ALOG(TX)148 Tr=¥(1)149 TFCITYPE.NE.L)TY=ALOG(TY )150 SUMX=SUMX+TX151 SUMX2=SUMX2+TX*TX152 SUMY=SUMY+TY153 SUMY 2=SUMY2+TY*TY -154 XY=XY+TX*TY .
155 100 CONTINUE$40 APPENDIX 2
 
156 .
157 TF(N.LT.2) RETURN
158 B=(N*XY -SUMX*SUMY ) / (N*SUMX2 - SUMX*SUMX )159 A=(SUMY -B*SUMX ) /N
160
161 C---- Correlation coefficient
162 R1=N*XY -SUMX*SUMY
163 R2=(N*SUMX 2 - SUMX *SUMX ) * (N*SUMY 2 - SUMY *SUMY )164 R = ((R1**2)/R2)*100
165
166 C---- Standard deviation around fitted function167 SD=0
168 00 150 J=1,N
169 TY=¥(J)
170 TX=X(J)
171 RV=REGVAL(TX,A,B,ITYPE)
172 T=TY-RV
173 150 SO=SD+T*T
174 SD=SQRT(SD/(N-1))
175
176 RETURN
77 END
LEAST-SQUARES SOLUTION FOR CORN VERSUS SOYBEANS
Least-Squares Regression Analysis . Data InputY (dep) X (ind)1.27 2.431.19 2.261.10 2.151.10 2.071.05 2.031.00 2.45,- 98 2.361.09 2.44 -1.12 2.521.18 2.74 ‘1.16 2.981.24 2.931.03 2.691.08 2.631.15 2.631.33 3.081.08 ~ 3.241.57 6.222.55 6.123.02 6.332.54 4.92 ~ —2.25 6.81 7 -2.02 5.88 “2.25 6.61 -2.52 6.283.11 7.412.50 6.05r2 St devLINEAR Y= 7.274 + -339*X 84.2  .278 -CURVI Y= -310 + 2323*X + .002*X2 -278LOG Un(¥)=  -.616 + .79S*L(X) 86.3 .282
EXPON in(¥)= ~.373 + »195*X 87.3 .283APPENDIX 2 . 64)
 
x LINEAR CURVE LOG EXPON
1.00 61 -63 54 841.50 78 80 75 922.00 95 -96 94 1.022.50 1.12 1.13 1.12 1.123.00 1.29 1.29 1.30 1.243.50 1.46 1.46 1.47 1.364.00 1.63 1.63 1.64 1.504.50 1.80 1.80 1.80 1,665.00 1.97 1.97 1.95 1.835.50 2.14 2.14 2.11 2.016.00 2.31 2.31 2.26 2.226.50 2.48 2.48 2.41 2.457.00 2.65 2.66 2.56 2.70
Plot of Rearession Analvsis
CORN 5 tenant nant nn ent tp tn nt et tet tent3.073.032.992.952.91 12.872.83 :2.79 32.76
2.72 + eo
2.68 1 : .
2.64 ! “ r
2.603 — * :
2.56 ! . :
2.52: x xx 4 3
x2a™
*
Naai ee he.
'2.05% - .
‘
\ 31.81 1 * ‘
t !
 APPENDIX 2
642
Plot of Recression Analysis
CORN
RMT OAR MO IND
 
NOLTSSNS ss enavsryen
CSTE TD OR ARGS SRDS SPADA NA OSS POR
MARANANNANN AN CN
NANA Naa
 
bewannenaRRSSsnRsse
‘
5888s
™
xx
1
2x28
.1 me XX
x”q°
 
798
4.34 5.14 5.94 6.73 75SOYBEANS
3.54
2.75
hn hp ng pee pete:
 
- ~.616. B= 79.0% .000
Log
 APPENDIX 2 : 643
 
a
Plot of Regression Analvsis
 
*
*
x\8‘
*
 
.°8*
8a*?
*
Nq.
aa'+
 
+xoex xx
 
L410 (XX‘
OLon npn hn pn enn eth hen ape
2.75 36S 4,34 s.14 5.94 6.73 5SOYBEANS -
   
EXPON A= +373, B .19e. 0 +000ne RR I NSAPPENDIX 2
644
Plot of Kearession Analysis
 
ane
 
+
z53
nn be ee ee
aernoreeonagoan 2SSTEFSBIANBSSHHVSISHARAS
MYNANNAN AN NNN
 
2g
sinc
2
a
36a
°
AU MPMARYO MAN MEHansooNDe ye
PRBBRRSTIGRTISHARANSSEAad asd Gah
 
3.94
5.14
“SOYBEANS,
4.34
'
3.54
2.73
c=
+825.
uo
= S10,
As
CURVE,APPENDIX 2
 
LEAST-SQUARES SOLUTION FOR SOYBEANS ONLY
Least Squares Regression Analysis
Y (dep)
43126150703453644$2749893+69+63+630812422
DYIDDODEDDDVWUUN AANA NYYANANNNN
LINEARCURYI
LOG
EXPON
to.ll.12,13,14,15,16.17.18.19,20.
WOVYAMRONYE
-a71 +.527 +
X (ind)2,002.003.004.005.006.007.008.009.0010.0011,0012,0013.0014,0015.0016.0017,0018.0019.0020.0021.0022.0023.0024.00 -25.0026.0027.00Y= -987 +Y= 1.684 +in(Y=Ln (y=x LINEAR00 1.2000 1,4100 1.6200 1.8300 2,0400 2.2500 2,4700 2,6800 2.8900 3,1000 3.3100 3,5200 3.7300 3,9400 4,1500 4.3700 4,5800 4.7900 §.0000 §.2100 5.42
+211*Xx-112*X + -004*X2»416*Ln(X)-053*X .
CURVI LOG EXPON1,80 1.31 1.791.92 1.