   
clear all
close all


disp('Some Images for RanVar Chapter')
  lw = 3;
  set(0, 'DefaultAxesFontSize', 16);
  fs = 15;
  msize = 10;
% end of preabmle--------------------------------------
  disp('Exponentials')
  lw = 3; 
  set(0, 'DefaultAxesFontSize', 16);
  fs = 16;
  msize = 10;

%  RANVAR exponentials figure \ref{fig:exppdfcdf}
   figure(1)
   time=0:0.01:30;
   pdf = exppdf(time, 1/0.05);
   plot(time, pdf,'b-','linewidth',lw);
   xlabel('Time (in years)')
   ylabel('PDF')
  %  print -depsc 'C:\BESTAT\RanVar\RanVareps\exppdf.eps'

   cdf = expcdf(time, 1/0.05);
   figure(2)
   plot(time, cdf, 'b-','linewidth',lw);
   xlabel('Time (in years)')
   ylabel('CDF')
   
  % print -depsc 'C:\BESTAT\RanVar\RanVareps\expcdf.eps'

 %%  
%  -----Gamma function densities ------
clear all
close all
disp('Gamma')
  lw = 2; 
  set(0, 'DefaultAxesFontSize', 16);
  fs = 15;
  msize = 10;

t = 0:0.0001:8;
y = gamma(t);
figure(1)
semilogy(t, y, 'linewidth', lw)
hold on
semilogy(floor(t), gamma(floor(t)), 'ro', 'Markersize',8,...
'MarkerFaceColor','r','MarkerEdgeColor','b')
axis([0 8 0.5 10000])
xlabel('x'); ylabel('\Gamma(x)')
% print -depsc 'C:\BESTAT\RanVar\RanVareps\gammafun.eps'
   
%   

xx=0:0.001:15;

figure(2)
yy1 = gampdf(xx, 1, 3);
plot(xx, yy1,'b-', 'linewidth',lw)
yy2 = gampdf(xx, 2, 1.5);
hold on
plot(xx, yy2, 'r-', 'linewidth',lw)
yy3 = gampdf(xx, 20, 0.5);
plot(xx, yy3, 'g-','linewidth',lw)
axis([0 15 0 0.35])
legend('\it Ga(1, 1/3)','\it Ga(2, 2/3)','\it Ga(20,2)')
   xlabel('x')
   ylabel('PDF')

%print -depsc 'C:\BESTAT\RanVar\RanVareps\gammapdfs.eps'
   
   
%
clear all
close all
disp('Beta')
  lw = 2; 
  set(0, 'DefaultAxesFontSize', 16);
  fs = 15;
  msize = 10;

  figure(1)
xx = 0:0.0001:1;
subplot(3,3,1)
  yy1 = betapdf(xx, 1/2, 1/2);
  plot(xx, yy1, 'linewidth',lw)
  axis([0 1 0 5])
subplot(3,3,2)
  yy1 = betapdf(xx, 1, 1);
  plot(xx, yy1, 'linewidth',lw)
  axis([0 1 0 1.1])
subplot(3,3,3)
  yy1 = betapdf(xx, 2, 2);
  plot(xx, yy1, 'linewidth',lw)
  axis([0 1 0 1.7])
subplot(3,3,4)
  yy1 = betapdf(xx, 10, 10);
  plot(xx, yy1, 'linewidth',lw)
subplot(3,3,5)
  yy1 = betapdf(xx, 1, 5);
  plot(xx, yy1, 'linewidth',lw)
  axis([0 1 0 5.5])
subplot(3,3,6)
  yy1 = betapdf(xx, 1, 0.4);
  plot(xx, yy1, 'linewidth',lw)
  axis([0 1 0 5.5])
subplot(3,3,7)
  yy1 = betapdf(xx, 3, 5);
  plot(xx, yy1, 'linewidth',lw)
  axis([0 1 0 2.7])
subplot(3,3,8)
  yy1 = betapdf(xx, 50, 30);
  plot(xx, yy1, 'linewidth',lw)
  axis([0 1 0 8])
subplot(3,3,9)
  yy1 = betapdf(xx, 5000, 3000);
  plot(xx, yy1, 'linewidth',lw)
  axis([0 1 0 70])
%print -depsc 'C:\Springer\RanVar\RanVareps\betapdfs.eps'
% 
clear all
close all
disp('Logistic')
  lw = 3; 
  set(0, 'DefaultAxesFontSize', 16);
  fs = 15;
  msize = 10;
%
x = -6:0.01:6;
fx = exp(x)./(1 + exp(x)).^2;
ffx = exp(x)./(1 + exp(x));
figure(1)
  plot(x, fx, 'linewidth',lw)
   hold on
  plot(x, normpdf(x,0, pi/sqrt(3)),'r:', 'linewidth',lw)
  legend('logistic','normal')
  xlabel('x'); ylabel('PDF')
% print -depsc 'C:\BESTAT\RanVar\RanVareps\logipdf.eps'

figure(2)
  plot(x, ffx, 'linewidth',lw) 
   hold on
  plot(x, normcdf(x,0, pi/sqrt(3)),'r:', 'linewidth',lw)
  legend('logistic','normal',2)
   xlabel('x'); ylabel('CDF')
% print -depsc 'C:\BESTAT\RanVar\RanVareps\logicdf.eps'

  
  % 
  
  close all
  lw=2
x = -3.5:0.01:3.5
fx = normpdf(x);
ffx =normcdf(x);
figure(1)
  plot(x, fx, 'linewidth',lw) 
  xlabel('x'); ylabel('PDF')
  
  axis tight
 %  print -depsc 'C:\BESTAT\RanVar\RanVareps\normalpdf.eps'
figure(2)
  plot(x, ffx, 'linewidth',lw) 
  xlabel('x'); ylabel('CDF')
  axis tight
 % print -depsc 'C:\BESTAT\RanVar\RanVareps\normalcdf.eps'

  %%
  close all
  clear all
  disp('Bivariate Normal')
  lw = 3; 
  set(0, 'DefaultAxesFontSize', 16);
  fs = 15;
  msize = 10;

figure(1)
mu = [-1 2];
Sigma = [3 -0.9; -0.9 1];
x = (mu(1)-5):0.2:(mu(1)+5); y = (mu(2)-3):0.1:(mu(2)+3);
[X,Y] = meshgrid(x,y);
f = mvnpdf([X(:) Y(:)],mu,Sigma);
f = reshape(f,length(y),length(x));
surf(x,y,f);
axis([-6 4 -1 5 0 .1])
xlabel('x'); ylabel('y'); 
%print -depsc 'C:\Springer\RanVar\RanVareps\mvnpdf.eps'
figure(2)
contour(x,y,f,[.001 .01 .05 .1],'LineWidth',2);
xlabel('x'); ylabel('y');
%print -depsc 'C:\Springer\RanVar\RanVareps\mvncon.eps' 
 