 %Cellular Differentiation Data
clear all
close all
 disp('Poisson Regression:Cellular Differentiation Data')

%-----------------figure defaults
lw = 2.5;  
set(0, 'DefaultAxesFontSize', 16);
fs = 15;
msize = 8;


load 'C:\Springer\Logistic\Logisticdat\celular.dat'

number = celular(:,1);
TNF =    celular(:,2);
IFN =    celular(:,3);
[b, dev, stats] = glmfit([TNF IFN  TNF.*IFN],number,'poisson','link','log')
%         stats.dfe %   degrees of freedom for errors        
%         stats.s   %   theoretical or estimated dispersion parameter
%         stats.sfit     %   estimated dispersion parameter
%         stats.se      %standard errors of coefficient estimates B
%         stats.coeffcorr% correlation matrix for B
%         stats.covb%      estimated covariance matrix for B
%         stats.t%         t statistics for B
%         stats.p%         p-values for B
%         stats.resid %     residuals
%         stats.residp%    Pearson residuals
%         stats.residd%    deviance residuals
%         stats.resida%    Anscombe residuals

format long
b
sse = stats.se
stats.dfe
stats.s
stats.sfit
format short

ws = b./(stats.sfit * stats.se)
pva= 1-chi2cdf(ws.^2, 1)

figure(1)
lin = b(1) + b(2)*TNF  + b(3)*IFN + b(4)* TNF.*IFN;
plot(lin, number,'o',...
'MarkerSize',msize, 'MarkerEdgeColor','k', 'MarkerFaceColor','g')
              
  xx = 3.3:0.01:5.4;
  imp =  exp(xx);
  hold on
  plot(xx, imp,'r-','LineWidth',lw)
  xlabel('Linear Predictor: b_0 + b_1*TNF + b_{2} *IFN + b_3 TNF*IFN')
  ylabel('Number of Cells')
  %print -depsc 'C:\Springer\Logistic\Logisticeps\celular.eps'
  
  
  [bl, devl, statsl] = glmfit([TNF IFN],number,'poisson','link','log') 
  
     devl - dev % difference of deviances  160.1603 - 142.3853 =  17.7750
     pval = 1-chi2cdf(devl,1)     %0
bl