(38G) LSQS Linear Fit & Multiple Linear Regression Programme - Printable Version +- HP Forums ( https://www.hpmuseum.org/forum)+-- Forum: HP Software Libraries ( /forum-10.html)+--- Forum: General Software Library ( /forum-13.html)+--- Thread: (38G) LSQS Linear Fit & Multiple Linear Regression Programme ( /thread-3663.html) |

(38G) LSQS Linear Fit & Multiple Linear Regression Programme - Gerald H - 04-18-2015 10:12 AM
So here we have a useful programme called LSQS. If you have a body of n vector observations & wish to fit your data in some linear relationship a*V1+b*V2+c*V3.....=V enter V1 in the first column of M1, V2 in the second column of M1....Vn in the nth column & V in the n+1th column. The programme LSQS calculates the values of co-efficients a,b,c.... such that the errors in the resulting values of V are minimised. The co-efficients are returned in Ans in Home view. LSQS SIZE(M1)►L1: Ans(1)►R: L1(2)►C: M1►M2: DELCOL M2;C: SUB M3;M1;{1,C};{R,C}: TRN(M2): INVERSE(Ans*M2)*Ans*(M3*[1]): RE: HP 38G: LSQS Linear Fit & Multiple Linear Regression Programme - Gerald H - 04-19-2015 09:06 AM
If you want a constant in your linear regression like this C+a*V1+b*V2+c*V3.....=V then use the programme MLR below. Constant & regression co-efficients are returned in Ans & M5, your data remains unchanged in M1. MLR M1►M4: SIZE(M1): MAKEMAT(1,Ans(1),1)*[1]: ADDCOL M1;Ans;1: RUN LSQS: Ans►M5: M4►M1: M5: |