Test if a data distribution follows a Gaussian distribution in MATLAB

后端 未结 3 734
被撕碎了的回忆
被撕碎了的回忆 2020-12-14 10:09

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

相关标签:
3条回答
  • 2020-12-14 10:28

    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
    
    0 讨论(0)
  • 2020-12-14 10:42

    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...

    0 讨论(0)
  • 2020-12-14 10:48

    Check this documentation page on all available hypothesis tests.

    From those, for your purpose you can use:

    • Chi-square goodness-of-fit test
    • Lilliefors test
    • z-test
    • t-test
    • Kolmogorov-Smirnov test

    ... among others

    You can also use some visual tests like:

    • hist
    • normplot
    • cdfplot
    0 讨论(0)
提交回复
热议问题