htfa.groups.group_tree¶
- htfa.groups.group_tree(groups, n_subjects, subject_ids=None)[source]¶
Build the template tree of a grouped HTFA fit.
- Parameters:
- groupssequence of labels, sequence of sequences of labels, or GroupTree
One label (
strorint) per subject, or a list of such sequences, one per level, top level first. For example,[site, subgroup]can group participants first by acquisition site and then by a subgroup within that site; these names illustrate nesting, not required labels. A tree fromGroupTree.from_pathsalso supports unequal path depths and repeated folder names under distinct parents. For label sequences, groups must be nested: every label of a level belongs to one label of the level above (use distinct labels such as'A-patient'and'B-patient'for groups under different parents).- n_subjectsint
Number of subjects.
- subject_idssequence, optional
One unique identifier per subject (per entry of
X). Repeated identifiers raiseValueError: repeated runs are not independent subjects and must be combined before fitting.
- Returns:
- GroupTree
- Raises:
- ValueError
On labels that are not strings or integers, a level with the wrong number of labels, a label under two parents (crossed levels), or a subject identifier in two groups (crossed designs, such as the same people before and after a treatment, are not supported).
Examples
An illustrative age-group tree for four independent participants, with one global template above separate child and adult templates:
>>> tree = group_tree(["child", "adult", "child", "adult"], 4) >>> tree.paths [(), ('child',), ('adult',)] >>> tree.solve(np.array([1.0, 4.0, 3.0, 6.0])) # global, then group means array([3.5, 2.5, 4.5])