Apply a confidence interval to values in a dataframe based on the beta distribution.
Source:R/stats_extensions.R
beta_interval.Rd
Apply a confidence interval to values in a dataframe based on the beta distribution.
Arguments
- .data
Data frame; a confidence interval will be applied to each row in the data frame.
- alpha
First shape parameter of the beta distribution, must be greater than 0
- beta
Second shape parameter of the beta distribution, must be greater than 0
- conf
Confidence interval, must be between
[0, 1]
. Defaults to 0.95.
See also
Other interval verbs:
normal_interval()
Examples
# create example df
alpha <- rnorm(10, 100, 20)
beta <- rnorm(10, 80, 10)
example <- dplyr::bind_cols(alpha, beta)
#> New names:
#> • `` -> `...1`
#> • `` -> `...2`
colnames(example) <- c("alpha", "beta")
# apply the default confidence interval of 0.95
beta_interval(example, alpha, beta)
#> # A tibble: 10 × 4
#> alpha beta ci_lower ci_upper
#> <dbl> <dbl> <dbl> <dbl>
#> 1 72.0 74.5 0.411 0.572
#> 2 105. 86.3 0.478 0.619
#> 3 51.3 101. 0.265 0.414
#> 4 99.9 63.7 0.535 0.684
#> 5 112. 85.1 0.500 0.637
#> 6 123. 61.4 0.598 0.733
#> 7 63.6 74.8 0.377 0.543
#> 8 95.1 79.5 0.471 0.618
#> 9 95.1 85.4 0.454 0.599
#> 10 94.3 70.9 0.495 0.645
# apply a custom confidence interval
beta_interval(example, alpha, beta, conf = 0.99)
#> # A tibble: 10 × 4
#> alpha beta ci_lower ci_upper
#> <dbl> <dbl> <dbl> <dbl>
#> 1 72.0 74.5 0.386 0.597
#> 2 105. 86.3 0.456 0.640
#> 3 51.3 101. 0.244 0.439
#> 4 99.9 63.7 0.511 0.705
#> 5 112. 85.1 0.478 0.658
#> 6 123. 61.4 0.575 0.752
#> 7 63.6 74.8 0.353 0.569
#> 8 95.1 79.5 0.447 0.640
#> 9 95.1 85.4 0.431 0.621
#> 10 94.3 70.9 0.471 0.668