Created
December 24, 2014 22:56
-
-
Save abikoushi/39e00a3dc1ab59cbfbf6 to your computer and use it in GitHub Desktop.
crate table of confidence interval of ratio.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example
dat2<-data.frame(
CTs =c(50, 6),
IMP =c(100,10)
)
result2 <-CIset(k =dat2$CTs,n =dat2$IMP)