use crate::accum::moments::comoment_pairs;
use crate::error::StatError;
use crate::htest::ci::ci_correlation;
use crate::htest::result::{EffectSize, TestResult};
use crate::special::betai;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CorMethod {
Pearson,
}
pub fn cor_test(a: &[f64], b: &[f64], method: CorMethod) -> Result<TestResult, StatError> {
let CorMethod::Pearson = method; let c = comoment_pairs(a, b)?;
let n = c.count() as f64;
if n < 3.0 { return Err(StatError::TooFewObservations { needed: 3, got: n as usize }); }
let r = c.pearson();
let df = n - 2.0;
let t = r * (df / (1.0 - r * r)).sqrt();
let p = betai(df / 2.0, 0.5, df / (df + t * t));
Ok(TestResult {
statistic: t, df, df2: None, p_value: p,
effect_size: Some(EffectSize::R(r)),
ci: ci_correlation(a, b, 0.95).ok(),
})
}