1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
use crateTailType;
use ;
/// Calculates the p-value for a given test statistic.
///
/// This function determines the p-value based on the provided test statistic,
/// the type of tail (left, right, or two), and the statistical distribution used.
///
/// # Arguments
///
/// * `t_stat` - The test statistic (e.g., t-statistic).
/// * `tail` - The type of tail (left, right, or two).
/// * `dist` - The statistical distribution to be used, which must implement the `ContinuousCDF` trait.
///
/// # Returns
///
/// The p-value corresponding to the test statistic and tail type.
///
/// # Example
///
/// ```rust
/// use statrs::distribution::{StudentsT, ContinuousCDF};
/// use hypors::common::types::TailType;
/// use hypors::common::calc::calculate_p_value;
///
/// let t_stat = 2.0;
/// let tail = TailType::Two;
/// let t_dist = StudentsT::new(0.0, 1.0, 10.0).unwrap(); // Student's t-distribution with 10 degrees of freedom
///
/// let p_value = calculate_p_value(t_stat, tail, &t_dist);
/// assert!(p_value > 0.0 && p_value < 1.0);
/// ```
/// Calculates the confidence interval for a sample mean.
///
/// This function computes the confidence interval for a sample mean based on
/// the provided sample mean, standard error, significance level, and statistical distribution.
///
/// # Arguments
///
/// * `sample_mean` - The sample mean for the dataset.
/// * `std_error` - The standard error of the mean.
/// * `alpha` - The significance level (e.g., 0.05 for a 95% confidence interval).
/// * `dist` - The statistical distribution to be used, which must implement the `ContinuousCDF` trait.
///
/// # Returns
///
/// A tuple `(lower_bound, upper_bound)` representing the confidence interval.
///
/// # Example
///
/// ```rust
/// use statrs::distribution::{StudentsT, ContinuousCDF};
/// use hypors::common::calc::calculate_confidence_interval;
///
/// let sample_mean = 5.0;
/// let std_error = 1.5;
/// let alpha = 0.05;
/// let t_dist = StudentsT::new(0.0, 1.0, 10.0).unwrap(); // Student's t-distribution with 10 degrees of freedom
///
/// let ci = calculate_confidence_interval(sample_mean, std_error, alpha, &t_dist);
/// assert!(ci.0 < sample_mean && ci.1 > sample_mean); // Lower and upper bounds should surround the mean
/// ```
/// Calculates the confidence interval for Chi-squared distribution.
///
/// This function computes the confidence interval for the variance of a population
/// based on the sample variance and the Chi-squared distribution.
///
/// # Arguments
///
/// * `sample_variance` - The sample variance for the dataset.
/// * `alpha` - The significance level (e.g., 0.05 for a 95% confidence interval).
/// * `dist` - The Chi-squared distribution used for the calculation.
///
/// # Returns
///
/// A tuple `(lower_bound, upper_bound)` representing the confidence interval for variance.
///
/// # Example
///
/// ```rust
/// use statrs::distribution::ChiSquared;
/// use hypors::common::calc::calculate_chi2_confidence_interval;
///
/// let sample_variance = 2.5;
/// let alpha = 0.05;
/// let chi_squared_dist = ChiSquared::new(10.0).unwrap(); // Chi-squared distribution with 10 degrees of freedom
///
/// let ci = calculate_chi2_confidence_interval(sample_variance, alpha, &chi_squared_dist);
/// assert!(ci.0 < sample_variance && ci.1 > sample_variance); // Lower and upper bounds should surround the variance
/// ```