eelbrain.Factor
- class eelbrain.Factor(x, name=None, random=False, repeat=1, tile=1, labels=None, default=None)
Container for categorial data.
- Parameters:
x (Iterable[Any]) – Sequence of Factor values (see also the
labelskwarg).name (str) – Name of the Factor.
random (bool) – Treat Factor as random factor (for ANOVA; default is False).
repeat (int | Sequence[int]) – repeat each element in
x, either a constant or a different number for each element.tile (int | Sequence[int]) – Repeat
xas a wholetilemany times.labels (dict[Any, str]) – An optional dictionary mapping values as they occur in
xto the Factor’s cell labels.default (str) – Label to assign values not in
label(by default this isstr(value)).
- Variables:
.name (None | str) – The Factor’s name.
.cells (tuple of str) – Ordered names of all cells. Order is determined 1) by the order of cells in the
labelsargument, and 2) for cells that do not occur inlabelsit is determined by first occurrence inx..random (bool) – Whether the factor represents a random or fixed effect (for ANOVA).
Examples
The most obvious way to initialize a Factor is a list of strings:
>>> Factor(['in', 'in', 'in', 'out', 'out', 'out']) Factor(['in', 'in', 'in', 'out', 'out', 'out'])
The same can be achieved with a list of integers plus a labels dict:
>>> Factor([1, 1, 1, 0, 0, 0], labels={1: 'in', 0: 'out'}) Factor(['in', 'in', 'in', 'out', 'out', 'out'])
Or more parsimoniously:
>>> Factor([1, 0], labels={1: 'in', 0: 'out'}, repeat=3) Factor(['in', 'in', 'in', 'out', 'out', 'out'])
Since the Factor initialization simply iterates over the
xargument, a Factor with one-character codes can also be initialized with a single string:>>> Factor('iiiooo') Factor(['i', 'i', 'i', 'o', 'o', 'o'])
Methods
|
Summarize the Factor by collapsing within the cells of |
Convert the Factor to a list of str |
|
|
Convert into a Var |
|
A deep copy |
|
Cumulative count of the occurrences of |
|
An index that is true for all cases whose name ends with |
|
Enumerate the occurrence of each cell value throughout the data |
|
Fill in empty regions in a Factor from the nearest non-empty value |
|
Generate index to conform to another Factor's order |
|
Array with |
|
Find an optimized index for a given cell. |
|
Find the index of entries matching one of the |
|
Find the index of entries matching one of the |
|
Find the index of entries not in |
|
Find the index of entries not in |
|
Create Var with the length of each label string |
|
All labels to lower-case |
|
An index that is true for all cases whose name matches |
|
Repeat each element |
|
Reorder the cells of the Factor (in-place) |
|
Create an index that could be used to sort this data_object. |
|
An index that is true for all cases whose name starts with |
A table containing information about categories |
|
|
Construct a Factor by repeating |
|
Change one or more labels in place |
|
All labels to upper-case |