1 use super::*;
2 use crate::report::ComparisonData;
3 use std::path::Path;
4
t_test( path: &Path, title: &str, comparison: &ComparisonData, size: Option<(u32, u32)>, )5 pub(crate) fn t_test(
6 path: &Path,
7 title: &str,
8 comparison: &ComparisonData,
9 size: Option<(u32, u32)>,
10 ) {
11 let t = comparison.t_value;
12 let (xs, ys) = kde::sweep(&comparison.t_distribution, KDE_POINTS, None);
13
14 let x_range = plotters::data::fitting_range(xs.iter());
15 let mut y_range = plotters::data::fitting_range(ys.iter());
16 y_range.start = 0.0;
17 y_range.end *= 1.1;
18
19 let root_area = SVGBackend::new(&path, size.unwrap_or(SIZE)).into_drawing_area();
20
21 let mut chart = ChartBuilder::on(&root_area)
22 .margin((5).percent())
23 .caption(format!("{}: Welch t test", title), (DEFAULT_FONT, 20))
24 .set_label_area_size(LabelAreaPosition::Left, (5).percent_width().min(60))
25 .set_label_area_size(LabelAreaPosition::Bottom, (5).percent_height().min(40))
26 .build_cartesian_2d(x_range, y_range.clone())
27 .unwrap();
28
29 chart
30 .configure_mesh()
31 .disable_mesh()
32 .y_desc("Density")
33 .x_desc("t score")
34 .draw()
35 .unwrap();
36
37 chart
38 .draw_series(AreaSeries::new(
39 xs.iter().zip(ys.iter()).map(|(x, y)| (*x, *y)),
40 0.0,
41 &DARK_BLUE.mix(0.25),
42 ))
43 .unwrap()
44 .label("t distribution")
45 .legend(|(x, y)| {
46 Rectangle::new([(x, y - 5), (x + 20, y + 5)], DARK_BLUE.mix(0.25).filled())
47 });
48
49 chart
50 .draw_series(std::iter::once(PathElement::new(
51 vec![(t, 0.0), (t, y_range.end)],
52 DARK_BLUE.filled().stroke_width(2),
53 )))
54 .unwrap()
55 .label("t statistic")
56 .legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &DARK_BLUE));
57
58 chart.configure_series_labels().draw().unwrap();
59 }
60