[−][src]Module peroxide::statistics::stat
Basic statistics
Statistics
trait
- To make generic code, there is
Statistics
traitmean
: just meanvar
: variancesd
: standard deviation (R-like notation)cov
: covariancecor
: correlation coefficient
pub trait Statistics { type Array; type Value; fn mean(&self) -> Self::Value; fn var(&self) -> Self::Value; fn sd(&self) -> Self::Value; fn cov(&self) -> Self::Array; fn cor(&self) -> Self::Array; }
For Vec<f64>
-
Caution: For
Vec<f64>
,cov
&cor
are unimplemented (those forMatrix
)#[macro_use] extern crate peroxide; use peroxide::fuga::*; fn main() { let a = c!(1,2,3,4,5); a.mean().print(); // 3 a.var().print(); // 2.5 a.sd().print(); // 1.5811388300841898 }
-
But there are other functions to calculate
cov
&cor
#[macro_use] extern crate peroxide; use peroxide::fuga::*; fn main() { let v1 = c!(1,2,3); let v2 = c!(3,2,1); cov(&v1, &v2).print(); // -0.9999999999999998 cor(&v1, &v2).print(); // -0.9999999999999993 }
For Matrix
-
For
Matrix
,mean, var, sd
means column operations -
cov
means covariance matrix &cor
means also correlation coefficient matrix#[macro_use] extern crate peroxide; use peroxide::fuga::*; fn main() { let m = matrix(c!(1,2,3,3,2,1), 3, 2, Col); m.mean().print(); // [2, 2] m.var().print(); // [1.0000, 1.0000] m.sd().print(); // [1.0000, 1.0000] m.cov().print(); // c[0] c[1] // r[0] 1.0000 -1.0000 // r[1] -1.0000 1.0000 m.cor().print(); // c[0] c[1] // r[0] 1 -1.0000 // r[1] -1.0000 1 }
For DataFrame
- Similar to Matrix but,
Value
isDataFrame
cov
means covariance matrix.
#[macro_use] extern crate peroxide; use peroxide::fuga::*; fn main() { #[cfg(feature = "dataframe")] { let mut m = DataFrame::with_header(vec!["x", "y"]); m["x"] = c!(1,2,3); m["y"] = c!(3,2,1); m.cov().print(); // c[0] c[1] // r[0] 1.0000 -1.0000 // r[1] -1.0000 1.0000 } }
Enums
QType | R Quantile Type enums |
Traits
OrderedStat | Trait for Ordered Statistics |
Statistics | Statistics Trait |
Functions
cor | Pearson's correlation coefficient |
cov | Covariance (to Value) |
lm | R like linear regression |
quantile |