Skip to content

Commit

Permalink
feat(anova): TwoWayANOVA
Browse files Browse the repository at this point in the history
  • Loading branch information
storopoli committed Jan 21, 2024
1 parent 7ae2811 commit 7bc7fe4
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions power/src/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)),
}
}
Expand All @@ -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))
}
}
}

Expand Down

0 comments on commit 7bc7fe4

Please sign in to comment.