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 92.7 90.5 0.434 0.578
#> 2 117. 87.3 0.504 0.640
#> 3 123. 78.6 0.543 0.677
#> 4 75.8 62.5 0.465 0.630
#> 5 108. 53.6 0.594 0.739
#> 6 111. 69.6 0.543 0.684
#> 7 79.3 69.1 0.454 0.614
#> 8 99.4 77.5 0.488 0.634
#> 9 116. 80.2 0.523 0.660
#> 10 73.8 82.6 0.394 0.550
# 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 92.7 90.5 0.412 0.600
#> 2 117. 87.3 0.483 0.660
#> 3 123. 78.6 0.521 0.696
#> 4 75.8 62.5 0.439 0.655
#> 5 108. 53.6 0.570 0.759
#> 6 111. 69.6 0.520 0.705
#> 7 79.3 69.1 0.429 0.638
#> 8 99.4 77.5 0.465 0.656
#> 9 116. 80.2 0.501 0.680
#> 10 73.8 82.6 0.371 0.574