kstest.m

来自「kriging算法」· M 代码 · 共 49 行

M
49
字号
function [d, prob] = kstest (data) 

%	   [d, prob] = kstest (data) 
%
%	KOLMOGOROV-SMIRNOV ONE SAMPLE TEST 
%	USING STANDARD NORMAL DISTRIBUTION
%
% Function based on the ksone.f Fortran Numerical Recipes routine.
% The ksone.f subroutine has been modified to be linked with the 
% matlab environment through ksoneg.f.
%
% data: variable samples
% d:    K-S statistique D corresponding to the maximum difference
%	between the sample distribution and the normat distribution
% prob: significance level of d.  Small values of prob show that the 
%	cumulative sample distribution is significantly different 
% 	from the normal one.
%
% Critical values of d are given in TABLE B (page 404) of 
% Legendre, L. and P. Legendre (1983). Numerical Ecology. Elsevier, Amsterdam, 419 p.
%
% To see what the sample ditribution looks like: hist(data);
%
% C. Lafleur 16/08/96

% Standardisation of the sampled variable (data)

  x = (data - mean(data)) / std(data);

% Sort data by ascending order

  y = sort(x);

% Calculation of the cumulative normal distribution corresponding to y

  l = length(y);
  k = 1 / sqrt(2*pi);

  for i = 1:l
    xx = (-10:0.01:y(i));
    yy  = exp(-(xx.^2)/2);
    t(i) = k .* trapz(xx,yy);
  end

% Kolmogorov-Smirnov Test

  [d, prob] = ksone (y(:),l,t(:));
  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?