clear all
close all force
%===================================================
% Insulin 
%===================================================
% Insulin has anti-inflammatory effects, as evaluated by its ability to reduce
% the plasma concentrations of cytokines. H The cytokine content in several 
% organs after endotoxin (lipopolysaccharide, LPS) exposure and the effect
% of hyperinsulinaemia was examined in a porcine model, Brix-Christensen et al. (2005).
% All animals (35-40kg) were subject to general anaesthesia and ventilated for 570 minutes.
% There were two possible interventions:
% 
% LPS: Lipopolysaccharide infusion for 180 minutes.
% 
% HEC: Hyperinsulinemic Euglycemic Clamp in 570 minutes (from start). Insulin was infused
% with constant rate and plasma glucose was clamped at a certain level by infusion of glucose.
% 
% LPS  induces a systemic inflammation (make the animals sick) and HEC  acts as
% a treatment. There were four experimental cells: (1) Only anaesthesia(No HEC, No LPS), 
% (2) HEC, (3) LPS, and (4) HEC and LPS.
% 
% The responses are levels of interleukin-10 (IL-10) in the kidney after 330 minutes are given.
% The table correspond to balanced design $n=8$ although the original experiment was unbalanced
% with 10 animals in group 1, 9 in group 2, 10 in group 3, and 9 in group 4.

% 
% IL-10 measurements in the liver after 570 minutes are given for  LPS (no=1, yes=2) and
% HEC (no=1, yes=2).

  disp('INSULIN')
  lw =2.5; 
  set(0, 'DefaultAxesFontSize', 16);
  fs = 15;
  msize = 10;
close all
data2 = [...       %columns: IL10  LPS  HEC
7.0607  1 1;...
2.6168  1 1;...
4.3489  1 1;...
3.6356  1 1;...
4.7510  1 1;...
2.9530  1 1;...
3.6137  1 1;...
5.6969  1 1;...    
3.0693  1 2;...
1.6489  1 2;...
2.9160  1 2;...
2.9149  1 2;...
2.1102  1 2;...
3.1004  1 2;...  
4.1170  1 2;...
3.0229  1 2;...  
3.6911  2 1;...
4.3933  2 1;...
6.0513  2 1;...
4.2559  2 1;...
4.5554  2 1;...
3.8447  2 1;...
1.3590  2 1;...
2.1449  2 1;...  
2.4159  2 2;...
3.1493  2 2;... 
4.4462  2 2;...
2.8545  2 2;...
1.8944  2 2;...
3.5133  2 2;...
4.6254  2 2;...
3.8967  2 2];  

IL10 = data2(:,1);  LPS=data2(:,2);  HEC=data2(:,3);
[p table stats terms] = anovan( IL10, {LPS,HEC},'varnames',{'LPS','HEC'}, ... 
    'model','interaction')
cell11 = mean(data2( 1: 8,1))   %L1 H1
cell12 = mean(data2( 9:16,1))   %L1 H2
cell21 = mean(data2(17:24,1))   %L2 H1
cell22 = mean(data2(25:32,1))   %L2 H2

figure;
plot([1 2],[cell11 cell12],'o','markersize',10, 'MarkerEdgeColor','k',...
                'MarkerFaceColor','r') 
hold on
plot([1 2],[cell11 cell12],'r-', 'linewidth',3)
plot([1 2],[cell21 cell22],'o','markersize',10, 'MarkerEdgeColor','k',...
                'MarkerFaceColor','k') 
plot([1 2],[cell21 cell22],'k-', 'linewidth',3)
title('Lines for LPS=1 (red) and LPS = 2 (black)')
xlabel('HEC')
axis([1 2 0 5])
%print -depsc 'C:\BESTAT\ANOVA\ANOVAeps\lineshec1.eps'
figure;
plot([1 2],[cell11 cell21],'o','markersize',10, 'MarkerEdgeColor','k',...
                'MarkerFaceColor','r') 
hold on
plot([1 2],[cell11 cell21],'r-','linewidth',3)
plot([1 2],[cell12 cell22],'o','markersize',10, 'MarkerEdgeColor','k',...
                'MarkerFaceColor','k') 
plot([1 2],[cell12 cell22],'k-','linewidth',3)
title('Lines for HEC=1 (red) and HEC = 2 (black)')
xlabel('LPS')
axis([1 2 0 5])
%print -depsc 'C:\BESTAT\ANOVA\ANOVAeps\lineshec2.eps'

%
SSA = table{2,2}; SSB = table{3,2}; SSAB=table{4,2}; SSE=table{5,2}; SST = table{6,2};

%Display bar a bar graph of anova table
H=figure;
set(H,'Position',[400 400 400 400]);
y=[0 0 1 1];
hold on
h1=fill([0 SST SST 0],y,'c');
y=y+1;
h2=fill([0 SSA SSA 0],y,'y');
h3=fill([0 SSB SSB 0]+SSA,y,'r');
h4=fill([0 SSAB SSAB 0]+SSA+SSB,y,'g');
h5=fill([0 SSE SSE 0]+SSA+SSB+SSAB,y,'b');
y=y+1;
h6=fill([0 SST SST 0],y,'w');
hold off
legend([h1 h2 h3 h4 h5],'SST','SSA','SSB','SSAB','SSE','Location','NorthEast')
title('Sums of Squares')
axis tight
%print -depsc 'C:\BESTAT\ANOVA\ANOVAeps\splithec.eps'

%%
figure;
multcompare(stats,'dimension',1)
figure;
multcompare(stats,'dimension',2)







