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
labels
kwarg).name (str) – Name of the Factor.
random (bool) – Treat Factor as random factor (for ANOVA; default is False).
repeat (Union[int, Sequence[int]]) – repeat each element in
x
, either a constant or a different number for each element.tile (Union[int, Sequence[int]]) – Repeat
x
as a wholetile
many times.labels (Dict[Any, str]) – An optional dictionary mapping values as they occur in
x
to the Factor’s cell labels.default (str) – Label to assign values not in
label
(by default this isstr(value)
).
- Variables
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
x
argument, 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 |
|
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 |