about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander <alexanderkabua@gmail.com>2022-04-25 13:24:57 +0300
committerAlexander <alexanderkabua@gmail.com>2022-04-25 13:24:57 +0300
commit80f50c5a1cdc66e900cbfabe07ba60e8d83f5f57 (patch)
tree824a45b97e5af5c315507f2f4201bac97b022698 /src
parenta85b311d51acafe0e32b1635fb2f183c0c5e6146 (diff)
downloadcorrelation_rust-80f50c5a1cdc66e900cbfabe07ba60e8d83f5f57.tar.gz
add spearman correlation
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c00657a..f78fc0f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -7,6 +7,8 @@ use assert_approx_eq::assert_approx_eq;
 
 trait Correlation {
     fn correlate(&self,x:&[f64],y:&[f64]) ->(f64,f64);
+
+    
 }
 
 
@@ -21,6 +23,8 @@ struct Pearson {
     degrees_of_freedom:f64,
 }
 
+
+
 impl Pearson {
     fn new(n:usize) -> Self {
 
@@ -32,6 +36,8 @@ impl Pearson {
 }
 
 
+
+
 impl Correlation for Pearson {
     fn correlate(&self,x:&[f64],y:&[f64]) ->(f64,f64){
 
@@ -53,10 +59,29 @@ impl Correlation for Pearson {
     }
 }
 
-fn main() {
 
+#[derive(PartialEq, Debug)]
+struct Spearman {
+    n: usize,
+    degrees_of_freedom:f64,
+}
+
+
+impl Spearman {
+    fn new(n:usize) ->Spearman {
+        Spearman { n: n, degrees_of_freedom: (n - 2) as f64 }
+    }
 }
 
+impl Correlation for Spearman {
+
+    fn correlate(&self,x:&[f64],y:&[f64]) -> (f64,f64){
+        (1.2,2.1)
+    }
+}
+
+
+
 #[cfg(test)]
 mod tests {
     use super::*;
@@ -78,4 +103,12 @@ mod tests {
         assert_eq!(format!("{:.2}", corr_coeff),"1.00");
         assert_approx_eq!(p_val,1.341575855,2f64);
     }
+
+    #[test]
+    fn test_spearman(){
+        let new_spearman = Spearman::new(5);
+
+        assert_eq!(new_spearman,Spearman{n:5, degrees_of_freedom:3.0});
+
+    }
 }
\ No newline at end of file