StatsClusterResult
Namespace: STSLIB · Library: Statistics Library
#include <sts/sts_cluster.h>
struct STSLIB::StatsClusterResult
Result structure for cluster permutation tests.
Per-call output of a cluster permutation test: observed statistic map, cluster masses, cluster p-values and cluster labels.
src/examples/ex_sts_statistics/main.cpp
// 12 subjects, 8 channels on a line, 1 time point; channels 2-4 carry an effect in condition B
SparseMatrix<int> chain(8, 8);
for (int i = 0; i + 1 < 8; ++i) {
chain.insert(i, i + 1) = 1;
chain.insert(i + 1, i) = 1;
}
QVector<MatrixXd> condA, condB;
for (int s = 0; s < 12; ++s) {
MatrixXd noiseA(8, 1), noiseB(8, 1);
for (int ch = 0; ch < 8; ++ch) {
noiseA(ch, 0) = std::sin(1.3 * s + 0.7 * ch);
noiseB(ch, 0) = std::cos(0.9 * s + 1.1 * ch) + ((ch >= 2 && ch <= 4) ? 3.0 : 0.0);
}
condA.append(noiseA);
condB.append(noiseB);
}
const StatsClusterResult clusters = StatsCluster::permutationTest(condA, condB, chain, 500);
// Cluster ids are negative where A < B; |id| - 1 indexes vecClusterStats and vecClusterPvals
const int effectCluster = clusters.matClusterIds(3, 0);
Example
- Full source:
src/examples/ex_sts_statistics/main.cpp - Build target:
ex_sts_statistics(runs under CTest)
Used in examples
ex_sts_statistics
Statistics library on small literal data sets with known answers.
src/examples/ex_sts_statistics/main.cpp, line 176
const StatsClusterResult clusters = StatsCluster::permutationTest(condA, condB, chain, 500);
// Cluster ids are negative where A < B; |id| - 1 indexes vecClusterStats and vecClusterPvals
const int effectCluster = clusters.matClusterIds(3, 0);
const bool clusterOk = effectCluster < 0 && clusters.matClusterIds(2, 0) == effectCluster && clusters.matClusterIds(4, 0) == effectCluster && clusters.matClusterIds(7, 0) != effectCluster;
const double clusterP = clusterOk ? clusters.vecClusterPvals[-effectCluster - 1] : -1.0;
// The observed statistic counts as one permutation, so p >= 1 / (500 + 1) as in MNE-Python
ok &= expect(clusterOk && clusterP >= 1.0 / 501.0 && clusterP < 0.05,
QString("channels 2-4 form one negative cluster, 1/501 <= p %1 < 0.05").arg(clusterP));
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>