% 
%
clear all
close all force
  disp('Mice PO2')
  set(0, 'DefaultAxesFontSize', 16);
  lw =2.5;  fs = 16;  msize = 10;


         load 'C:\STAT\ANOVA\ANOVAdat\oxygen.dat';
%===========================u=
         noxygen=[oxygen(:,1)  2 * oxygen(:,2) + oxygen(:,3) ...
                     oxygen(:,4)  oxygen(:,5)];
         a=[1 diff( noxygen(:,1))' ];
         ind = find( a ~= 0 );
         nnoxy=[];
         alln=16*371;
            for ii=1:alln
                if noxygen(ii,2)==1
                   nnoxy=[nnoxy; noxygen(ii,:)];
                end
            end
            for ii=1:alln
                if noxygen(ii,2)==2
                   nnoxy=[nnoxy; noxygen(ii,:)];
                end 
            end
            for ii=1:alln
                if noxygen(ii,2)==3
                   nnoxy=[nnoxy; noxygen(ii,:)];
                end
            end
%==============================
         matw=[]; matt=[]; matr=[];
         le=length(ind);
         for i = 1: le
            indc=ind(i); indt=indc+370;
            matr=[matr   nnoxy(indc:indt,4) ];
         end
howlong = 512; % fdr=0.05;
trss=[6 5 5];
matri = matr';
n1=trss(1); n2=trss(2); n3=trss(3); 
  howmuch=365;
  n=sum(trss); x=(1:howmuch) * 0.1667 ;
%============== fanova in the time domain=========================
[mtd, trtd, msttd, msetd, ftd]=fanova(matri, trss);
treat1=trtd(1,1:howmuch); 
treat2=trtd(2,1:howmuch); 
treat3=trtd(3,1:howmuch);
figure(2)
clf reset;
set(0, 'DefaultAxesFontSize', 14);
set(0, 'DefaultAxesFontName', 'Times')
subplot(2,2,1); plot(x,mtd(1:howmuch), 'k-');
 axis tight;
 hold on
 plot([20 20],[-90 90], 'r--');
xlabel('t (min)');
ylabel('\mu(t)');
subplot(2,2,2); plot(x, treat1, 'k-');
 axis tight;
hold on
 plot([20 20],[-90 90], 'r--');
xlabel('t (min)');
ylabel('\alpha_1(t)');
subplot(2,2,3); plot(x, treat2, 'k-');
 axis tight;
hold on
 plot([20 20],[-90 90], 'r--');
xlabel('t (min)');
ylabel('\alpha_2(t)');
subplot(2,2,4); plot(x, treat3, 'k-');
 axis tight;
hold on
 plot([20 20],[-90 90], 'r--');
xlabel('t (min)');
ylabel('\alpha_3(t)');
%------------------------------------------------
%print -depsc 'C:/BESTAT/ANOVA/ANOVAeps/figTD.eps'
%------------------------------------------------
figure(1)
clf reset;
set(0, 'DefaultAxesFontSize', 8);
set(0, 'DefaultAxesFontName', 'Times')
treatment=[1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3];
for i = 1:16
if treatment(i)==1
      label='Treatment \bf 1';
elseif treatment(i)==2
      label='Treatment \bf 2';
else  label='Treatment \bf 3';
end
subplot(4,4,i); plot(x, matri(i,1:howmuch), 'k-');
 axis tight;
hold on
 plot([20 20],[0 90], 'r--');
xlabel('t (min)');
ylabel(label);
end
%-------------------------------------
%print -deps 'C:/BESTAT/ANOVA/ANOVAeps/figDATA.eps'
%-------------------------------------

