Post Reply 
(50g) Working Multiple linear regression in English
04-15-2022, 09:55 PM (This post was last modified: 04-15-2022 09:55 PM by acser.)
Post: #1
(50g) Working Multiple linear regression in English
I am aware of https://www.hpcalc.org/details/6616 which crashes Emu50G on iOS.
I am also aware of https://www.hpcalc.org/details/6207 which is great and works but is in Spanish.

Does anyone have information about a multiple linear regression program (preferably with source) for the HP 50g?

Thanks in advance.
A
Find all posts by this user
Quote this message in a reply
04-15-2022, 11:41 PM (This post was last modified: 04-23-2022 09:48 AM by Gil.)
Post: #2
RE: (50g) Working Multiple linear regression in English
See the thread
https://www.hpmuseum.org/forum/thread-14...regression
relative to my multiple linear regression program, which is quite complete and does not crash.

Linear Regression program for P-Var (with or without the constant) of dimension N (if P = then it returns the exact solution) with clear results and indication from which directory-path the variables came from and how each intermediate result and each variable were obtained, t, s, prob-values, beta lower and upper limits, R2 and R2adj, R2mod and R2modAdj when no constant, variation coefficient, full detailed anova with or without constant, correlation matrix and min-max-interval, 1st order partial correlation, half partial, multi-order correlation with Z1... Zk control variables, restriction model test for k independent variables Xi with k < p, including here also t, s, prob-values, variation coefficient, R2... and anova as for full, non-restricted model model, Spearman's rank rho (with or without ties) + rho crit and prob, including rho lower/upper limits. All stats calculated for any chosen value of alpha (set to 5% by default or if you incidentally erase it), even for Spearman's rho H0-prob and rho crit when N < 11.

Attached here is the full directory "STAT.Ver3.8e.Doc" of the latest version with its different subdirectories and explanations/notes. Note that, despite its ending ".Doc", it is not a Word document : it is a normal HP50G Directory to be copied directedly into the HP50G (or its EMU48 Version) and saved, for example, under the name STAT.REG.

Regards,
Gil Campart


Attached File(s)
.doc  STAT.3.8e2.DOC (Size: 89.87 KB / Downloads: 2)
Find all posts by this user
Quote this message in a reply
04-16-2022, 12:29 AM
Post: #3
RE: (50g) Working Multiple linear regression in English
Gil,
Excellent, thanks for sharing. I am already looking at it. Is there by any chance a PDF
manual or tutorial that includes the multivariate linear regression part of the STAT package?
Thanks,
A
Find all posts by this user
Quote this message in a reply
04-16-2022, 12:41 AM (This post was last modified: 04-16-2022 12:44 AM by Gil.)
Post: #4
RE: (50g) Working Multiple linear regression in English
No, unfortunately.

The explanations are in the given thread and in the subdirectory NOTES, Pages 1 to 19 (“PA1... PA19") ; these so called pages are actually HP50G small programs.

Before launching part of the several programs, the required input(s) , and in which form, is/are always explained in details.

Try with your own y and X Matrixes.

If you need help, then advise me and I will try and help you use the different subprograms.

Regards,
Gil
Find all posts by this user
Quote this message in a reply
04-16-2022, 01:32 AM
Post: #5
RE: (50g) Working Multiple linear regression in English
Thank you.
So far, I tried this (my comments are after #)

DATA # change directory to DATA
MY.EX # change directory to MY.EXAMPLE
{ X10 X20 X30 Y15 } # create a list with dependent variable values in columns X10, X20, X30 and dependent variable values in Y15
C.REG # execute the regression command

I get a matrix with the results.

The directory is now full with computed values.

My questions:
1) how can I get the p-value for the F value of the entire model?
2) how can I get the p-values of X10, X20, and X30 independent variables?

Thanks,
A
Find all posts by this user
Quote this message in a reply
04-16-2022, 04:14 AM
Post: #6
RE: (50g) Working Multiple linear regression in English
Perhaps this elaboration for the 38G may help?

