Skip to main content

aok/
aok.rs

1//! Example of use of [`basic_stats::aok`] traits.
2//! Requires features **`aok`** and **`normal`**.
3
4use basic_stats::{
5    aok::{AokBasicStats, AokFloat},
6    core::{AltHyp, SampleMoments},
7    normal::{welch_alt_hyp_ci, welch_p, welch_test},
8};
9
10fn main() {
11    let x = [14., 15., 15., 15., 16., 18., 22., 23., 24., 25., 25.];
12    let y = [
13        10., 12., 14., 15., 18., 22., 24., 27., 31., 33., 34., 34., 34.,
14    ];
15
16    let moments_x = SampleMoments::from_slice(&x);
17    let moments_y = SampleMoments::from_slice(&y);
18    let alt_hyp = AltHyp::Gt;
19
20    {
21        println!("*** Ok scenario:");
22
23        let alpha = 0.05;
24
25        // Welch function calls below return Ok prior to invocation of aok().
26
27        let p = welch_p(&moments_x, &moments_y, alt_hyp).aok();
28        println!("p={p}");
29        let ci = welch_alt_hyp_ci(&moments_x, &moments_y, alt_hyp, alpha).aok();
30        println!("ci={ci:?}");
31        let test_res = welch_test(&moments_x, &moments_y, alt_hyp, alpha).aok();
32        println!("test_res={test_res:?}");
33    }
34
35    {
36        println!("*** Err scenario:");
37
38        let alpha = 1.0;
39
40        // Welch function calls below return Err prior to invocation of aok().
41
42        let p = welch_p(&moments_x, &SampleMoments::default(), alt_hyp).aok();
43        println!("p={p}");
44        let ci = welch_alt_hyp_ci(&moments_x, &moments_y, alt_hyp, alpha).aok();
45        println!("ci={ci:?}");
46        let test_res = welch_test(&moments_x, &moments_y, alt_hyp, alpha).aok();
47        println!("test_res={test_res:?}");
48    }
49}