17

I have some data points and their mean point. I need to find whether those data points (with that mean) follows a Gaussian distribution. Is there a function in MATLAB which can do that kind of a test? Or do I need to write a test of my own?

I tried looking at different statistical functions provided by MATLAB. I am very new to MATLAB so I might have overlooked the right function.

cheers

4

3 回答 3

15

Check this documentation page on all available hypothesis tests.

From those, for your purpose you can use:

... among others

You can also use some visual tests like:

于 2009-12-10T20:57:27.100 回答
6

I like Spiegelhalter's test (D. J. Spiegelhalter, 'Diagnostic tests of distributional shape,' Biometrika, 1983):

function pval = spiegel_test(x)
% compute pvalue under null of x normally distributed;
% x should be a vector;
xm = mean(x);
xs = std(x);
xz = (x - xm) ./ xs;
xz2 = xz.^2;
N = sum(xz2 .* log(xz2));
n = numel(x);
ts = (N - 0.73 * n) / (0.8969 * sqrt(n)); %under the null, ts ~ N(0,1)
pval = 1 - abs(erf(ts / sqrt(2)));    %2-sided test.

whenever hacking statistical tests, alway test them under the null! here's a simple example:

pvals = nan(10000,1);
for j=1:numel(pvals);
pvals(j) = spiegel_test(randn(300,1));
end
nnz(pvals < 0.05) ./ numel(pvals)

I get the results:

ans =    
   0.0505

Similarly

nnz(pvals > 0.95) ./ numel(pvals)

I get

ans = 
   0.0475
于 2009-12-10T20:55:13.487 回答
5

For testing in general, look up the Kolmogorov-Smirnov Test, also in the Stats Toolbox, as kstest and the two-sample version: kstest2 . You feed it your empirical data, (and the data from a possible function, like the gaussian, etc...) then it tests the likelihood that your sample was pulled from the normal distribution (or the one you supplied for the two-sample version)... The nicety is that it'll work for any possible distributions...

于 2009-12-10T19:49:13.860 回答