📄 kolmog.m
字号:
%#
%# function [ks,kscrit]=kolmog(x,alpha);
%#
%# AIM: Kolmogorov-Smirnov test to check if a set of observations are
%# normally distributed.
%#
%# PRINCIPLE: The test consists in determining the largest difference between
%# two cumulative relative frequency distributions: the observed
%# distribution and the expected (normal) distribution. The test
%# is only applicable to continuous distributions.
%#
%# REFERENCE: "Handbook of Chemometrics and Qualimetrics, Part A"
%# Massart, Vandeginste, Buydens, De Jong, Lewi, Smeyers-Verbeke
%# Elsevier, 1997, p.117.
%#
%# INPUT: x: Vector of observations (row- or column-vector).
%# alpha Critical level to apply the test (0.1, 0.05 or 0.01).
%# Ex: alpha=0.05 --> Test at the 5% level
%#
%# OUTPUT: ks: The calculated value for the test.
%# kscrit: The tabulated value for the test.
%# If ks < kscrit, the observations can be considered as
%# normally distributed, otherwise not.
%#
%# SUBROUTINES: pietstat.dll: Dynamic link library containing the statistical
%# table for the one-sided normal test.
%# kolsmir.mat: Matrix containing tabulated values for the
%# Kolmogorov-Smirnov test.
%#
%# AUTHOR: Frederic Despagne
%# Copyright (c) 1998 for ChemoAC
%# Dienst FABI, Vrije Universiteit Brussels
%# Laarbeeklaan 103 Jette
%#
%# VERSION: 1.1 (28/12/1998)
%#
%# TEST:
%#
function [ks,kscrit]=kolmog(x,alpha);
load kolsmir
x = sort(x); % Observations sorted in ascending order.
if alpha == 0.1;
col = 2;
elseif alpha == 0.05
col = 3;
else
col = 4;
end
[a,b] = size(x);
if min([a b]) ~= 1
error('Observations must be input in a row- or column-vector, not in matrix')
end
n = length(x); % Number of observations.
mx = mean(x); % Mean of observations.
stdx = std(x); % Standard deviation of observations.
z = (x-mx)/stdx; % Vector of standardised deviations from the mean.
for i=1:n % Determination of cumulative relative expected frequencies.
if z(i) < 0
FE(i) = pietstat(13,z(i));
else
FE(i) = 1-pietstat(13,z(i));
end
FO(i) = i/n;
end
d = abs(FO-FE); % Differences between the two distributions.
maxd = max(d);
FOm = zeros(size(FO));
FOm(2:n) = FO(1:n-1);
dm = abs(FOm-FE);
maxdm = max(dm);
ks = max([maxd maxdm]); % Calculated test value.
index = find(kstable(:,1)==n);
if isempty(index)
if col == 2
kscrit = 0.84*sqrt(n);
elseif col == 3
kscrit = 0.9*sqrt(n);
else
kscrit = 1.05*sqrt(n);
end
else
kscrit = kstable(index,col);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -