Code covered by the BSD License  

Highlights from
Reliable and Roubst Design

image thumbnail
from Reliable and Roubst Design by Stuart Kozola
MATLAB Code used in the Jan 2008 Digest Article

survivalFit(miles3,miles5,miles7)
function survivalFit(miles3,miles5,miles7)
%SURVIVALFIT    Create plot of datasets and fits
%   SURVIVALFIT(MILES3,MILES5,MILES7)
%   Creates a plot, similar to the plot in the main distribution fitting
%   window, using the data that you provide as input.  You can
%   apply this function to the same data you used with dfittool
%   or with different data.  You may want to edit the function to
%   customize the code and this help message.
%
%   Number of datasets:  3
%   Number of fits:  3

% This function was automatically generated on 08-Jan-2008 09:12:16
 
% Data from dataset "Damping Ratio 0.3":
%    Y = miles3
 
% Data from dataset "Damping Ratio 0.5":
%    Y = miles5
 
% Data from dataset "Damping Ratio 0.7":
%    Y = miles7
 
% Force all inputs to be column vectors
miles3 = miles3(:);
miles5 = miles5(:);
miles7 = miles7(:);

% Set up figure to receive datasets and fits
f_ = clf;
figure(f_);
set(f_,'Units','Pixels','Position',[654 334 680 469.45]);
legh_ = []; legt_ = {};   % handles and text for legend
ax_ = newplot;
set(ax_,'Box','on');
hold on;

% --- Plot data originally in dataset "Damping Ratio 0.3"
t_ = ~isnan(miles3);
Data_ = miles3(t_);
[Y_,X_] = ecdf(Data_,'Function','survivor'...
              );  % compute empirical function
h_ = stairs(X_,Y_);
set(h_,'Color',[0.333333 0 0.666667],'LineStyle','-', 'LineWidth',1);
xlabel('Data');
ylabel('Survivor function')
legh_(end+1) = h_;
legt_{end+1} = 'Damping Ratio 0.3';
% --- Plot data originally in dataset "Damping Ratio 0.5"
t_ = ~isnan(miles5);
Data_ = miles5(t_);
[Y_,X_] = ecdf(Data_,'Function','survivor'...
              );  % compute empirical function
h_ = stairs(X_,Y_);
set(h_,'Color',[0.333333 0.666667 0],'LineStyle','-', 'LineWidth',1);
xlabel('Data');
ylabel('Survivor function')
legh_(end+1) = h_;
legt_{end+1} = 'Damping Ratio 0.5';
% --- Plot data originally in dataset "Damping Ratio 0.7"
t_ = ~isnan(miles7);
Data_ = miles7(t_);
[Y_,X_] = ecdf(Data_,'Function','survivor'...
              );  % compute empirical function
h_ = stairs(X_,Y_);
set(h_,'Color',[0 0 0],'LineStyle','-', 'LineWidth',1);
xlabel('Data');
ylabel('Survivor function')
legh_(end+1) = h_;
legt_{end+1} = 'Damping Ratio 0.7';

% Nudge axis limits beyond data limits
xlim_ = get(ax_,'XLim');
if all(isfinite(xlim_))
   xlim_ = xlim_ + [-1 1] * 0.01 * diff(xlim_);
   set(ax_,'XLim',xlim_)
end

x_ = linspace(xlim_(1),xlim_(2),100);

% --- Create fit "Weibull Fit (Damping Ratio 0.3)"

% Fit this distribution to get parameter values
t_ = ~isnan(miles3);
Data_ = miles3(t_);
% To use parameter estimates from the original fit:
%     p_ = [ 197384.2484336, 3.968708696396];
p_ = wblfit(Data_, 0.05);
y_ = wblcdf(x_,p_(1), p_(2)); % compute cdf
y_ = 1 - y_; % convert to survivor function
h_ = plot(x_,y_,'Color',[1 0 0],...
          'LineStyle','-', 'LineWidth',2,...
          'Marker','none', 'MarkerSize',6);
legh_(end+1) = h_;
legt_{end+1} = 'Weibull Fit (Damping Ratio 0.3)';

% --- Create fit "Weibull Fit (Damping Ratio 0.5)"

% Fit this distribution to get parameter values
t_ = ~isnan(miles5);
Data_ = miles5(t_);
% To use parameter estimates from the original fit:
%     p_ = [ 164694.3864163, 49994.13306482];
pargs_ = cell(1,2);
[pargs_{:}] = normfit(Data_, 0.05);
p_ = [pargs_{:}];
y_ = normcdf(x_,p_(1), p_(2)); % compute cdf
y_ = 1 - y_; % convert to survivor function
h_ = plot(x_,y_,'Color',[0 0 1],...
          'LineStyle','-', 'LineWidth',2,...
          'Marker','none', 'MarkerSize',6);
legh_(end+1) = h_;
legt_{end+1} = 'Weibull Fit (Damping Ratio 0.5)';

% --- Create fit "Weibull Fit (Damping Ratio 0.7)"

% Fit this distribution to get parameter values
t_ = ~isnan(miles7);
Data_ = miles7(t_);
% To use parameter estimates from the original fit:
%     p_ = [ 145835.2832132, 3.627387845666];
p_ = wblfit(Data_, 0.05);
y_ = wblcdf(x_,p_(1), p_(2)); % compute cdf
y_ = 1 - y_; % convert to survivor function
h_ = plot(x_,y_,'Color',[0.666667 0.333333 0],...
          'LineStyle','-', 'LineWidth',2,...
          'Marker','none', 'MarkerSize',6);
legh_(end+1) = h_;
legt_{end+1} = 'Weibull Fit (Damping Ratio 0.7)';

hold off;
leginfo_ = {'Orientation', 'vertical', 'Location', 'NorthEast'}; 
h_ = legend(ax_,legh_,legt_,leginfo_{:});  % create legend
set(h_,'Interpreter','none');

Contact us at files@mathworks.com