June 15, 2007, 10:19 AM
Leo LMulti Linear Regression
Anyone ever done a Multi Linear Regression to calculate the Slope and the Intercept. I know they have the REGRESS function, but that unfortunately doesn't give the formula.
I've got a scenario where I'm looking for the slope and intercept for a function with 2 "x" variables.
Guess I was checking to see if anyone has already encountered this and if there was a way to get the slope and intercept from the "REGRESS" function.
June 15, 2007, 11:16 PM
Bob H.That and more was there with the ANALYZE function back in PC/Focus 6.01.. disappeared since..
June 16, 2007, 04:23 PM
FrankDutchyes that was a great functionality....
the old days
June 16, 2007, 07:52 PM
susannahi guess that's why there is a relationship with the stat software company SPSS. I, like amsterdam frank, miss the old analyze days.
June 18, 2007, 08:03 AM
ET http://documentation.informationbuilders.com/masterinde...df_archive/stats.pdfThe above links to a manual that pertains to the analyse command has formulas displayed for various kinds of regresssion. You need to login to tech support. I have these formulas in an old mainframe manual but there is no way for me type it here because of the various Greek symbols and sub/super scripts. I tried to cut and paste them from the above pdf report above but that did not work either. There were at least 3 fuctions (possibly more) that mention regression specifically. MULTR - for multiple linear regression, POLRG - polynomial regression, STEPR - stepwise multiple regression analysis. I think this still works on the mainframe but this stuff is way over my head as to what it means.
Good luck.
et
June 19, 2007, 05:43 PM
David BriarsHi Leo,
In the first step, I compute the slope and intercept, for all observations.:
-TYPE Calculating Slope and Intercept for Linear Equation to follow..
JOIN CLEAR *
DEFINE FILE ALLCHGIN
X/D15.4 = VOL_MNTH;
Y/D15.4 = VOLUME;
XY/D15.4 = X * Y;
XCUBED/D15.4 = X * X;
END
TABLE FILE ALLCHGIN
"Slope and Y Intercept Components"
" "
SUM X Y XY XCUBED CNT.X AVE.X AVE.Y
COMPUTE SLOPE/D15.4 = (XY - ((X * Y) / CNT.X)) /
(XCUBED - ((X * X) / CNT.X));
COMPUTE YINTERCEPT/D15.4 = IF CNT.X EQ 1 THEN 0 ELSE
AVE.Y - (SLOPE * AVE.X);
BY UNIT_ID
ON TABLE HOLD AS REGCALCS FORMAT FOCUS INDEX UNIT_ID
END
In the second step, I join my observation file, to my results file, and create my predicted values:
-TYPE Creating Predicted Values for the first sixty 'historical months'..
JOIN CLEAR *
JOIN UNIT_ID IN ALLCHGIN TO UNIT_ID IN REGCALCS AS GETCALS
DEFINE FILE ALLCHGIN
PREDICTED/D15.4 = YINTERCEPT +(SLOPE * VOL_MNTH);
END
TABLE FILE ALLCHGIN
PRINT VOL_MNTH
YINTERCEPT
SLOPE
VOLUME
PREDICTED
BY UNIT_ID
ON TABLE HOLD AS HISTMOS FORMAT FOCUS
END
Perhaps this code is adaptable to your requirements.
Regards,
Dave
June 22, 2007, 12:08 PM
Leo LWell I've come up with a solution that works for my application, so I thought I would share the code for other people that might be in the same scenario.
[CODE]
-*...
-* In the table with the data, we added
-* COMPUTE ONE/I1 = 1;
-* In order to join in the formula afterwards
DEFINE FILE DATA
X1SQ/D18.1 = X1 * X1;
X2SQ/D18.1 = X2 * X2;
X1X2/D18.1 = X1 * X2;
X1Y/D18.1 = X1 * Y;
X2Y/D18.1 = X2 * Y;
END
TABLE FILE DATA
SUM Y X1 X2
X1SQ X2SQ X1X2 X1Y X2Y
ON TABLE HOLD AS REGRESS1 FORMAT ALPHA
END
DEFINE FILE REGRESS1
D2/D20 = X1SQ * X2SQ - X1X2*X1X2;
F7/D20.10 = X2SQ / D2;
F8/D20.10 = -X1X2 / D2;
F9/D20.10 = X1SQ / D2;
INTERCEPT/D18.4 = F7 * X1Y + F8 * X2Y;
SLOPE/D18.4 = F8 * X1Y + F9 * X2Y;
ONE/I1 = 1;
END
TABLE FILE REGRESS1
SUM SLOPE INTERCEPT
BY ONE
ON TABLE HOLD AS REGRESS FORMAT FOCUS INDEX ONE
END
JOIN ONE IN DATA TO ONE IN REGRESS
...
[/CODE}
So assuming I renamed all the names correcty to the more generic example table, this was my solution for the multilinear equation in order to get the "formula" values.