%  MATLAB FUNCTION s322e16b.m, USED BY s322e16a.m
%  TO DO TRANSFORMATION, AND MAKE PLOT
%  FOR INTERACTIVE BOX-COX TRANSFORMATION EXAMPLE
%  FROM s322eg16.m


%  DRAW EVERYTHING INTO FIGURE 2
figure(2) ;
clf
          %  THIS CLEAR GETS RID OF ANY STUFF FROM OTHER PART


subplot(2,2,1) ;
  plot(xdat,ydat,'+') ;
          %  PUTS RAW DATA SCATTERPLOT IN UPPER LEFT
    title('Raw Data') ;

%  DO TRANSFORMATION OF X'S
if abs(lamx) < 10^(-10) ;
          %  TRANSFO PARAMETER IS ESSENTIALLY 0, SO USE LOG TRANSFORM
  txdat = log(xdat) ;
else ;    %  DO POWER TRANSFORM
  txdat = (xdat.^lamx - 1) ./ lamx ;
end ;

subplot(2,2,2) ;
  plot(txdat,ydat,'+') ;
          %  PUT TRANSFORM OF X'S ONLY IN UPPER RIGHT
    title('Xs Transformed') ;

%  DO TRANSFORMATION OF Y'S
if abs(lamy) < 10^(-10) ;
          %  TRANSFO PARAMETER IS ESSENTIALLY 0, SO USE LOG TRANSFORM
  tydat = log(ydat) ;
else ;    %  DO POWER TRANSFORM
  tydat = (ydat.^lamy - 1) ./ lamy ;
end ;

subplot(2,2,3) ;
  plot(xdat,tydat,'+') ;
          %  PUT TRANSFORM OF Y'S ONLY IN LOWER LEFT
    title('Ys Transformed') ;

subplot(2,2,4) ;
  plot(txdat,tydat,'+') ;
          %  PUT TRANSFORM OF BOTH VARIABLES IN LOWER RIGHT
    title('Xs & Ys Transformed') ;
