terms.GroupSpecificTerm
terms.GroupSpecificTerm(expr, factor)Group-specific model term.
Group specific terms are of the form (expr | factor). The expression expr is evaluated as a model formula with only common effects and produces a model matrix following the rules for common terms. factor is inspired on factors in R, but here it is evaluated as an ordered pandas.CategoricalDtype object.
The pipe operator | works as in R package lme4. As its authors say: “One way to think about the vertical bar operator is as a special kind of interaction between the model matrix and the grouping factor. This interaction ensures that the columns of the model matrix have different effects for each level of the grouping factor”
Parameters
Attributes
data : scipy.sparse.csr_matrix-
The values associated with the term as they go into the design matrix.
kind : str-
Indicates the type of the term. Can be one of
"numeric","categoric", or"interaction".
Methods
| Name | Description |
|---|---|
| eval_new_data | Evaluates the term with new data. |
| eval_new_data_group_index | Evaluate the grouping factor as indices for new data. |
eval_new_data
terms.GroupSpecificTerm.eval_new_data(data)Evaluates the term with new data.
Converts the variable in factor to the type remembered from the first evaluation and produces the design matrix for this grouping, calls .eval_new_data() on self.expr to obtain the design matrix for the expr side, then computes the design matrix corresponding to the group specific effect.
Parameters
Returns
Zi : scipy.sparse.csr_matrix
eval_new_data_group_index
terms.GroupSpecificTerm.eval_new_data_group_index(data)Evaluate the grouping factor as indices for new data.
Unlike eval_new_data, this method preserves the distinction between missing values and unseen, non-missing levels. Existing factor columns are represented by their fitted index, missing values by -1, and unseen levels by consecutive indices after the fitted columns.