rem Multiple Independent Variable Linera Regression rem Using the form y=c+a1*x1+a2*x2+...+an*xn cls print print "Multiple Independent Variable Linear Regression" print "Using the form Y=C+C1*X1+C2*X2+...+Cn*Xn" print dim t(9) dim x(9) dim s(9) dim a(9,10) rem data entry input "Number of independent variables? ";v input "Number of points to input? ";n [aleap] input "Use keyboard (k) or read from data (d)? ";c$ print if c$="k" then x(1)=1 for i=1 to n print "Point ";i;":" for j=1 to v print " Independent Variable ";j;": "; input " ";x1 x(j+1)=x1 next j print " Dependent variable:"; input " ";y1 x(v+2)=y1 for k=1 to v+1 for l=1 to v+2 a(k,l)=a(k,l)+x(k)*x(l) s(k)=a(k,v+2) next l next k s(v+2)=s(v+2)+x(v+2)^2 next i goto [zleap] end if if c$="d" then rem data must be in form 'data x1 x2 x3 ... xn y' x(1)=1 for i=1 to n for j=1 to v read x1 x(j+1)=x1 next j read y1 x(v+2)=y1 for k=1 to v+1 for l=1 to v+2 a(k,l)=a(k,l)+x(k)*x(l) s(k)=a(k,v+2) next l next k s(v+2)=s(v+2)+x(v+2)^2 next i else goto [aleap] end if rem start calcs [zleap] for i=2 to v+1 t(i)=a(1,i) next i for i=1 to v+1 j=i [cleap] if a(j,i)<>0 then goto [bleap] end if j=j+1 if j<=(v+1) then goto [cleap] else print print "Sorry, no unique solution..." end end if [bleap] for k=1 to v+2 b=a(i,k) a(i,k)=a(j,k) a(j,k)=b next k z=1/a(i,i) for k=1 to v+2 a(i,k)=z*a(i,k) next k for j=1 to v+1 if j=i then goto [dleap] end if z=-1*a(j,i) for k=1 to v+2 a(j,k)=a(j,k)+z*a(i,k) next k [dleap] next j next i rem print coefficients print print "Y=C+C1*X1+C2*X2+...+Cn*Xn" print "C = " ;a(1,v+2) for i=2 to v+1 print "C";i-1;" = ";a(i,v+2) next i rem calculation of fit parameters p=0 for i=2 to v+1 p=p+a(i,v+2)*(s(i)-t(i)*s(1)/n) next i r=s(v+2)-s(1)^2/n z=r-p l=n-v-1 i=p/r rem print fit parameters print print "Coef. of Determination: ";i print "Coef. mult. correlation: ";i^.5 print "Standard Error of est. : ";(abs(z/l))^.5 rem interpolation routine print print "Interpolation (enter x1=q to end program) " [again] p=a(1,v+2) j=1 print input "x1= ";x1$ if x1$="q" then end else x=val(x1$) end if p=p+a(j+1,v+2)*x for j=2 to v print "x";j;"="; input " ";x p=p+a(j+1,v+2)*x next j print "Y= ";p goto [again] data 8,48,59 data 9,49,55 data 6,44,50 data 10,59,80 data 8,55,61 data 9,51,75 data 9,55,67 data 7,50,58