help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: regression functions available?


From: Ted Harding
Subject: Re: regression functions available?
Date: Wed, 26 Mar 1997 17:23:01 +0000 (GMT)

( 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
> address@hidden

Try this one.

Ted.                                    (address@hidden)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]