regression functions available?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

regression functions available?

Tom Goles

Hi,
Can someone please tell me if there are any regression (i.e. simple
regression and multiple regression) functions available for octave
and if so could you please point me to that site?
Thanks very much for any info.
Tom Goles
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: regression functions available?

Ted.Harding
( Re Message From: Tom Goles )

>
> Status:  
>
>
> Hi,
> Can someone please tell me if there are any regression (i.e. simple
> regression and multiple regression) functions available for octave
> and if so could you please point me to that site?
> Thanks very much for any info.
> Tom Goles
> [hidden email]

Try this one.

Ted.                                    ([hidden email])
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function [a,b,C,fit,res]=regress(y,X,NoInt)
#  [a,b,C,fit,res] = regress(y,X,NoInt)
#  NoInt is optional
#  NoInt=1 suppresses intercept (i.e. forces regression through origin).
#  Model is   y = a + X*b + e   (a=0 if NoInt=1).
#  y is col-vector, b is col-vector.

if nargin<2
  error('Must have at least 2 args: [a,b,C,fit,res] = regress(y,X,{NoInt})')
  return
endif
if nargin==2, NoInt=0; endif
[r,c]=size(X);
if ~NoInt
  X=[ones(r,1) X]; c=c+1;
endif
K=inv(X'*X);
H=K*X';
P=X*H;
Q=eye(r)-P;
t=H*y;
if ~NoInt
  a=t(1);
  b=t(2:c);
else
  a=0;
  b=t;
endif
df=r-c;
res=Q*y;
fit=X*t;
C=(res'*res/df)*K;
endfunction