download linreg.m
Language: Matlab
LOC: 43
Project Info
MatLinks/Chorus(matlinks)
Server: SourceForge
Type: cvs
...chest\copyleft\gpl\stixbox\
   bincoef.m
   cat2tbl.m
   ciboot.m
   ciquant.m
   cmpmod.m
   Contents.m
   contincy.m
   corr.m
   covboot.m
   covjack.m
   cvar.m
   datas1.m
   datas10.m
   datas11.m
   datas2.m
   datas3.m
   datas4.m
   datas5.m
   datas6.m
   datas7.m
   datas8.m
   datas9.m
   dbeta.m
   dbinom.m
   dchisq.m
   df.m
   dgamma.m
   dgumbel.m
   dhypg.m
   dlognorm.m
   dnorm.m
   dt.m
   dweib.m
   egumbel.m
   getdata.m
   histo.m
   identif5.m
   identify.m
   kaplamai.m
   ldiscrim.m
   linreg.m
   lodds.m
   loddsinv.m
   logitfit.m
   lsfit.m
   lsselect.m
   normmix.m
   octvinit.m
   pairs.m
   pbeta.m
   pbinom.m
   pchisq.m
   pf.m
   pgamma.m
   pgumbel.m
   phypg.m
   plognorm.m
   plotdens.m
   plotempd.m
   plotsym.m
   pnorm.m
   pt.m
   pweib.m
   qbeta.m
   qbinom.m
   qchisq.m
   qf.m
   qgamma.m
   qgumbel.m
   qhypg.m
   qlognorm.m
   qnorm.m
   qqgamma.m
   qqgumbel.m
   qqnorm.m
   qqplot.m
   qqweib.m
   qt.m
   quantile.m
   qweib.m
   ranktrf.m
   rbeta.m
   rbinom.m
   rboot.m
   rchisq.m
   Readme.m
   rf.m
   rgamma.m
   rgumbel.m
   rhypg.m
   rlognorm.m
   rnorm.m
   rt.m
   rweib.m
   spearman.m
   stdboot.m
   stdize.m
   stdjack.m
   stixdemo.m
   test1b.m
   test1n.m
   test1r.m
   test2n.m
   test2r.m

function [b, Ib, e, s, Is] = linreg(y,x,C,sym,pmax)
%LINREG   Linear or polynomial regression
%
%	  linreg(y,x)
%         [b, Ib, e, s, Is] = linreg(y,x,C,sym,pmax)
%
%         The output  b  is the point estimate of the parametars 
%         in the model  y = b(1)*x + b(2) + error.
%         The columns of  Ib  are the corresponding confidence 
%         intervals. The residuals are in  e. The standard deviation 
%	  of the residuals is  s.
%
%         A pointwise confidence band for the expected y-value is
%         plotted, as well as a dashed line which indicates the
%         prediction interval given x. The input  C  is the confidence
%	  which is 0.95 by default. C = []  gives no plotting
%         of confidence band or prediction band.
%
%	  Input sym is plotting symbol, with 'o' as default. For 
%	  polynomial regression give input  pmax  a desired value,  
%	  the model is then  y = [x^pmax, ... x^2, x, 1] * b' + error.
%
%         See also LSFIT and LSSELECT.

%       GPL Copyright (c) Anders Holtsberg, 1995, 1998

if nargin < 3, C = 0.95; end
if nargin < 4 | ~exist('sym'), sym = 'o'; end
if isempty(sym), sym = 'o'; end
if nargin < 5, pmax = 1; end

y = y(:);  
x = x(:);
if length(x) ~= length(y)
   error('Error in input format to linreg')
end
n = length(x);

X = ones(n,pmax+1);
for i = pmax:-1:1
    X(:,i) = x .* X(:,i+1);
end

[b, Ib, e, s, Is] = lsfit(y,X,C);

mn = 1.1*min(x)-0.1*max(x);
mx = 1.1*max(x)-0.1*min(x);
xx = linspace(mn,mx,50)';

V = xx(:,ones(1,pmax+1));
V = V .^ (ones(length(xx),1)*(pmax:-1:0));
yy = V*b;

h = ishold;
plot(x,y,sym)
hold on
plot(xx,yy)

if ~isempty(C)
   R = chol(X'*X);
   E = V/R;
   t = qt(1-(1-C)/2, n-pmax);
   d = sum((E.*E)')';

   dd = t*s*sqrt(d);
   ym = yy - dd;
   yp = yy + dd;

   dd1 = t*s*sqrt(1+d);
   ym1 = yy - dd1;
   yp1 = yy + dd1;

   plot(xx,ym)
   plot(xx,yp)
   plot(xx,ym1,'--')
   plot(xx,yp1,'--')
end

if ~h, hold off; end

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us