add_CI_values.Rd
This function create upper and lower CI for observed rate. Two new variables will be added LC and UC the formula is based on 95% CI: rate+/- 1.96 x sqrt((!!var x (1-!!var))/!!n_cases)
add_CI_values(data, var, n_cases)
variable you want to sort
number of cases used to calculate CI
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
tb = tibble::tibble(cs_rate = c(0.1, 0.3),
n_pt_cases = c(140, 234))
tb %>%
add_CI_values(var = cs_rate,
n_cases = n_pt_cases)
#> # A tibble: 2 × 4
#> cs_rate n_pt_cases LC UC
#> <dbl> <dbl> <dbl> <dbl>
#> 1 0.1 140 0.0503 0.150
#> 2 0.3 234 0.241 0.359