stats_ci/
lib.rs

1#![doc = include_str!("../README.md")]
2#![crate_type = "lib"]
3#![crate_name = "stats_ci"]
4#![forbid(unsafe_code)]
5#![deny(rustdoc::broken_intra_doc_links)]
6#![deny(rustdoc::private_intra_doc_links)]
7#![warn(missing_docs)]
8
9pub mod comparison;
10pub mod error;
11pub mod mean;
12pub mod proportion;
13pub mod quantile;
14
15pub mod utils;
16
17mod confidence;
18mod interval;
19mod stats;
20
21pub use confidence::Confidence;
22pub use error::CIResult;
23pub use interval::Interval;
24pub use mean::MeanCI;
25pub use mean::StatisticsOps;
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30
31    #[test]
32    fn test_readme() {
33        // 2. collect the data
34        let data = [
35            10.6, 6.6, 26.7, 0.4, 5.7, 0.3, 1.1, 5.0, 8.4, 1.4, 15.1, 0.3, 20.4, 1.2, 28.4, 10.7,
36            0.4, 10.1, 4.5, 7.1, 4.3, 37.4, 0.9, 10.1, 12.6, 21.7, 21.9, 2.0, 8.4, 9.3,
37        ];
38        // 3. define the confidence level (for 95% confidence)
39        let confidence = Confidence::new(0.95);
40
41        // 4a. compute the interval for the arithmetic mean
42        if let Ok(ci) = mean::Arithmetic::<f64>::ci(confidence, &data) {
43            // display the interval
44            println!("{}% c.i. for the mean = {}", confidence.percent(), ci);
45            if !ci.contains(&10.) {
46                println!("Does NOT contains the theoretical mean!");
47            }
48        }
49        // 4b. compute the interval for the median (i.e., 0.5-quantile)
50        if let Ok(ci) = quantile::ci::<f64, _>(confidence, &data, 0.5) {
51            // display the interval
52            println!("{}% c.i. for the median = {}", confidence.percent(), ci);
53            if !ci.contains(&6.93147) {
54                println!("Does NOT contains the theoretical median!");
55            }
56        }
57    }
58}