htfa.group_permutation_test¶
- htfa.group_permutation_test(model, X, coords, n_permutations=100, level=0, random_state=None, verbose=False)[source]¶
Permutation test of differences between groups, per factor.
Group paths must have equal depth, with distinct labels for groups under different parents; ragged folder hierarchies can be fitted and plotted but do not define this level-wise permutation scheme.
The labels of
levelare shuffled among the units under each parent (the groups of the next level, moved with their subjects, or the subjects at the innermost level), and the model is refitted with the shuffled labels: the same estimator parameters,random_stateincluded, and the model’s unpenalized stage-0 fits (free_fits_) asstarts, since those do not depend on the labels. The observed statistics come from the same refit with the true labels (which, for an integerrandom_stateand a fit made withoutstartsorinit_template, reproducesmodel). Every refit’s global template is matched to the first subject’s fixed stage-0 centers (mixture-weighted centers for mixture factors). This reference does not depend on the group labels. A single common permutation displays all statistics in the supplied model’s global template order;reference_indicesrecords the underlying reference identity of each column. SeeGroupTestfor the statistics.Any caller-supplied
startsmust be independent of the tested labels; label-informed initialization invalidates this conditional permutation procedure. Group labels must be exchangeable within the specified units under the null. Subject order, and thus the first-subject reference, must be fixed independently of the tested labels and before inspecting effects; the reference is not generally invariant to reordering subjects. Per-factor hypotheses should be specified before examining their effects; use max-statistic correction for selection across factors.- Parameters:
- modelHTFA
A fitted HTFA with
groups.- X, coordslist of array_like
The data and coordinates
modelwas fitted on.- n_permutationsint
Number of permutations P (default 100). The smallest attainable p-value is
1 / (P + 1).- levelint
Which level of
groupsto test (0, the top level, by default).- random_stateint, optional
Seed of the permutations (the refits use
model.random_state).- verbosebool
Print the progress of the refits.
- Returns:
- GroupTest
- Raises:
- ValueError
If
modelwas fitted without groups,levelis out of range, no parent atlevelhas two groups, orn_permutations < 1.
Examples
>>> import warnings >>> from htfa import HTFA >>> from htfa.synthetic import make_htfa_data >>> Xs, Rs, _ = make_htfa_data(4, (8, 8), 15, K=2, random_state=0) >>> model = HTFA(K=2, template_update="fixed", max_global_iter=2, ... max_local_iter=3, init="power", standardize=False, ... random_state=0) >>> with warnings.catch_warnings(): ... warnings.simplefilter("ignore") # 2 global iterations only ... model = model.fit(Xs, Rs, groups=["a", "a", "b", "b"]) ... test = group_permutation_test(model, Xs, Rs, n_permutations=3, ... random_state=0) >>> test.groups, test.center_null.shape, test.pvalues("center").shape (['a', 'b'], (3, 2), (2,))