diff options
| author | Alexander <alexanderkabua@gmail.com> | 2022-04-25 14:01:43 +0300 |
|---|---|---|
| committer | Alexander <alexanderkabua@gmail.com> | 2022-04-25 14:01:43 +0300 |
| commit | 4cf6667b72574ee89dd50ee4783d477a07414de2 (patch) | |
| tree | d148ae68a717a253a2b3890e59ab82063e2b4b9c /src | |
| parent | c4126434743a6f01cee4e2468ad889d3cdaa75a2 (diff) | |
| download | correlation_rust-4cf6667b72574ee89dd50ee4783d477a07414de2.tar.gz | |
add tests for spearman correlation
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs index 378bd33..71b2da2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,8 +84,10 @@ impl Correlation for Spearman { //p-val two sided - let p_val = - return (rho,2.1); + let t = rho * (self.degrees_of_freedom / ((rho + 1.0) * (1.0 - rho))).sqrt(); + let p_val = 2.0* (tdist_Q(t.abs(), self.degrees_of_freedom)); + + return (rho,p_val); } } @@ -120,4 +122,16 @@ mod tests { assert_eq!(new_spearman,Spearman{n:5, degrees_of_freedom:3.0}); } + #[test] + fn test_spearman_correlation(){ + let new_spearman = Spearman::new(5); + + let (s_rho,p_val) = new_spearman.correlate(&[1.,2.,3.,4.,5.], &[5.,6.,7.,8.,7.]); + + + assert_approx_eq!(s_rho,0.079603960396039,2f64); + assert_approx_eq!(p_val,0.43111687,2f64) + + + } } \ No newline at end of file |
