import numpy as np
from pyfixest.core.detect_singletons import detect_singletons
ids = np.array([[0, 0], [0, 0], [1, 1], [1, 1], [2, 2]])
detect_singletons(ids)array([False, False, False, False, True])
Detect singleton fixed effects in a dataset.
This function iterates over the columns of a 2D numpy array representing fixed effects to identify singleton fixed effects. An observation is considered a singleton if it is the only one in its group (fixed effect identifier).
| Name | Type | Description | Default |
|---|---|---|---|
| ids | np.ndarray | A 2D numpy array representing fixed effects, with a shape of (n_samples, n_features). Elements should be non-negative integers representing fixed effect identifiers. | required |
| Name | Type | Description |
|---|---|---|
| numpy.ndarray | A boolean array of shape (n_samples,), indicating which observations have a singleton fixed effect. |
The algorithm iterates over columns to identify fixed effects. After each column is processed, it updates the record of non-singleton rows. This approach accounts for the possibility that removing an observation in one column can lead to the emergence of new singletons in subsequent columns.
For performance reasons, the input array should be in column-major order. Operating on a row-major array can lead to significant performance losses.
Each row is an observation, each column a fixed effect. Only the last observation is alone in both of its groups.
array([False, False, False, False, True])
Dropping a singleton can create new singletons, so detection cascades across columns. Here all observations are singletons.