Open in the MATLAB editor: g08ch_example
function g08ch_example fprintf('g08ch example results\n\n'); x = [0.4782745, 1.2858962, 1.1163891, 2.0410619, 2.2648109, 0.0833660, ... 1.2527554, 0.4031288, 0.7808981, 0.1977674, 3.2539440, 1.8113504, ... 1.2279834, 3.9178773, 1.4494309, 0.1358438, 1.8061778, 6.0441929, ... 0.9671624, 3.2035042, 0.8067364, 0.4179364, 3.5351774, 0.3975414, ... 0.6120960, 0.1332589]; n = int64(numel(x)); % Maximum likelihood estimate of mean beta = mean(x); % PIT, using exponential CDF with mean beta y = 1 - exp(-x/beta); % Let g08ch sort the (approximately) uniform variates issort = false; % Calculate a-squared [a2, y, ifail] = g08ch( ... issort, y); aa2 = (1+0.6/numel(y))*a2; % Number of simulations nsim = int64(888); % Initialize the base generator to a repeatable sequence seed = [int64(206033)]; genid = int64(1); subid = int64(-1); [state, ifail] = g05kf( ... genid, subid, seed); [state, xsim, ifail] = g05sf( ... n*nsim, beta, state); % Simulations loop nupper = 0; for j=1:nsim k = (j-1)*n; x = xsim(k+1:k+n); % Maximum likelihood estimate of mean sbeta = mean(x); % PIT y = 1 - exp(-x/sbeta); % Calculate a-squared [sa2, y, ifail] = g08ch( ... issort, y); if sa2 > aa2 nupper = nupper + 1; end end % Simulated upper tail probability value p = nupper/(nsim+1); % Results fprintf('H0: data from exponential distribution with mean %10.4e\n', beta); fprintf('Test statistic, A-squared: %8.4f\n', a2); fprintf('Upper tail probability: %8.4f\n', p);
g08ch example results H0: data from exponential distribution with mean 1.5240e+00 Test statistic, A-squared: 0.1616 Upper tail probability: 1.0000