57 const int k = groups.size();
58 const int nVars =
static_cast<int>(groups[0].cols());
62 for (
int g = 0; g < k; ++g) {
63 N +=
static_cast<int>(groups[g].rows());
67 RowVectorXd grandMean = RowVectorXd::Zero(nVars);
68 for (
int g = 0; g < k; ++g) {
69 grandMean += groups[g].colwise().sum();
71 grandMean /=
static_cast<double>(N);
74 RowVectorXd ssBetween = RowVectorXd::Zero(nVars);
75 RowVectorXd ssWithin = RowVectorXd::Zero(nVars);
77 for (
int g = 0; g < k; ++g) {
78 int ng =
static_cast<int>(groups[g].rows());
79 RowVectorXd groupMean = groups[g].colwise().mean();
82 RowVectorXd diff = groupMean - grandMean;
83 ssBetween +=
static_cast<double>(ng) * diff.array().square().matrix();
86 MatrixXd centered = groups[g].rowwise() - groupMean;
87 ssWithin += centered.colwise().squaredNorm();
90 int dfBetween = k - 1;
93 RowVectorXd msBetween = ssBetween /
static_cast<double>(dfBetween);
94 RowVectorXd msWithin = ssWithin /
static_cast<double>(dfWithin);
97 RowVectorXd fstat = msBetween.array() / msWithin.array();
100 MatrixXd matPval(1, nVars);
101 for (
int j = 0; j < nVars; ++j) {
102 matPval(0, j) = 1.0 -
fCdf(fstat(j), dfBetween, dfWithin);