www.gusucode.com > stats 源码程序 matlab案例代码 > stats/TestDataForNormalDistributionUsingProbplotExample.m

    %% Test Data for Normal Distribution Using |probplot|
%

%%
% Generate sample data containing about 20% outliers in the tails.
% The left tail of the sample data contains 10 values
% randomly generated from an exponential distribution with parameter
% |mu = 1|. The right tail contains 10 values randomly generated from an
% exponential distribution with parameter |mu = 5|. The center of the
% sample data contains 80 values randomly generated from a standard normal
% distribution.
rng default  % For reproducibility
left_tail = -exprnd(1,10,1);
right_tail = exprnd(5,10,1);
center = randn(80,1);
data = [left_tail;center;right_tail];

%%
% Create a probability plot to assess whether the sample data comes from
% a normal distribution. Plot a _t_ location-scale curve on the same figure
% to compare with |data|.
figure;
probplot(data);
p = mle(data,'dist','tlo');
t = @(data,mu,sig,df)cdf('tlocationscale',data,mu,sig,df);
h = probplot(gca,t,p);
h.Color = 'r';
h.LineStyle = '-';
title('{\bf Probability Plot}')
legend('Data','Normal','t','Location','NW')

%%
% The plot shows that neither the normal line nor the _t_ location-scale
% curve fits the tails very well because of the outliers.