Post Reply 
(50g) Working Multiple linear regression in English
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
Post Reply 


Messages In This Thread
RE: (50g) Working Multiple linear regression in English - acser - 04-19-2022 03:42 AM



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