pub trait Stats<T> {
Show 15 methods
// Required methods
fn mean(&self) -> StatsResult<T>;
fn median(&self) -> StatsResult<T>;
fn mode(&self) -> StatsResult<Vec<T>>;
fn variance(&self) -> StatsResult<T>;
fn std_dev(&self) -> StatsResult<T>;
fn variance_pop(&self) -> StatsResult<T>;
fn std_dev_pop(&self) -> StatsResult<T>;
fn min(&self) -> StatsResult<T>;
fn max(&self) -> StatsResult<T>;
fn range(&self) -> StatsResult<T>;
fn sum(&self) -> StatsResult<T>;
fn percentile(&self, p: f64) -> StatsResult<T>;
fn iqr(&self) -> StatsResult<T>;
// Provided methods
fn quartile_1(&self) -> StatsResult<T> { ... }
fn quartile_3(&self) -> StatsResult<T> { ... }
}Expand description
Main trait providing statistical functions for collections
Required Methods§
Sourcefn mean(&self) -> StatsResult<T>
fn mean(&self) -> StatsResult<T>
Calculate the arithmetic mean (average)
Sourcefn median(&self) -> StatsResult<T>
fn median(&self) -> StatsResult<T>
Calculate the median (middle value)
Sourcefn mode(&self) -> StatsResult<Vec<T>>
fn mode(&self) -> StatsResult<Vec<T>>
Calculate the mode (most frequent value)
Sourcefn variance(&self) -> StatsResult<T>
fn variance(&self) -> StatsResult<T>
Calculate the variance
Sourcefn std_dev(&self) -> StatsResult<T>
fn std_dev(&self) -> StatsResult<T>
Calculate the standard deviation
Sourcefn variance_pop(&self) -> StatsResult<T>
fn variance_pop(&self) -> StatsResult<T>
Calculate the population variance
Sourcefn std_dev_pop(&self) -> StatsResult<T>
fn std_dev_pop(&self) -> StatsResult<T>
Calculate the population standard deviation
Sourcefn min(&self) -> StatsResult<T>
fn min(&self) -> StatsResult<T>
Find the minimum value
Sourcefn max(&self) -> StatsResult<T>
fn max(&self) -> StatsResult<T>
Find the maximum value
Sourcefn range(&self) -> StatsResult<T>
fn range(&self) -> StatsResult<T>
Calculate the range (max - min)
Sourcefn sum(&self) -> StatsResult<T>
fn sum(&self) -> StatsResult<T>
Calculate the sum of all values
Sourcefn percentile(&self, p: f64) -> StatsResult<T>
fn percentile(&self, p: f64) -> StatsResult<T>
Calculate a percentile
Sourcefn iqr(&self) -> StatsResult<T>
fn iqr(&self) -> StatsResult<T>
Calculate the interquartile range (Q3 - Q1)
Provided Methods§
Sourcefn quartile_1(&self) -> StatsResult<T>
fn quartile_1(&self) -> StatsResult<T>
Calculate the first quartile (25th percentile)
Examples found in repository?
examples/basic_usage.rs (line 22)
3fn main() {
4 println!("=== Statify Statistics Library Demo ===\n");
5
6 // Basic descriptive statistics
7 let data = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0];
8
9 println!("Dataset: {:?}\n", data);
10 println!("Descriptive Statistics:");
11 println!(" Mean: {:.2}", data.mean().unwrap());
12 println!(" Median: {:.2}", data.median().unwrap());
13 println!(" Std Dev: {:.2}", data.std_dev().unwrap());
14 println!(" Variance: {:.2}", data.variance().unwrap());
15 println!(" Min: {:.2}", data.min().unwrap());
16 println!(" Max: {:.2}", data.max().unwrap());
17 println!(" Range: {:.2}", data.range().unwrap());
18 println!(" Sum: {:.2}", data.sum().unwrap());
19
20 // Percentiles and quartiles
21 println!("\nPercentiles:");
22 println!(" 25th percentile (Q1): {:.2}", data.quartile_1().unwrap());
23 println!(" 50th percentile (Median): {:.2}", data.percentile(50.0).unwrap());
24 println!(" 75th percentile (Q3): {:.2}", data.quartile_3().unwrap());
25 println!(" IQR: {:.2}", data.iqr().unwrap());
26
27 // Correlation and covariance
28 let x = vec![1.0, 2.0, 3.0, 4.0, 5.0];
29 let y = vec![2.0, 4.0, 6.0, 8.0, 10.0];
30
31 println!("\nCorrelation Analysis:");
32 println!(" X: {:?}", x);
33 println!(" Y: {:?}", y);
34 println!(" Correlation: {:.4}", correlation(&x, &y).unwrap());
35 println!(" Covariance: {:.4}", covariance(&x, &y).unwrap());
36
37 // Z-scores
38 let sample = vec![10.0, 20.0, 30.0, 40.0, 50.0];
39 let z_vals = z_scores(&sample).unwrap();
40
41 println!("\nZ-Scores:");
42 println!(" Data: {:?}", sample);
43 println!(" Z-scores: {:?}", z_vals.iter().map(|&x| format!("{:.2}", x)).collect::<Vec<_>>());
44
45 // Real-world example: test scores
46 let test_scores = vec![
47 85.0, 92.0, 78.0, 95.0, 88.0, 76.0, 89.0, 94.0, 81.0, 87.0,
48 ];
49
50 println!("\n=== Real-World Example: Test Scores ===");
51 println!("Scores: {:?}", test_scores);
52 println!(" Average Score: {:.2}", test_scores.mean().unwrap());
53 println!(" Median Score: {:.2}", test_scores.median().unwrap());
54 println!(" Std Deviation: {:.2}", test_scores.std_dev().unwrap());
55 println!(" Lowest Score: {:.2}", test_scores.min().unwrap());
56 println!(" Highest Score: {:.2}", test_scores.max().unwrap());
57 println!(" Score Range: {:.2}", test_scores.range().unwrap());
58}Sourcefn quartile_3(&self) -> StatsResult<T>
fn quartile_3(&self) -> StatsResult<T>
Calculate the third quartile (75th percentile)
Examples found in repository?
examples/basic_usage.rs (line 24)
3fn main() {
4 println!("=== Statify Statistics Library Demo ===\n");
5
6 // Basic descriptive statistics
7 let data = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0];
8
9 println!("Dataset: {:?}\n", data);
10 println!("Descriptive Statistics:");
11 println!(" Mean: {:.2}", data.mean().unwrap());
12 println!(" Median: {:.2}", data.median().unwrap());
13 println!(" Std Dev: {:.2}", data.std_dev().unwrap());
14 println!(" Variance: {:.2}", data.variance().unwrap());
15 println!(" Min: {:.2}", data.min().unwrap());
16 println!(" Max: {:.2}", data.max().unwrap());
17 println!(" Range: {:.2}", data.range().unwrap());
18 println!(" Sum: {:.2}", data.sum().unwrap());
19
20 // Percentiles and quartiles
21 println!("\nPercentiles:");
22 println!(" 25th percentile (Q1): {:.2}", data.quartile_1().unwrap());
23 println!(" 50th percentile (Median): {:.2}", data.percentile(50.0).unwrap());
24 println!(" 75th percentile (Q3): {:.2}", data.quartile_3().unwrap());
25 println!(" IQR: {:.2}", data.iqr().unwrap());
26
27 // Correlation and covariance
28 let x = vec![1.0, 2.0, 3.0, 4.0, 5.0];
29 let y = vec![2.0, 4.0, 6.0, 8.0, 10.0];
30
31 println!("\nCorrelation Analysis:");
32 println!(" X: {:?}", x);
33 println!(" Y: {:?}", y);
34 println!(" Correlation: {:.4}", correlation(&x, &y).unwrap());
35 println!(" Covariance: {:.4}", covariance(&x, &y).unwrap());
36
37 // Z-scores
38 let sample = vec![10.0, 20.0, 30.0, 40.0, 50.0];
39 let z_vals = z_scores(&sample).unwrap();
40
41 println!("\nZ-Scores:");
42 println!(" Data: {:?}", sample);
43 println!(" Z-scores: {:?}", z_vals.iter().map(|&x| format!("{:.2}", x)).collect::<Vec<_>>());
44
45 // Real-world example: test scores
46 let test_scores = vec![
47 85.0, 92.0, 78.0, 95.0, 88.0, 76.0, 89.0, 94.0, 81.0, 87.0,
48 ];
49
50 println!("\n=== Real-World Example: Test Scores ===");
51 println!("Scores: {:?}", test_scores);
52 println!(" Average Score: {:.2}", test_scores.mean().unwrap());
53 println!(" Median Score: {:.2}", test_scores.median().unwrap());
54 println!(" Std Deviation: {:.2}", test_scores.std_dev().unwrap());
55 println!(" Lowest Score: {:.2}", test_scores.min().unwrap());
56 println!(" Highest Score: {:.2}", test_scores.max().unwrap());
57 println!(" Score Range: {:.2}", test_scores.range().unwrap());
58}