Apply a confidence interval to values in a dataframe based on the normal distribution.
Source:R/stats_extensions.R
normal_interval.Rd
Apply a confidence interval to values in a dataframe based on the normal distribution.
Arguments
- .data
Data frame; a confidence interval will be applied to each row in the data frame.
- mean
Mean of the distribution
- std_dev
Standard deviation of the distribution
- conf
Confidence interval, must be between
[0, 1]
. Defaults to 0.95.
See also
Other interval verbs:
beta_interval()
Examples
# create example df
mean <- rnorm(10, 100, 20)
std_dev <- rnorm(10, 80, 10)
example <- dplyr::bind_cols(mean, std_dev)
#> New names:
#> • `` -> `...1`
#> • `` -> `...2`
colnames(example) <- c("mean", "std_dev")
# apply the default confidence interval of 0.95
normal_interval(example, mean, std_dev)
#> # A tibble: 10 × 4
#> mean std_dev ci_lower ci_upper
#> <dbl> <dbl> <dbl> <dbl>
#> 1 155. 85.5 -12.5 323.
#> 2 101. 57.3 -11.3 213.
#> 3 112. 107. -97.8 321.
#> 4 102. 76.4 -47.4 252.
#> 5 61.8 82.1 -99.2 223.
#> 6 117. 90.7 -60.6 295.
#> 7 95.1 73.3 -48.6 239.
#> 8 95.9 91.1 -82.8 275.
#> 9 100. 77.5 -51.6 252.
#> 10 101. 68.2 -33.1 234.
# apply a custom confidence interval
normal_interval(example, mean, std_dev, conf = 0.99)
#> # A tibble: 10 × 4
#> mean std_dev ci_lower ci_upper
#> <dbl> <dbl> <dbl> <dbl>
#> 1 155. 85.5 -65.1 375.
#> 2 101. 57.3 -46.6 248.
#> 3 112. 107. -164. 387.
#> 4 102. 76.4 -94.4 299.
#> 5 61.8 82.1 -150. 273.
#> 6 117. 90.7 -116. 351.
#> 7 95.1 73.3 -93.8 284.
#> 8 95.9 91.1 -139. 331.
#> 9 100. 77.5 -99.3 300.
#> 10 101. 68.2 -75.1 276.