download logitfit.m
Language: Matlab
LOC: 35
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, Vb] = logitfit(y,x,C);
%LOGITFIT Fit a logistic regression model.
%
%     	  [b, Ib, Vb] = logitfit(y,X,C)
%
%	  Fit the model log(p/(1-p)) = X*b, where p is the probability 
%	  that y is 1 and not 0. Output b is vector of point estimates,  
%	  Ib is confidence intervals, and Vb is the estimated variance 
%	  matrix of b. Input C is confidence level for the confidence 
%	  intervals, default is 0.95.
%
%         If an intercept is not included in X it is automatically added 
%         as an extra column. Note that the intercept is then the last
%         coefficient, not the first!
%
%	  See also LODDS and LODDSINV.

%       Anders Holtsberg, 14-12-94
%       Copyright (c) Anders Holtsberg

if nargin<3 
   C = 0.95;
end
if size(y,2)>1
   error('Input y must be column vector');
end
n = length(y);
if sum(y==1|y==0) < n
   error('Hey, only 0 or 1 as response varable y')
end
one = ones(n,1);
if any(abs(one-x*(x\one)) > 1e-10)
   fprintf('   Intercept column added \n')
   x = [x, ones(n,1)];
end
nb = size(x,2);

b  = x\(4*y-2);

for i=1:50
   z  = x*b;
   g1 = 1+exp(-z);
   g0 = 1+exp(+z);
   df1 = -1 ./ g0;
   df0 = +1 ./ g1;
   df = sum(((y.*df1+(1-y).*df0)*ones(1,nb)) .* x)';
   ddf = (((1 ./ (g0+g1))*ones(1,nb)) .* x)'*x;
   b = b - (ddf\df);
   if all(abs(df)<0.0001), break; end;
end

if i== 50, error('No convergence'), end

logL = y.*log(g1) + (1-y).*log(g0);
Vb = inv(ddf);
lamda = qnorm(1-(1-C)/2);
Ib = lamda*sqrt(diag(Vb));
Ib = [b-Ib, b+Ib];

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