https://www.hpmuseum.org/forum/thread-36...hlight=mlr
Find all posts by this user
Quote this message in a reply
04-16-2022, 01:24 PM (This post was last modified: 04-16-2022 01:32 PM by Gil.)
Post: #7
RE: (50g) Working Multiple linear regression in English
Suppose the Production P is a function of Labour T & invested Capital C.

P=f(T, C).

Let's call these variables P61, T61 and C61 like in DATA /DODGE Directory.

These variables should be found on pages 3.5, 3.3 & 3.4 of DODGE Directory.

Here they are reproduced in Matrix Form as they have to be saved in the DATA /DODGE Directory.

{P .61:
[[ 60 ]
[ 120 ]
[ 190 ]
[ 250 ]
[ 300 ]
[ 360 ]
[ 380 ]
[ 430 ]
[ 440 ]]

T.61:
[[ 1100 ]
[ 1200 ]
[ 1430 ]
[ 1500 ]
[ 1520 ]
[ 1620 ]
[ 1800 ]
[ 1820 ]
[ 1800 ]]

C.61:
[[ 300 ]
[ 400 ]
[ 420 ]
[ 400 ]
[ 510 ]
[ 590 ]
[ 600 ]
[ 630 ]
[ 610 ]]

Write now {1 T61 C61 P61}
and press ENTER.

Note:
- Use brackets
- Put the number 1 as the first element of the list if you want the normal model with a constant (don't put that number 1 if you want a special model without the constant)
- Put all the explaining, independent variables in the list, in the order you wish
- Put always the explained, dependent variable at the end of that list

Press the program C.OK, which has to be present in the working file DATA/DODGE.

Note
This program C.OK will
- show the path where the data come from
{ 1 T.61 C.61 P.61 { DATA DODGE } }
- and put you back to the main menu

Now you can press
C.REG (B-key)

Note
- C with a dot stands here (and everywhere) for calculation.
- Suppose you see PROBbeta (Page 6.6 in the main directory) and ask yourself how it was calculated (in other words, you look for its "definition" here),then do:
'C.PROBbeta' ENTER RCL.

What you get is a very large Matrix

[[ 'YP.61' 'ßižŒ5%' 'ßi¦Values' 'T.TAB2.44691185114' 'Sߏ' 'PROBߏ' 'VIF1¦With.Const1' 'VIF.WITH.CONST1' 'CONDIT.IND' ]
[ 1 'OK' -437.713632901 -7.55577881008 57.9309749403 2.78970456598E-4 '¯' '¯' '¯' ]
[ 'T.61' 'OK' .336530289395 3.75321467363 .089664545905 9.47384870108E-3 8.19773451775 '—XY¦?Not.Calc' '—XY¦?Not.Calc' ]
[ 'C.61?' 'ߍ0' .410015695781 2.09038685644 .196143452834 .081554631945 8.19773451781 '—XY¦?Not.Calc' '—XY¦?Not.Calc' ]
[ '¯' '¯' '¯' '¯' '¯' '¯' '¯' '¯' '¯' ]
[ 'R2' '¯' .978404282436 'R2ADJ' .971205709914 'VARIAT.COEF¦%¦' 8.20725553662 '¯' '¯' ]]

To enter the RESUL(T) Matrix:
Have the requested Matrix in the stack
And press the "Down-Arrow"-key (just above the SYMB-Key).

The beta values are in the 3rd column.
The probability associated in the 6th column .
The name of the independent variables in row 3 & 4, column 1
The name of the depend variable Y, here P61, in row 1, column 1.

So betas are
[[ -437.713632901 ]
[ .336530289395 ]
[ .410015695781 ]]

Note
If, afterwards, you want to get back only the betas, write:
Alpha-key
Redshift-key
B-key
ENTER

Suppose you cleared your screen and want to get back your results:
Press RESUL(ts) key (D-key).

Suppose you are not sure from which file the given variables come from.
Then press LIST0.. key (C-key).

Note
The full name of LIST0 is
LIST0.INPUT.REG.LAST

Now about the F values
Press the ANOVA-KEY (E-key), which is just in the right of RESUL (key).

Note
Before executing ANOVA (key), you must, of course, have run C.REG.

Result of Anova will give the following:

[[ 'All.ßi¦0?†No†' '°lib' '…C' 'µC' 'F.ANOVAPROB' ]
[ 'REGP¯1' '3¯1' 144695.122156 72347.561078 (135.916430532,1.00717031607E-5) ]
[ '“N¯P' '9¯3' 3193.76667537 532.294445895 'FŒ5%žP¯1žN¯P' ]
[ 'TOTN¯1' '9¯1' 147888.888889 18486.1111111 5.14325284979 ]]

To enter the ANOVA Matrix:
Have the requested Matrix in the stack
And press the "Down-Arrow"-key (just above the SYMB-Key).

Explanations for ANOVA output:
2nd row, 5th column: Eff F value calc. from your data =135.9
2nd row, 5th column: p value associated=0.00001
Just above, row 1/col 5: expl names F/p

4th row, 5th column: F theorical from tables=5.14
Just above, row 4/col: expl how to get this value from a book.

As the F Eff statistics =135.9
>
Ftable <alpha-level=5%,p-1=2,n-p=6> = 5.14,
we reject, with the alpha-level = 5%, the Ho hypothesis that beta1=beta2=0.

Work out this
Please try and work out this example and report me please how clear or unclear it all seems to you.

In fact, I gave priority to the results description.

Regards,
Gil
Find all posts by this user
Quote this message in a reply
04-19-2022, 03:42 AM (This post was last modified: 04-19-2022 04:23 AM by acser.)
Post: #8
RE: (50g) Working Multiple linear regression in English
Looks good. Thanks for sharing.

While playing with the above code, I also wrote my own.
STOre the below INOUT code as directory MLR. You can call it anything else you like. In the directory you will find a program called MLR.
MLR takes two arguments: X (design matrix, first column is 1s, columns 2 to p+1 (p=number of independent variables) are independent variable values. Y is the response matrix. MLR then stores all calculated values into OUTPUT and also puts some important ones on the stack. It is similar to what R’s lm (linear model) object does.
RESET clears the contents of OUTPUT.
Directory SAMPLE contains a sample X and Y matrix.

DIR
OUTPUT
DIR
END
SAMPLE
DIR
Y
[[ 10.2 ]
[ 15.8 ]
[ 19 ]
[ 43.3 ]
[ 1.02 ]
[ 57.3 ]]
X
[[ 1 1 1 1 ]
[ 1 2 1 2 ]
[ 1 4 2 1 ]
[ 1 3 4 6 ]
[ 1 0 0 0 ]
[ 1 9 6 5 ]]
END
MLR
\<< 0. \-> X Y j
\<< OUTPUT X TRAN DUP X * INV SWAP * Y * 'b' STO X TRAN DUP X * INV X SWAP * SWAP * 'H' STO X SIZE OBJ\-> DROP 1. - 'p' STO 'n' STO n IDN 'I' STO { n n } 1. CON 'J' STO H n INV J * - Y * Y TRAN SWAP * ABS 'SSR' STO Y TRAN I H - Y * * ABS 'SSE' STO n p - 1. - 'dfE' STO p 'dfR' STO n 1. - 'dfT' STO SSR dfR / SSE dfE / / 'F' STO dfR dfE F UTPF 'pF' SSR SSE + 'SSTO' STO STO SSR SSTO / 'R2' STO 1. SSE dfE / SSTO dfT / / - 'adjR2' STO SSE dfE / '\Gs2' STO \Gs2 X TRAN X * INV * 'C' STO { 'p+1.' 1. } 0. CON 'pi' STO pi 1. p 1. +
FOR j { j 1. } dfE b j GET C { j j } GET \v/ / UTPT 2. * PUT
NEXT 'pi' STO b "b" \->TAG F "F" \->TAG pF "pF" \->TAG R2 "R2" \->TAG adjR2 "adjR2" \->TAG pi "p(i)" \->TAG UPDIR
\>>
\>>
RESET
\<< 'OUTPUT' DUP PGDIR CRDIR
\>>
END
Find all posts by this user
Quote this message in a reply
04-19-2022, 09:40 AM (This post was last modified: 04-19-2022 10:02 AM by Gil.)
Post: #9
RE: (50g) Working Multiple linear regression in English
Interesting.

Suppose you have run the full Model H1 with the explaining variables X1X2 X3 X4... X6.

Suppose that the associated t-values are not big enough for X2 and X3.

It would be nice to have also a program testing automatically the full model H1 (constant X1, X2, X3, X4, X5, X6) versus alternative HP (constant, X1, X4, X5, X6), ie making all the F statistics by itself with the final conclusions.

As in C.RESTR?
inside STAT.3.7:

« "Argument:

{lst1 [{lst2}]}

† lst1:
- {1 X1 X[k-1] Y}
here 1 is for model
with const 1
(with intercept)

(only poss. if last
run of C.REG was
also with const 1)

- or lst1:
{ X1 Xk Y}
if NO-const model
(with NO intercept)

#k 'expl' Var
X1Xk or
1 X1X[k-1]
in restricted mod
must be < #P in C.REG

Best way to procede:
1)Just modify lst1 of
CHOIX on the left,

deleting
-appropriate expl ind
var among X1 Xp of
the full model C.REG
-or const 1
-or both

2) ENTER 3) C.RESTR?

