Skip to content

Instantly share code, notes, and snippets.

@ChrisBeeley
Created June 21, 2019 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisBeeley/ebfd8e1bb41fc53b82406045cc668108 to your computer and use it in GitHub Desktop.
Save ChrisBeeley/ebfd8e1bb41fc53b82406045cc668108 to your computer and use it in GitHub Desktop.
---
title: "Binomial confidence intervals"
author: "Chris Beeley"
date: "20/06/2019"
output: html_document
---
```{r setup, include=FALSE}
library(tidyverse)
library(knitr)
knitr::opts_chunk$set(echo = FALSE)
```
```{r}
conf_ints <- map(c(.1, .3, .5, .7, .9), function(x) {
map(c(10, 20, 30, 40, 50, 100, 150, 200), function(i){
values <- binom.test(x * i, i)
return(paste(round(values$conf.int[1] * 100, 1), round(values$conf.int[2] * 100, 1)))
})
})
check <- data.frame(do.call(cbind, conf_ints))
names(check) <- paste0(seq(10, 50, 10), "%")
check <- cbind(n = c(10, 20, 30, 40, 50, 100, 150, 200), check)
test1 <- check %>%
separate(2, sep = " ", into = c("lowerCI10%", "upperCI10%")) %>%
separate(4, sep = " ", into = c("lowerCI30%", "upperCI30%")) %>%
separate(6, sep = " ", into = c("lowerCI50%", "upperCI50%")) %>%
separate(8, sep = " ", into = c("lowerCI70%", "upperCI70%")) %>%
separate(10, sep = " ", into = c("lowerCI90%", "upperCI90%"))
kable(test1)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment