%box-cox

close all
clear all
%-----------------------------------
 disp('Figure figsal1-3.eps:Box-Cox Transform')
  lw = 3; 
  set(0, 'DefaultAxesFontSize', 17);
  fs = 17;
  msize = 20;

% See Exercise: Duchenne Muscular Dystrophy
% In the data file dmd.dat, the 4th column is pyruvate kinase. The 
% distribution is skewed to the right. We will find Box-Cox transform 
% to symmetrize the data (make it approximately normal).
% 

x=[14.5000   12.6992   15.2988   15.7988   12.8984   16.5977   12.8984   10.2988   11.6992 ...
   14.1992   15.2988   17.0977   12.1992   11.0996   13.1992    9.8984   11.8984   16.5977 ...
   16.3984   11.0000   13.5000   17.3984   12.0000   13.6992   14.0000   20.6992   10.2988 ...
   15.0996   15.2988   12.0000   15.5996   14.5996   15.3984   12.1992   17.5000   14.5000 ...
    8.8984   15.1992   17.0977    9.8984    7.2998   22.0000   13.0000   10.7988   17.0977 ...
   15.2988   10.5000   15.2988   16.1992    8.8984   16.3984    7.0000   17.0000    8.6992 ...
   31.8984    7.3994   10.8984   10.2988   10.2988   11.7988   18.1992  110.0000   16.5000 ...
   11.2988   10.0000   12.5000   22.1992   22.6992    8.0996   18.0977   11.7988   12.2988 ...
    7.8994   10.8984    9.2988   10.0000   14.0000    9.8984   15.2988   15.5000   10.3984 ...
   25.1992   27.0977   20.0977   23.7969   10.8984   18.2969   20.1992   11.7988    9.5996 ...
   16.0977   10.1992   16.7969   17.8984   10.8984   19.3984   10.6992   17.0977    5.8994 ...
    3.8999    5.0996   26.7969   11.8984    3.7998    2.7998    6.0996    7.5996   10.6992 ...
    3.5000    6.0000   25.5977   21.2969   12.7988   20.5977   18.7969   62.8984   41.5938 ...
   23.2969   21.5977   15.0996   16.8984   19.8984   63.6953   16.5977   16.0000   18.5977 ...
   16.0977   36.0000   51.5938   36.3984   32.1953   12.0996    8.7988   10.8984    5.2998 ...
   22.0000   20.8984    6.6992    9.6992    6.8994    4.3994    8.5996    6.0000    8.8984 ...
    6.3994    6.8994    5.5996    5.5996    8.0000   11.3984   10.0996   11.8984   21.5977 ...
   19.8984   73.0000    9.7988   12.0000   12.5996   16.3984   11.6992   14.0000   16.6992 ...
   22.2969   10.5996    5.7998   13.2988   14.3984   11.2988   20.2969   16.0977    8.2988 ...
   13.6992   21.0000   21.7969   14.1992   22.5977   10.1992   16.3984   49.0938   15.0996 ...
   12.6992   12.0996    8.7988    9.6992   11.0000   11.1992   17.3984   22.6992   12.8984 ...
   25.2969   33.8984   49.0938   18.7969   19.7969];


hist(x,12)
%print -depsc 'C:\BESTAT\Norm\Normeps\figsal1.eps'

figure(2)
n= length(x);
liks = [];
lambdas = [];
for lam=-1:0.05:0.6
   if lam ~= 0
       xl = (x.^lam - 1)/lam;
   else
       xl = log(x);
   end
   xlbar = mean(xl);
   lik = -n/2 * log( mean( (xl-xlbar).^2 )) + (lam -1)*sum(log(x));
   liks = [liks lik];
   lambdas =[lambdas lam];
end

plot(lambdas, liks,'.','markersize',msize)
hold on
plot(-0.15, -386.5199, 'ro')
axis tight
%print -depsc 'C:\BESTAT\Norm\Normeps\figsal2.eps'
tr = (x.^(-0.15) - 1)/(-0.15);
figure(3)
hist(tr,11)
%print -depsc 'C:\BESTAT\Norm\Normeps\figsal3.eps'
