46 const int k = groups.size();
47 const int nVars =
static_cast<int>(groups[0].cols());
51 for (
int g = 0; g < k; ++g) {
52 N +=
static_cast<int>(groups[g].rows());
56 RowVectorXd grandMean = RowVectorXd::Zero(nVars);
57 for (
int g = 0; g < k; ++g) {
58 grandMean += groups[g].colwise().sum();
60 grandMean /=
static_cast<double>(N);
63 RowVectorXd ssBetween = RowVectorXd::Zero(nVars);
64 RowVectorXd ssWithin = RowVectorXd::Zero(nVars);
66 for (
int g = 0; g < k; ++g) {
67 int ng =
static_cast<int>(groups[g].rows());
68 RowVectorXd groupMean = groups[g].colwise().mean();
71 RowVectorXd diff = groupMean - grandMean;
72 ssBetween +=
static_cast<double>(ng) * diff.array().square().matrix();
75 MatrixXd centered = groups[g].rowwise() - groupMean;
76 ssWithin += centered.colwise().squaredNorm();
79 int dfBetween = k - 1;
82 RowVectorXd msBetween = ssBetween /
static_cast<double>(dfBetween);
83 RowVectorXd msWithin = ssWithin /
static_cast<double>(dfWithin);
86 RowVectorXd fstat = msBetween.array() / msWithin.array();
89 MatrixXd matPval(1, nVars);
90 for (
int j = 0; j < nVars; ++j) {
91 matPval(0, j) = 1.0 -
fCdf(fstat(j), dfBetween, dfWithin);