BBS: Inland Empire Archive Date: 04-11-92 (17:14) Number: 11 From: JEAN CREPEAU Refer#: NONE To: DON KROUSE Recvd: NO Subj: Regression Conf: (2) Quik_Bas
In a message to ALL, DON KROUSE wrote: DK=> Hi Folks, DK=> Does anyone know were I might find source code for a multiple regression routine? DK=> I am particularly interested in a routine that does Linear, Log, Exponential, Power, etc. and that optimizes the order in which the dependent variables are included. Use the following formula m=(n*SUM(x*y) - SUM(x)*(SUM(y))/(n*SUM(x*x) - SUM(x)*SUM(x)) b=(SUM(y)-m*SUM(x))/n where n=# of samples Your linear equation is y=mx+b Here is the source: TYPE RECT X AS SINGLE Y AS SINGLE END TYPE SUB REGR(N,VEC() AS RECT,MODE,M,B) FOR X=0 TO N-1 IF MODE AND 1 THEN CX=LOG(VEC(X).X) ELSE CX=VEC(X).X IF MODE AND 2 THEN CY=LOG(VEC(X).Y) ELSE CY=VEC(X).Y SX=SX+CX:SY=SY+CY:SXY=SXY+CX*CY:SX2=SX2+CX*CX NEXT M=(N*SXY-SX*SY)/(N*SX2-SX*SX) B=(SY-M*SX)/N END SUB This sub calculates m and b from a list of points vec(0...n-1). It has been modified to compute linear, log, exp and power regression. To use it: 1. You put the data in a vector of type RECT INPUT "NUMBER OF DATA: ",N REDIM VEC(N-1) AS RECT FOR X=0 TO N-1 INPUT "(X,Y): ",VEC(X).X,VEC(X).Y NEXT 2. You determine the mode MODE=0 => linear MODE=1 => log MODE=2 => exp MODE=3 => power 3. You call the sub REGR N,VEC(),MODE,M,B 4. Your regression equation is Mode 0: y=m*x+b Mode 1: y=m*log x + b Mode 2: y=exp(b)*exp(m*x) Mode 3: y=exp(b)*x^m --- * Origin: INTERACESS Montreal (QC) Canada (514) 528-1415 (1:167/280)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET