r2rs_stats/traits/
variance.rs1use nalgebra::DMatrix;
7
8use crate::funcs::{cor, cov, cov2cor, sd, var, Method, NAMethod};
9
10pub trait Variance {
11 fn standard_deviation(&self) -> f64;
12 fn var(&self, na_method: NAMethod) -> f64;
13 fn covariance(&self, method: Method, na_method: NAMethod) -> Self;
14 fn covariance_y(&self, y: &Self, method: Method, na_method: NAMethod) -> Self;
15 fn correlation(&self, na_method: NAMethod, method: Method) -> Self;
16 fn correlation_y(&self, y: &Self, na_method: NAMethod, method: Method) -> Self;
17 fn covariance_to_correlation(&self) -> Self;
18}
19
20impl Variance for DMatrix<f64> {
21 fn standard_deviation(&self) -> f64 {
22 sd(self.as_slice())
23 }
24
25 fn var(&self, na_method: NAMethod) -> f64 {
26 var(self, na_method)
27 }
28
29 fn covariance(&self, method: Method, na_method: NAMethod) -> Self {
30 cov(self, self, method, na_method)
31 }
32
33 fn covariance_y(&self, y: &Self, method: Method, na_method: NAMethod) -> Self {
34 cov(self, y, method, na_method)
35 }
36
37 fn correlation(&self, na_method: NAMethod, method: Method) -> Self {
38 cor(self, self, na_method, method)
39 }
40
41 fn correlation_y(&self, y: &Self, na_method: NAMethod, method: Method) -> Self {
42 cor(self, y, na_method, method)
43 }
44
45 fn covariance_to_correlation(&self) -> Self {
46 cov2cor(self)
47 }
48}