And don't change lst2!

Att: lst1 {1 Y} (with
no Xi): not allowed

† lst2: path or
directories where
to fetch Var X1Xk,Y

Must be same Path/
Dir as for C.REG!

" DROP -3 SF 6 CF DTAG 4 CF { CHEMIN.LIST LIST0 N P LIST0.INPUT RESUL ANOVA XX ß ß0 ß.INT COVßi Sß Tß T.TAB PROBß ¥ “ S2ß S2 R2 R2ADJ R2mod R2modADJ —XY0 —XY —XY.CRIT PROB.—XY —XY.INT T.—XY T.—XY.TAB —.PART Z.TAB F.ANOVA PROB.ANOVA F.TAB …C.TOT µC.TOT …Cmod.TOT µCmod.TOT …C.REG µC.REG …Cmod.REG µCmod.REG …C“ µC“ VARIAT.COEF VIF1 VIF.WITH.CONST1 CONDIT.IND C1 } C.SAVE.VAR.ORIGINAL.REGFULL C.REG0 …C“ '…C“.RESTR' STO RESUL 'RESUL2.RESTR' STO ANOVA 'ANOVA.RESTR' STO 5 FIX -105 SF C.F.RESTR C.F.RESTR.TAB C.PROB.RESTR LIST0.INPUTFULL "FULL" TAG LIST0.INPUT DUP 'LIST0.INPUT.RESTR' STO "H0" TAG LIST0.INPUTFULL DUP 'LIST0.INPUT' STO 'CHOIX.POSS.LIST0.INPUT.RESTR' STO C.SAVEBACK.VAR.FULLORIGINAL.REG C.SUPP.VAR.FULL C.RESUL.RESTR RESUL.RESTR "H0¦RESTR" LIST0.INPUT.RESTR + "FULL¦" LIST0.INPUT + 2 LIST 'LIST0.INPUT.RESTR.LAST' STO
»

