File:KuiperTestVisualization 2Sample.png

From testwiki
Jump to navigation Jump to search
    Original file (560 × 420 pixels, file size: 23 KB, MIME type: image/png)

    This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

    Summary

    Description
    English: Visualization of Kuiper Test Statistic with two sample traces. Modified source code from user Bscan's work on 2 sampled KS-test. Matlab code shown below
    Date
    Source Own work
    Author Lucas(CA)
    PNG development
    InfoField
     This diagram was created with MATLAB.
    %Matlab code for two-sample Kuiper-Test visualization
    %Generate random samples on [0,2pi)
    % modified from user Bscan's work on 2 sampled KS-test
    num_samps =100; 
    mean1 = pi; std1 = pi/2;
    mean2 = pi/4; std2 = pi/2;
    randn
    dat1 = mod(mean1 + std1*randn(num_samps,1),2*pi);
    dat2 = mod(mean2 + std2*randn(num_samps,1), 2*pi);
    
    %Get emprical cdfs
    [f1,x1] = ecdf(dat1);
    [f2,x2] = ecdf(dat2);
    
    for k1 = 1:length(x1);
        [~,k2] = min(abs(x2 - x1(k1))); % closest x2 value to x1
        cdf_diff(k1) = f1(k1) - f2(k2);
    end
    [D_plus,ind_plus] = max(cdf_diff);
    [D_minus,ind_minus] = max(-cdf_diff);
    V = D_plus + D_minus;
    
    %Plot the two ecdfs
    figure; hold on;
    stairs(x1,f1,'b-','LineWidth',2);
    stairs(x2,f2,'r-','LineWidth',2);
    set(gca,'FontSize',16) %Increase font size
    plot([x1(ind_plus) x1(ind_plus)], [f1(ind_plus), f1(ind_plus)-cdf_diff(ind_plus)],'k')
    plot([x1(ind_minus) x1(ind_minus)], [f1(ind_minus), f1(ind_minus)-cdf_diff(ind_minus)],'k')
    grid on; box on; %Add grid to figure
    xlim([0 2*pi]); ylim([0 1])
    xlabel('X (Radians)')
    ylabel('Cumulative Probability')
    text(x1(ind_plus)+0.05,f1(ind_plus)-0.4*cdf_diff(ind_plus),'D_+','FontSize',18);
    text(x1(ind_minus)+0.1,f1(ind_minus)-0.4*cdf_diff(ind_minus),'D_-','FontSize',18);
    annotation('textbox', [0.15 0.75 0.2 0.1], 'String', 'V = D_++ D_-','FontSize',18, 'FitBoxToText','on','FaceAlpha',1)
    

    Licensing

    I, the copyright holder of this work, hereby publish it under the following license:
    w:en:Creative Commons
    attribution share alike
    This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
    You are free:
    • to share – to copy, distribute and transmit the work
    • to remix – to adapt the work
    Under the following conditions:
    • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
    • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

    Captions

    Add a one-line explanation of what this file represents

    Items portrayed in this file

    depicts

    21 September 2016

    23,648 byte

    420 pixel

    560 pixel

    image/png

    c8f1deed103ff34b02e96a0c569c4435f3003165

    File history

    Click on a date/time to view the file as it appeared at that time.

    Date/TimeThumbnailDimensionsUserComment
    current23:34, 21 September 2016Thumbnail for version as of 23:34, 21 September 2016560 × 420 (23 KB)wikimediacommons>Lucas(CA)User created page with UploadWizard

    There are no pages that use this file.