www.gusucode.com > stats 源码程序 matlab案例代码 > stats/GeneratingDataUsingFlexibleFamiliesOfDistributionsExample.m
%% Generating Data Using Flexible Families of Distributions % This example shows how to generate data using the Pearson and Johnson % systems of distributions. % Copyright 2015 The MathWorks, Inc. %% Load Data and Plot load carbig MPG = MPG(~isnan(MPG)); histogram(MPG,15) %% Compute Sample Moments moments = {mean(MPG),std(MPG),skewness(MPG),kurtosis(MPG)}; rng default % For reproducibility [r,type] = pearsrnd(moments{:},10000,1); %% Display Pearson Distribution Type type %% Plot Empirical Data and Pearson Model ecdf(MPG); [Fi,xi] = ecdf(r); hold on; stairs(xi,Fi,'r'); hold off %% Determine Quantiles for Transformation probs = normcdf([-1.5 -0.5 0.5 1.5]) %% Compute Quantile Values quantiles = quantile(MPG,probs) %% Define Johnson Distribution [r1,type] = johnsrnd(quantiles,10000,1); %% Display Johnson Distribution Type type %% Plot Empirical Data and Johnson Model ecdf(MPG); [Fi,xi] = ecdf(r1); hold on; stairs(xi,Fi,'r'); hold off %% Adjust Quantiles for Right Tail Matching qnorm = [-.5 .25 1 1.75]; probs = normcdf(qnorm); qemp = quantile(MPG,probs); r2 = johnsrnd([qnorm; qemp],10000,1); %% Plot Adjusted Quantiles [Fj,xj] = ecdf(r2); hold on; stairs(xj,Fj,'g'); hold off