
%
% clean the working space and close all open figures
clear all
close all

  disp('Exponential Survival Time: Melanoma')
  lw = 2; 
  set(0, 'DefaultAxesFontSize', 14);
  fs = 14;
  msize = 10;
% end of preabmle--------------------------------------
   % In the context of cancer survivability,
   % for women the highest five-year survival rate (90 per cent)
   % was for malignant melanoma of the skin.
   % ( http://info.cancerresearchuk.org/cancerstats/survival/latestrates/)
   % Assume that survival time T is exponential with unknown rate parameter 
   % lambda. 
   %
   % Using quantiles, determine  lambda. 
   % 
   %P(T > 5) = 0.90 -> exp(-5 *  lambda)=0.90
   lambda = - log(0.90)/5 
   %lambda = 0.0211, rounded  to 0.02
   
   %Find the probability that the survival time exceeds 10 years.
   % (a) Directly, 1 - F(10)
   1 - (1 - exp(- 10*0.02))     % 0.8187
   % (b) using MATLAB's cdf.  % note MATLAB
   % uses the 'scale' parameter, not the 'rate' parameter.
   1 - expcdf(10, 1/0.02)
     
   % Figures of survival curve, pdf, and cdf
    figure(1)
    time=0:0.01:40;
    cdf = expcdf(time, 1/0.02);
    plot(time, 1-cdf, 'k-','linewidth',lw);
  
   
   
   figure(2)
   time=0:0.01:40; 
   pdf = exppdf(time, 1/0.02); 
   plot(time, pdf,'b-','linewidth',lw); 
    figure(3)
   cdf = expcdf(time, 1/0.02);
   plot(time, cdf, 'b-','linewidth',lw);
   

