


%estimweibull.m

close all
clear all
s= RandStream('mt19937ar','Seed',0);
RandStream.setGlobalStream(s);
%
lambda=3;
r=2;
% Simulate 2000 Wei(r=2, lambda=3)
n=2000;
xx=wblrnd( lambda^(-1/r), r,[n 1]);
%In MATLAB's parametrization  of Weibull  distribution
% the scale parameter is  lambda^(-1/r)
%--
x = sort(xx);      i=(1:n)';
y = log( log(  (n+1)./(n +1 - i)  ));
b = regress(y, [ones(size(x)) log(x)]);
lambdahat= exp(b(1)) %3.0676
rhat=b(2)  %2.0371
% 
%Built in Weibull fits
parmhat = wblfit(x);
lambdahat = parmhat(1)^(-parmhat(2))  %3.1063
rhat = parmhat(2)  %2.0538