-
Notifications
You must be signed in to change notification settings - Fork 1
/
stats-confidence-intervals.R
63 lines (56 loc) · 1.21 KB
/
stats-confidence-intervals.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#' Confidence Interval Generic
#'
#' @family Statistic
#'
#' @author Steven P. Sanderson II, MPH
#'
#' @details Gets the lower 2.5% quantile of a numeric vector.
#'
#' @description Gets the lower 2.5% quantile of a numeric vector.
#'
#' @param .x A vector of numeric values
#' @param .na_rm A Boolean, defaults to FALSE. Passed to the quantile function.
#'
#' @return
#' A numeric value.
#'
#' @examples
#' x <- mtcars$mpg
#' ci_lo(x)
#'
#' @export
#'
ci_lo <- function(.x, .na_rm = FALSE) {
na_rm <- as.logical(.na_rm)
x_term <- .x
ret <- unname(stats::quantile(x_term, 0.025, na.rm = na_rm))
return(ret)
}
#' Confidence Interval Generic
#'
#' @family Statistic
#'
#' @author Steven P. Sanderson II, MPH
#'
#' @details Gets the upper 97.5% quantile of a numeric vector.
#'
#' @description Gets the upper 97.5% quantile of a numeric vector.
#'
#' @param .x A vector of numeric values
#' @param .na_rm A Boolean, defaults to FALSE. Passed to the quantile function.
#'
#' @return
#' A numeric value.
#'
#' @examples
#' x <- mtcars$mpg
#' ci_hi(x)
#'
#' @export
#'
ci_hi <- function(.x, .na_rm = FALSE) {
na_rm <- as.logical(.na_rm)
x_term <- .x
ret <- unname(stats::quantile(x_term, 0.975, na.rm = na_rm))
return(ret)
}