\<< "Argument:

{lst1 [{lst2}]}

\|> lst1:
- {1 X1 X[k-1] Y}
here 1 is for model
with const 1
(with intercept)

(only poss. if last
run of C.REG was
also with const 1)

- or lst1:
{ X1 Xk Y}
if NO-const model
(with NO intercept)

#k 'expl' Var
X1Xk or
1 X1X[k-1]
in restricted mod
must be < #P in C.REG

Best way to procede:
1)Just modify lst1 of
CHOIX on the left,

deleting
-appropriate expl ind
var among X1 Xp of
the full model C.REG
-or const 1
-or both

2) ENTER 3) C.RESTR?

And don't change lst2!

Att: lst1 {1 Y} (with
no Xi): not allowed

\|> lst2: path or
directories where
to fetch Var X1Xk,Y

Must be same Path/
Dir as for C.REG!

" DROP -3 SF 6 CF DTAG 4 CF { CHEMIN.LIST LIST0 N P LIST0.INPUT RESUL ANOVA XX \Gb \Gb0 \Gb.INT COV\Gbi S\Gb T\Gb T.TAB PROB\Gb \165 \Ge S2\Gb S2 R2 R2ADJ R2mod R2modADJ \GrXY0 \GrXY \GrXY.CRIT PROB.\GrXY \GrXY.INT T.\GrXY T.\GrXY.TAB \Gr.PART Z.TAB F.ANOVA PROB.ANOVA F.TAB \GSC.TOT \GmC.TOT \GSCmod.TOT \GmCmod.TOT \GSC.REG \GmC.REG \GSCmod.REG \GmCmod.REG \GSC\Ge \GmC\Ge VARIAT.COEF VIF1 VIF.WITH.CONST1 CONDIT.IND C1 } C.SAVE.VAR.ORIGINAL.REG\->FULL C.REG0 \GSC\Ge '\GSC\Ge.RESTR' STO RESUL 'RESUL2.RESTR' STO ANOVA 'ANOVA.RESTR' STO 5 FIX -105 SF C.F.RESTR C.F.RESTR.TAB C.PROB.RESTR LIST0.INPUT\->FULL "FULL" \->TAG LIST0.INPUT DUP 'LIST0.INPUT.RESTR' STO "H0" \->TAG LIST0.INPUT\->FULL DUP 'LIST0.INPUT' STO 'CHOIX.POSS.LIST0.INPUT.RESTR' STO C.SAVEBACK.VAR.FULL\->ORIGINAL.REG C.SUPP.VAR.FULL C.RESUL.RESTR RESUL.RESTR "H0\166RESTR" LIST0.INPUT.RESTR + "FULL\166" LIST0.INPUT + 2 \->LIST 'LIST0.INPUT.RESTR.LAST' STO
\>>
Find all posts by this user
Quote this message in a reply
04-19-2022, 11:42 AM
Post: #10
RE: (50g) Working Multiple linear regression in English
Very nice. I will look at that. Thanks for sharing.
Find all posts by this user
Quote this message in a reply
04-19-2022, 12:39 PM
Post: #11
RE: (50g) Working Multiple linear regression in English
Working my precious example,
you get after
{ 1 T.61 C.61 P.61 { DATA DODGE }
C.REG
the Matrixes RESUL(t):

[[ 'Y\->P.61' '\Gbi\[]\Ga\->5%' '\Gbi\166Values' 'T.TAB\->2.44691185114' 'S\Gb\|v' 'PROB\Gb\|v' 'VIF1\166With.Const1' 'VIF.WITH.CONST1\|v' 'CONDIT.IND\|v' ]
[ 1 'OK' -437.713632901 -7.55577881008 57.9309749403 2.78970456598E-4 '\175' '\175' '\175' ]
[ 'T.61' 'OK' .336530289395 3.75321467363 .089664545905 9.47384870108E-3 8.19773451775 '\GrXY\166?\->Not.Calc' '\GrXY\166?\->Not.Calc' ]
[ 'C.61?' '\Gb\->0' .410015695781 2.09038685644 .196143452834 .081554631945 8.19773451781 '\GrXY\166?\->Not.Calc' '\GrXY\166?\->Not.Calc' ]
[ '\175' '\175' '\175' '\175' '\175' '\175' '\175' '\175' '\175' ]
[ 'R2\->' '\175' .978404282436 'R2ADJ\->' .971205709914 'VARIAT.COEF\166%\166\->' 8.20725553662 '\175' '\175' ]]

We see that
the variable C61 has a question mark after its name (row 4, column 1).
It means that its beta coefficient is not significant.
It is confirmed in row 4, column 2, as there we read "beta—>0".
It's confirmed again in row 4, column 4, as there we read 2.09 for the t-value, when t-critical is greater and equal to 2.4469 (row 1, column 4).

What should be done?
Run the regression without the C61 variable.

In fact, in order to see what is happening, press the CHOIX (choice) at Page 2.1.

The result is
{ 1 T.61 C.61 P.61 { DATA DODGE } }.

Edit that list and delete the 3rd element, ie the variable C61.

The results is
{ 1 T.61 C.61 { DATA DODGE } }

Then run
C.RESTR?
(Page 2.2)

And you get the following Matrix:

[[ 'F.RESTR.TAB' ]
[ 5.98737760727 ]
[ '\[]>\[]' ]
[ 'F.RESTR' ]
[ 4.36971720886 ]
[ 'PROB.RESTR\166H0' ]
[ 8.15546319643E-2 ]
[ '\->H0\166Accepted' ]]

And you accept this Ho Hypothesis,
not using the C61 variable, as 5.987 > 4.3697.
Find all posts by this user
Quote this message in a reply
04-19-2022, 08:34 PM (This post was last modified: 04-21-2022 11:12 PM by Gil.)
Post: #12
RE: (50g) Working Multiple linear regression in English
Version 3.8 fixes the Var coeff:
- Mean of Y calculated beforehand;
- Var coeff set as infinity when mean of Y = 0.
Find all posts by this user
Quote this message in a reply
04-20-2022, 03:50 AM
Post: #13
RE: (50g) Working Multiple linear regression in English
My code with comments: and references


--- Installation ---

STOre the below INOUT (see end of this file for INOUT's description) code as directory MLR.
You can call it anything else you like.
In the directory you will find a program called MLR.
MLR takes two arguments:
X (design matrix, first column is 1s, columns 2 to p+1 (p=number of independent variables) are independent variable values.
Y is the response matrix, which contains the values of the dependent variable for each observation.

MLR then stores all calculated values into OUTPUT and also puts some important ones on the stack. It is similar to what R’s lm (linear model) object does.
RESET clears the contents of OUTPUT.
Directory SAMPLE contains a sample X and Y matrix.



--- Code begin, cut this line ---
DIR
OUTPUT
DIR
END
SAMPLE
DIR
Y
[[ 10.2 ]
[ 15.8 ]
[ 19 ]
[ 43.3 ]
[ 1.02 ]
[ 57.3 ]]
X
[[ 1 1 1 1 ]
[ 1 2 1 2 ]
[ 1 4 2 1 ]
[ 1 3 4 6 ]
[ 1 0 0 0 ]
[ 1 9 6 5 ]]
END
MLR
\<< 0. \-> X Y j
\<< OUTPUT
X TRAN DUP X * INV SWAP * Y * 'b' STO
X TRAN DUP X * INV X SWAP * SWAP * 'H' STO
X SIZE OBJ\-> DROP 1. - 'p' STO 'n' STO
n IDN 'I' STO
{ n n } 1. CON 'J' STO
H n INV J * - Y * Y TRAN SWAP * ABS 'SSR' STO
Y TRAN I H - Y * * ABS 'SSE' STO
n p - 1. - 'dfE' STO
p 'dfR' STO
n 1. - 'dfT' STO
SSR dfR / SSE dfE / / 'F' STO
dfR dfE F UTPF 'pF' STO SSR SSE + 'SSTO' STO
SSR SSTO / 'R2' STO
1. SSE dfE / SSTO dfT / / - 'adjR2' STO
SSE dfE / '\Gs2' STO \Gs2 X TRAN X * INV * 'C' STO
{ 'p+1.' 1. } 0. CON 'pi' STO
pi
1. p 1. + FOR j { j 1. } dfE b j GET C { j j } GET \v/ / UTPT 2. * PUT NEXT
'pi' STO
b "b" \->TAG F "F" \->TAG pF "pF" \->TAG R2 "R2" \->TAG adjR2 "adjR2" \->TAG pi "p(i}" \->TAG
UPDIR
\>>
\>>
RESET
\<< 'OUTPUT' DUP PGDIR CRDIR
\>>
END
---Code end, cut this line ---


--- MLR code (same as above), this time with comments, just for informational purposes, you won't be able to input this code with comments into the HP 50g ---
MLR
\<< 0. \-> X Y j ### X is the design matrix. First column is all 1's, remaining columns are values of X1, X2, X3, ..., XN
### Each row of the X design matrix represents an observation of X predictors.
### Y is the response column vector, which has to be represented as a n x 1 matrix for HP 50g's matrix algebra to work.


\<< OUTPUT ### We will store all values into the OUTPUT directory.
X TRAN DUP X * INV SWAP * Y * 'b' STO ### Calculate regression's b hat coefficients (sometimes called beta hat column vector).
X TRAN DUP X * INV X SWAP * SWAP * 'H' STO ### Calculate H (hat) matrix.
X SIZE OBJ\-> DROP 1. - 'p' STO 'n' STO ### Number of predictor variables p is the number of predictor variables
### which is the number of columns - 1 of the X design matrix. n is the number of observations which comes from the number of rows of the Y response matrix.
n IDN 'I' STO ### Create an n x n identity matrix
{ n n } 1. CON 'J' STO ### Create an n x n matrix of 1'
H n INV J * - Y * Y TRAN SWAP * ABS 'SSR' STO ### H is the "hat" matrix. SSR is sum of squares for the regression. Sometimes SSR is denoted as SSM (sum of squares of the model).
Y TRAN I H - Y * * ABS 'SSE' STO ### Calculate standard sum of errors (residuals)
n p - 1. - 'dfE' STO ### Calculate degrees of freedom for errors (residuals) = n - (p+1). The +1 comes from the fact that you want to to calculate the intercept too.
p 'dfR' STO ### Degrees of freedom for the regression, sometimes referred to as the model
n 1. - 'dfT' STO ### Total degrees of freedom
SSR dfR / SSE dfE / / 'F' STO ### Calculate F statistic for entire regression model.
dfR dfE F UTPF 'pF' STO ### Calculate probability belonging to dfR, dfE and the F value for the entire regression model.
SSR SSE + 'SSTO' STO ### SSTO is the standard sum of totals (sometimes denoted as SST)
SSR SSTO / 'R2' STO ### Calculate R^2
1. SSE dfE / SSTO dfT / / - 'adjR2' STO ### Calculate adjusted R^2
SSE dfE / '\Gs2' STO ### Calculate sigma^2
\Gs2 X TRAN X * INV * 'C' STO ### Calculate Covariance matrix = sigma^2 * (X*X')^(-1)
{ 'p+1.' 1. } 0. CON 'pi' STO ### Create an empty matrix of p values corresponding to each correlation coeeficient's Student t test.
pi
1. p 1. + FOR j { j 1. } dfE b j GET C { j j } GET \v/ / UTPT 2. * PUT NEXT ### For each correlation coefficient bj, get t_j=b_j/sqrt(C_jj) (diagonal values of the C matrix), then calculate the p value of t_i with dfE, the Student t distribution for lower and upper tails.
'pi' STO ### Store p_i of each correlation coefficient into the pi column vector.
b "b" \->TAG F "F" \->TAG pF "pF" \->TAG R2 "R2" \->TAG adjR2 "adjR2" \->TAG pi "p(i}" \->TAG ### Print out important results
UPDIR ### Go back to the main directory.
\>>
\>>

Use INOUT from https://www.hpmuseum.org/forum/thread-13941.html to load the below program
'IN'
Code:
@ 7-bit ascii string -> calc object
\<< \->STR 3 TRANSIO RCLF SIZE 3 >
#2F34Dh #3016Bh IFTE SYSEVAL + STR\-> \>>

'OUT'
Code:
@ Calc object -> 7-bit ascii string
\<< STD 64 STWS \->STR 3 TRANSIO RCLF SIZE 3 >
#2F34Fh #2FEC9h IFTE SYSEVAL \>>


--- References ---


https://online.stat.psu.edu/stat462/node/132/
https://www.stat.purdue.edu/~boli/stat51...topic3.pdf
https://www.robots.ox.ac.uk/~fwood/teach...ure_12.pdf , esp. page "Quadratic forms"
https://github.com/SurajGupta/r-source/b...ats/R/lm.R , esp. the summary() function
http://users.stat.umn.edu/~helwig/notes/mlr-Notes.pdf
https://scholar.princeton.edu/sites/defa...slides.pdf
http://www.stat.uchicago.edu/~yibi/teach...es/MLR.pdf
http://193.6.12.228/uigtk/uise/gtknappal...appali.pdf esp. section 4.1
Find all posts by this user
Quote this message in a reply
04-20-2022, 07:56 AM (This post was last modified: 04-20-2022 10:11 AM by Gil.)
Post: #14
RE: (50g) Working Multiple linear regression in English
Nice work, Acser!

Thanks for sharing.

Just perhaps missing the betas intervals, a restricted model test, partial correlations and VIF calculations.

When having many explaining/independent variables (consommation, work, etc) in a file/Directory, perhaps it might be a good idea to have labels in the results.
For instant, for betas:
Beta (consommation) : 45
Beta (work) : 75

Suppose you have different same variable names in different files/Directory, it might be also useful to show where the variables come from, from Dir1 or Dir2, with indication of the path.
Find all posts by this user
Quote this message in a reply
04-20-2022, 11:51 AM
Post: #15
RE: (50g) Working Multiple linear regression in English
Great points. I may implement them in the future.
Find all posts by this user
Quote this message in a reply
04-27-2022, 02:08 PM (This post was last modified: 04-27-2022 02:10 PM by acser.)
Post: #16
RE: (50g) Working Multiple linear regression in English
Just added confidence intervals. The "CI" variable shows a matrix of the 2.5% - 97.5% confidence intervals.

Source code is attached as a text file. You can use the OBJ-> command to convert it from string to a program.
Find all posts by this user
Quote this message in a reply
04-27-2022, 03:27 PM
Post: #17
RE: (50g) Working Multiple linear regression in English
I did not check, as I have not enough memory.

Can you change the alpha values, instead of 5, 10 % or...?

Do you have the confidence intervals for the correlation Matrix
(for example when having Y=f(X1, X2, X3), for
X1×X2
X1×X3
X1× Y
X2×X3
X2×Y
X3×Y)

?

Does it the s/t/prob values for each beta I value?
Find all posts by this user
Quote this message in a reply
04-27-2022, 03:29 PM (This post was last modified: 04-27-2022 03:58 PM by acser.)
Post: #18
RE: (50g) Working Multiple linear regression in English
(04-27-2022 03:27 PM)Gil Wrote:  I did not check, as I have not enough memory.

>>> You could always use Emu48 Smile

Can you change the alpha values, instead of 5, 10 % or...?

>>> Yes, it's in the code, so clumsy. Sad

Do you have the confidence intervals for the correlation Matrix
(for example when having Y=f(X1, X2, X3), for
X1×X2
X1×X3
X1× Y
X2×X3
X2×Y
X3×Y)

?

>>> No.

Does it the s/t/prob values for each beta I value?

>>> Yes, but they are not displayed.
Find all posts by this user
Quote this message in a reply
04-27-2022, 09:47 PM
Post: #19
RE: (50g) Working Multiple linear regression in English
"Can you change the alpha values, instead of 5, 10 % or...?
>>> Yes, it's in the code, so clumsy. Sad"

Instead of having 0.05 in your code (program P1), how about replacing its value in program P1 by the name of the variable (alpha : yellow key / Right Shift key / A key).

To change alpha or set its value to 10%,
just execute 0.1 'alpha' STO before running the program P1 or the other programs.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 6 Guest(s)