From 7bc7fe47667e93cdce55d64f26a33854b1c8c4d2 Mon Sep 17 00:00:00 2001 From: Jose Storopoli Date: Sun, 21 Jan 2024 10:20:31 -0300 Subject: [PATCH] feat(anova): TwoWayANOVA --- power/src/power.rs | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/power/src/power.rs b/power/src/power.rs index e77c8b2..23146ed 100644 --- a/power/src/power.rs +++ b/power/src/power.rs @@ -28,12 +28,18 @@ pub enum TestKind { /// Number of tested predictors (#B). q: i64, }, - IndependentSamplesTTest, /// ANOVA: Fixed effects, omnibus, one-way. OneWayANOVA { /// Number of groups. k: i64, }, + /// ANOVA: Fixed effects, special, main effects and interactions. + TwoWayANOVA { + /// Total number of cells in the design. + k: i64, + /// Degrees of freedom of the tested effect. + q: i64, + }, } #[derive(Clone, Debug)] @@ -83,13 +89,17 @@ impl TestKind { "increaseMultipleRegression" => { let rho = parse_i64(data, "rho").unwrap(); let q = parse_i64(data, "q").unwrap(); - Ok(TestKind::IncreaseMultipleRegression{ p, q }) - }, - "independentSamplesTTest" => Ok(TestKind::IndependentSamplesTTest), + Ok(TestKind::IncreaseMultipleRegression { rho, q }) + } "oneWayANOVA" => { let k = parse_i64(data, "k").unwrap(); Ok(TestKind::OneWayANOVA { k }) } + "twoWayANOVA" => { + let k = parse_i64(data, "k").unwrap(); + let q = parse_i64(data, "q").unwrap(); + Ok(TestKind::TwoWayANOVA { k, q }) + } _ => Err(format!("Unknown test: {}", text)), } } @@ -101,11 +111,29 @@ impl TestKind { let v = n - 2.0; // n1 + n2 - 2 Box::new(NoncentralT::new(v, (n / 2.0).sqrt() * es)) } + TestKind::DeviationFromZeroMultipleRegression { n_predictors } => { + Box::new(NoncentralF::new( + *n_predictors as f64, + n - (*n_predictors as f64) - 1.0, + es.powi(2) * n, + )) + } + TestKind::GoodnessOfFitChisqTest { df } => { + Box::new(NoncentralChisq::new(*df as f64, es.powi(2) * n)) + } + TestKind::IncreaseMultipleRegression { rho, q } => Box::new(NoncentralF::new( + *q as f64, + n - (*rho as f64) - 1.0, + es.powi(2) * n, + )), TestKind::OneWayANOVA { k } => Box::new(NoncentralF::new( *k as f64 - 1.0, n - *k as f64, es.powi(2) * n, )), + TestKind::TwoWayANOVA { k, q } => { + Box::new(NoncentralF::new(*q as f64, n - *k as f64, es.powi(2) * n)) + } } }