File:Rule of three.svg

From testwiki
Jump to navigation Jump to search
    Original file (SVG file, nominally 395 × 321 pixels, file size: 69 KB)

    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: Image comparing the rule of three to the exact binomial one-sided confidence interval (i.e. Clopper-Pearson)
    Date
    Source Own work
    Author Bscan
    SVG development
    InfoField
     The source code of this SVG is invalid due to an error.
     This W3C-invalid plot was created with Matplotlib.
     The file size of this SVG plot may be irrationally large because its text has been converted to paths inhibiting translations.
    Source code
    InfoField

    Python code

    #Python code shown below
    #This code is issued under the Creative Commons CC0 "License"
    
    from __future__ import division
    import numpy as np
    import matplotlib.pyplot as plt
    
    #Set domain of the graph
    MaxTrials = 10000
    MinTrials = 1
    UCB = np.zeros(MaxTrials)
    
    #Get points that are evenly spaced in log-space
    trials = np.exp(np.linspace(np.log(MinTrials),np.log(MaxTrials),100))
    
    #One-sided exact binomial upper confidence bound, equivalent to Clopper-Pearson
    #The choice of confidence interval does matter, but this is reasonable and
    #is typically the one from which Rule of 3 is derived
    #See Agresti and Coull 1998 for alternative binomial confidence intervals
    UCB = [1-0.05**(1/i) for i in trials]
    Rule_of_3 = [3/i for i in trials] 
    
    plt.figure(figsize=(4,3.2))
    plt.axes([0.17,0.13,0.79,0.8])
    plt.hold(True)
    A = []
    a, = plt.plot(trials, UCB,'-', color='orange',lw =2.5)
    b, = plt.plot(trials, Rule_of_3,'-', color='purple',lw =2.5)
    
    #Formatting
    A.append(a)
    A.append(b)
    ax = plt.gca()
    ax.set_yscale('log')
    ax.set_xscale('log')
    ax.grid()
    plt.xlabel("Sample Size")
    plt.ylabel(r"95% Upper Confidence Bound")
    leg_str = []
    leg_str.append(" Exact Binomial")
    leg_str.append(" Rule of Three")
    bx = plt.legend(A, leg_str,numpoints=1, handletextpad=0, loc="upper right")
    
    plt.savefig("rule_of_three.svg")
    

    Licensing

    I, the copyright holder of this work, hereby publish it under the following license:
    Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
    The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

    Captions

    Add a one-line explanation of what this file represents

    Items portrayed in this file

    depicts

    10 July 2014

    70,505 byte

    image/svg+xml

    2965405fbe7964944eb26b4f768324e240865722

    File history

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

    Date/TimeThumbnailDimensionsUserComment
    current14:41, 10 July 2014Thumbnail for version as of 14:41, 10 July 2014395 × 321 (69 KB)wikimediacommons>BscanUser created page with UploadWizard

    There are no pages that use this file.