Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
---
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