use scirs2_core::ndarray::array;
use scirs2_stats::{spearman_r, spearmanr};
#[allow(dead_code)]
fn main() {
let x = array![1.0, 2.0, 3.0, 4.0, 5.0];
let y = array![1.0, 4.0, 9.0, 16.0, 25.0];
let rho = spearman_r(&x.view(), &y.view()).expect("Operation failed");
println!("Spearman correlation coefficient: {}", rho);
assert!((rho - 1.0f64).abs() < 1e-10f64);
let (rho, p_value) = spearmanr(&x.view(), &y.view(), "two-sided").expect("Operation failed");
println!("Spearman correlation coefficient: {}", rho);
println!("Two-sided p-value: {}", p_value);
assert!((rho - 1.0f64).abs() < 1e-10f64);
println!(
"Is correlation significant at alpha=0.05? {}",
p_value < 0.05
);
let y2 = array![1.0, 3.8, 8.7, 17.2, 23.5]; let (rho2, p_value2) = spearmanr(&x.view(), &y2.view(), "two-sided").expect("Operation failed");
println!("\nSpearman correlation with noisy data: {}", rho2);
println!("Two-sided p-value: {}", p_value2);
let y3 = array![25.0, 16.0, 9.0, 4.0, 1.0]; let (rho3, p_value3) = spearmanr(&x.view(), &y3.view(), "two-sided").expect("Operation failed");
println!(
"\nSpearman correlation with negative relationship: {}",
rho3
);
println!("Two-sided p-value: {}", p_value3);
assert!((rho3 - (-1.0f64)).abs() < 1e-10f64);
let (_, p_greater) = spearmanr(&x.view(), &y.view(), "greater").expect("Operation failed");
let (_, p_less) = spearmanr(&x.view(), &y.view(), "less").expect("Operation failed");
println!("\nOne-sided tests for positive correlation:");
println!("P-value (greater): {}", p_greater); println!("P-value (less): {}", p_less);
let y4 = array![10.0, 5.0, 15.0, 8.0, 12.0]; let (rho4, p_value4) = spearmanr(&x.view(), &y4.view(), "two-sided").expect("Operation failed");
println!("\nSpearman correlation with uncorrelated data: {}", rho4);
println!("Two-sided p-value: {}", p_value4);
}