fix doco
Gitea Organization/civilyticsR/pipeline/head There was a failure building this commit
Gitea Organization/civilyticsR/pipeline/pr-master There was a failure building this commit

This commit is contained in:
2024-08-09 15:34:39 -04:00
parent 82b8db7f84
commit f4a4ee85a7
9 changed files with 119 additions and 13 deletions
+10
View File
@@ -0,0 +1,10 @@
#' @keywords internal
#' @importFrom stats qbeta
#' @importFrom stats qnorm
"_PACKAGE"
## usethis namespace: start
## usethis namespace: end
NULL
+26 -11
View File
@@ -6,17 +6,15 @@
# https://andrewpwheeler.com/2020/11/30/confidence-intervals-around-proportions/
#' Get a simple Clopper Pearson interval
#'
#' @param num
#' @param den
#' @param confint
#' @param num number of successes
#' @param den number of trials
#' @param conf.level default 0.95, set the confidence interval to return
#'
#' @return
#' @return three values forming the upper and lower bounds of the confidence region and the true value
#' @export
#'
#' @examples
clopper_pearson <- function(num, den, confint = 0.95) {
clopper_pearson <- function(num, den, conf.level = 0.95) {
# Same results as binom.test in base R
quant <- (1 - confint) / 2
quant <- (1 - conf.level) / 2
low <- qbeta(quant, num, den-num+1)
hi <- qbeta(1-quant, num+1, den-num)
obs <- num/den
@@ -24,7 +22,6 @@ clopper_pearson <- function(num, den, confint = 0.95) {
}
# TODO consider making a vectorized version
# z_gap_test_v <- Vectorize(z_gap_test,
# SIMPLIFY = TRUE)# we only want to return a scalar
@@ -53,6 +50,17 @@ z_univariate <- function(unit_prop, global_prop, unit_denom) {
}
#' Calculate a Wald interval
#'
#' @param x the numerator, number of times the event occurs
#' @param n the denominator, the number of trials
#' @param conf.level default 0.95, set the confidence interval to return
#'
#' @return two values forming the upper and lower bounds of the confidence region
#' @export
#'
#' @examples
#' waldInterval(x = 20, n =40) #this will return 0.345 and 0.655
waldInterval <- function(x, n, conf.level = 0.95){
p <- x/n
sd <- sqrt(p*((1-p)/n))
@@ -60,11 +68,18 @@ waldInterval <- function(x, n, conf.level = 0.95){
ci <- p + z*sd
names(ci) <- c('lwr', 'upr')
return(ci)
}#example
#waldInterval(x = 20, n =40) #this will return 0.345 and 0.655
}
#' Calculate the Agresti-Coull interval
#'
#' @param num a number of successes
#' @param den a number of trials
#' @param conf.level default 0.95, set the confidence interval to return
#'
#' @return an interval
agresti_coull_interval <- function(num, den, conf.level) {
num <- num + 2
den <- den + 4
return(num/den)
}