File:Jeffreys intervals plotted on a logistic curve.svg

From testwiki
Jump to navigation Jump to search
    Original file (SVG file, nominally 1,024 × 635 pixels, file size: 13 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: Jeffreys intervals plotted on a logistic curve, revealing asymmetry and good performance for small n and where p is at or near 0 or 1.
    Date
    Source Own work
    Author Iroqu
    SVG development
    InfoField
     The source code of this SVG is invalid due to 45 errors.
     This W3C-invalid chart was created with R.
      This file uses embedded text that can be easily translated using a text editor.
    Source code
    InfoField

    R code

    require("ggplot2")
    require("svglite")
    
    n <- c(10, 100)
    p <- seq(0, 1, 0.01)
    mat <- expand.grid(n, p)
    colnames(mat) <- c("n", "p")
    
    get_jeffreys_ci <- function(number_of_successes, total_number, ci_width = .95) {
      result <- qbeta(
        p = c((1 - ci_width) / 2, (1 / 2) + (ci_width / 2)),
        shape1 = number_of_successes + 1 / 2,
        shape2 = total_number - number_of_successes + 1 / 2
      )
    
      if (number_of_successes == 0) {
        result[1] <- 0
      } else if (number_of_successes == total_number) {
        result[2] <- 1
      }
    
      result
    }
    
    tmp <- apply(
      mat,
      MARGIN = 1,
      function(x) {
        ret <- get_jeffreys_ci(x[2] * x[1], x[1])
        c(ret[1], ret[2])
      }
    )
    
    mat[, "ci_lb"] <- t(tmp)[, 1]
    mat[, "ci_ub"] <- t(tmp)[, 2]
    mat[, "logit_p"] <- log(mat$p / (1 - mat$p))
    
    mat <- as.data.frame(mat)
    
    ggplot(
      mat,
      aes(
        x = logit_p
      )
    ) +
      geom_hline(yintercept = 0.5, linetype = "dotted", alpha = .5) +
      geom_vline(xintercept = 0, linetype = "dotted", alpha = .5) +
      annotate(geom = "text", x = 1.0, y = 0.43, label = "n = 10", hjust = -0.1) +
      annotate(geom = "text", x = 0.3, y = 0.48, label = "n = 100", hjust = -0.1) +
      geom_line(aes(y = p)) +
      geom_line(aes(y = ci_lb, linetype = factor(n)), colour = "purple") +
      geom_line(aes(y = ci_ub, linetype = factor(n)), colour = "purple") +
      xlab("logit(p)") +
      see::theme_modern() +
      theme(
        legend.position = "none"
      )
    
    ggsave(
      "out.svg",
      units = "px",
      height = 496 * 4,
      width = 800 * 4
    )
    

    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

    Jeffreys intervals plotted on a logistic curve

    Items portrayed in this file

    depicts

    13,355 byte

    image/svg+xml

    d8e2d697688a692bddcc3e1b72541e7123e9afbb

    File history

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

    Date/TimeThumbnailDimensionsUserComment
    current13:34, 13 November 2025Thumbnail for version as of 13:34, 13 November 20251,024 × 635 (13 KB)wikimediacommons>IroquUploaded while editing "Binomial proportion confidence interval" on en.wikipedia.org

    There are no pages that use this file.