Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created December 24, 2014 22:56
Show Gist options
  • Save abikoushi/39e00a3dc1ab59cbfbf6 to your computer and use it in GitHub Desktop.
Save abikoushi/39e00a3dc1ab59cbfbf6 to your computer and use it in GitHub Desktop.
crate table of confidence interval of ratio.
CIset<-function(k, n, group=NULL, conf=0.95){
rate = k/n
len <-length(k)
CI =sapply(1:len ,function(i){
ans <- binom.test(k[i], n[i], conf.level =conf)
ans$conf.int[1:2]})
data.frame(group =if(is.null(group)){LETTERS[1:len]}else{group},
rate=rate,
upper = CI[1,],
lower = CI[2,])
}
@abikoushi
Copy link
Author

Example

dat2<-data.frame(
CTs =c(50, 6),
IMP =c(100,10)
)

result2 <-CIset(k =dat2$CTs,n =dat2$IMP)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment